Automatic fit function
[1]:
import numpy as np
from smpl import plot
from smpl import stat
from smpl import io
from smpl import functions as f
import uncertainties.unumpy as unp
import smpl
smpl.__version__
[1]:
'1.3.0.303'
[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/30 [00:00<?, ?it/s]/__w/smpl/smpl/smpl/fit.py:121: FutureWarning: AffineScalarFunc.__lt__() is deprecated. It will be removed in a future release.
if min_sq is None or sum_sq < min_sq:
/__w/smpl/smpl/smpl/functions.py:42: 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)))
/__w/smpl/smpl/smpl/fit.py:121: FutureWarning: AffineScalarFunc.__gt__() is deprecated. It will be removed in a future release.
if min_sq is None or sum_sq < min_sq:
70%|███████ | 21/30 [00:00<00:00, 105.78it/s]/__w/smpl/smpl/smpl/functions.py:111: RuntimeWarning: invalid value encountered in power
return a * (x) ** k + y
/github/home/.cache/pypoetry/virtualenvs/smpl-4sWS420u-py3.10/lib/python3.10/site-packages/scipy/optimize/_minpack_py.py:881: OptimizeWarning: Covariance of the parameters could not be estimated
warnings.warn('Covariance of the parameters could not be estimated',
/github/home/.cache/pypoetry/virtualenvs/smpl-4sWS420u-py3.10/lib/python3.10/site-packages/uncertainties/core.py:131: RuntimeWarning: invalid value encountered in divide
covariance_mat / norm_vector / norm_vector[:, numpy.newaxis],
100%|██████████| 30/30 [00:00<00:00, 30.55it/s]
100%|██████████| 31/31 [00:00<00:00, 39.10it/s]


[ ]:
[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)
65%|██████▍ | 20/31 [00:00<00:00, 188.55it/s]/github/home/.cache/pypoetry/virtualenvs/smpl-4sWS420u-py3.10/lib/python3.10/site-packages/uncertainties/core.py:116: RuntimeWarning: invalid value encountered in sqrt
std_devs = numpy.sqrt(numpy.diag(covariance_mat))
100%|██████████| 31/31 [00:02<00:00, 13.67it/s]

[ ]:
[ ]: