from lmfit import Minimizer, Parameters, fit_report, minimize, Model, report_fit
filepath = "FILE PATH"data = np.loadtxt(filepath)q = data[:, 0]
r = data[:, 1]s = data[:, 2]
p = Parameters()
p.add('Amplitude', value=1, vary=True)p.add('Radius', value=40, vary=True)p.add('Polydispersity', value=0.1, vary=True)p.add('Background', value=0, vary=False)p.add('Roughness', value=0, vary=False)
def mdl(x,p):
amp = p['Amplitude'] radius = p['Radius'] pd = p['Polydispersity'] background = p['Background'] roughness = p['Roughness'] return mdls.hc_r_model(x, amp, background, radius, pd, roughness, wavelength)
fmodel = Model(mdl)result = fmodel.fit(r, params=p, x=q)fr = result.fit_report()print(fr)
plt.loglog(q, r, label='DATA',**marker_style,linewidth=0.7)plt.loglog(q, result.best_fit, 'r', label='FIT',linewidth=1.5)plt.xlabel(r'q', fontdict=font)plt.ylabel(r'I', fontdict=font)plt.title('Hard Cylinder Model', fontdict=font)plt.legend()
ValueError: Assign each parameter an initial value by passing Parameters or keyword arguments to fit.
Missing parameters: ['p']
Non initialized parameters: []
--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/c8349e6f-6eec-4572-bfc4-63948b11bfa7%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfi...@googlegroups.com.
Thanks a lot for your reply and yes wavelength is an independent variable. Actually, I really like the parameter class(the way I used to add parameters). Is there no way to use those defined parameters with model function?
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/8e38833f-4afd-485b-a5d8-9e11adf6d1d7%40googlegroups.com.
def mdl(x,amp, radius, pd, background, roughness):
--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/c8349e6f-6eec-4572-bfc4-63948b11bfa7%40googlegroups.com.