Reputation: 123
the output error is : MinimizerException: Cannot determine Confidence Intervals without sensible uncertainty estimates
Why I got this error? How can I calculate uncertainty estimates and solve this problem??
for dosya1 in glob.glob("mean*"):
data1=np.genfromtxt(dosya1, skip_header=0, skip_footer=0, names=["wavelength","mean"])
x=data1["wavelength"]
mod=VoigtModel()
pars = mod.guess(y, x=x)
pars['gamma'].set(value=0.7, vary=True, expr="")
out=mod.fit(y,pars, x=x)
pars=lmfit.Parameters()
pars.add_many(('amp', out.params["amplitude"].value), ('sig', out.params["sigma"].value), ("gam",out.params["gamma"].value),("cent",out.params["center"].value))
def residual(p):
amp=p["amp"].value
sig=p["sig"].value
gam=p["gam"].value
cent=p["cent"].value
return ((wofz((x-cent + wofz(gam).imag)/(sig*(sqrt(2)))).real) / (sig*(sqrt(2))))- y
mini = lmfit.Minimizer(residual, pars)
result=mini.minimize()
ci = lmfit.conf_interval(mini, result)
lmfit.printfuncs.report_ci(ci)
Upvotes: 3
Views: 5271
Reputation: 7862
You will get this error message if lmfit.minimize()
(actually, leastsq()
, which it calls) is unable to estimate uncertainties by inverting the curvature matrix. It uses these values (which are often very good estimates, BTW) as the scale for explicitly exploring parameter space. There are several possible reasons why leastsq()
might fail to estimate uncertainties. Common reasons are that one or more of the variables is not found to alter the fit, or the residual contains NaNs.
It is hard to predict when this might happen. You should allow for the possibility and/or check that the initial fit succeeded and was able to make the initial estimate of the uncertainties (check result.errorbars
) before calling conf_interval()
.
Upvotes: 4