Automatic fit function

[1]:
import numpy as np
import uncertainties.unumpy as unp

import smpl
from smpl import io, plot, stat

smpl.__version__
[1]:
'1.5.3'
[2]:
for n in ["test_linear_data.txt", "test_quad_data.txt"]:
    data = np.loadtxt(io.find_file(n, 3))
    xdata = data[:, 0]
    xerr = data[:, 2]
    ydata = data[:, 1]
    yerr = data[:, 3]
    x = unp.uarray(xdata, xerr)
    y = unp.uarray(ydata, yerr)

    function, fitparams, lfunc = plot.auto(
        xdata,
        ydata,
        fmt=".",
        label="data",
        xaxis="x in a.u.",
        yaxis="y in a.u.",
        sigmas=1,
        epsfcn=0.00001,
        maxfev=1000000,
        init=True,
    )
  0%|          | 0/27 [00:00<?, ?it/s]/home/docs/checkouts/readthedocs.org/user_builds/smpl/envs/v1.5.3/lib/python3.12/site-packages/smpl/fit.py:126: FutureWarning: AffineScalarFunc.__lt__() is deprecated. It will be removed in a future release.
  if min_sq is None or sum_sq < min_sq:
/home/docs/checkouts/readthedocs.org/user_builds/smpl/envs/v1.5.3/lib/python3.12/site-packages/smpl/functions.py:43: FutureWarning: AffineScalarFunc.__abs__() is deprecated. It will be removed in a future release.
  return a * np.abs(unp.cos(2 * np.pi * f * (x - phi)))
/home/docs/checkouts/readthedocs.org/user_builds/smpl/envs/v1.5.3/lib/python3.12/site-packages/smpl/fit.py:126: FutureWarning: AffineScalarFunc.__gt__() is deprecated. It will be removed in a future release.
  if min_sq is None or sum_sq < min_sq:
 74%|███████▍  | 20/27 [00:00<00:00, 108.12it/s]/home/docs/checkouts/readthedocs.org/user_builds/smpl/envs/v1.5.3/lib/python3.12/site-packages/smpl/functions.py:112: RuntimeWarning: invalid value encountered in power
  return a * (x) ** k + y
100%|██████████| 27/27 [00:00<00:00, 35.27it/s]
100%|██████████| 28/28 [00:00<00:00, 50.99it/s]
../../../_images/example_fit_auto_test_auto_2_1.png
../../../_images/example_fit_auto_test_auto_2_2.png
[ ]:

[3]:
x = np.linspace(-5, 5, 100)
y = stat.noisy(np.exp(2 * x))
ff = plot.auto(
    x, y, fmt=".", label="data", xaxis="x in a.u.", yaxis="y in a.u.", sigmas=1
)
100%|██████████| 28/28 [00:01<00:00, 16.94it/s]
../../../_images/example_fit_auto_test_auto_4_1.png
[ ]:

[ ]: