x = np.array([ float(datum[1]) for datum in data ])y = np.array([ float(datum[2]) for datum in data ])errs = np.array([ float(datum[3]) for datum in data ])
Thanks for replying.x is some arbitrary x-axis, y is the data. I then have a function mod(x), which gives me the model value. To get the residual I then do y-mod(x).Does the weight option take arrays? the errors are different for each point.
I'm new to lmfit, sorry if this is obvious.
On Thursday, 27 October 2016 17:33:37 UTC+2, Matt Newville wrote:On Thu, Oct 27, 2016 at 10:25 AM, Albin Nilsson <kold...@gmail.com> wrote:I'm trying to use lmfit for parameter estimation via emcee. The data I want to fit to is somewhat noisy, and each data point has a symmetric error bar associated with it.The data and errors are loaded into two different arrays:
x = np.array([ float(datum[1]) for datum in data ])y = np.array([ float(datum[2]) for datum in data ])errs = np.array([ float(datum[3]) for datum in data ])
and the error bar for each x is x[i] +- error[i] (in pseudocode)Does anyone know how to include the error bars in the code? Any help would be greatly appreciated.Generally speaking, one would want to make some model for the data (is that "y", and is "x" the independent data?) and then minimize the array(model - data) / errs
Typically, one would write an objective function that returned such a quantity. If you're using the Model class, you would specify a "weights" option to Model.fit(), with a value of 1/errs (checking for divide-by-zero, of course).--Matt
--
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+unsubscribe@googlegroups.com.
To post to this group, send email to lmfi...@googlegroups.com.
Visit this group at https://groups.google.com/group/lmfit-py.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/150a81bb-5b8b-468b-a866-ea76cf9aae54%40googlegroups.com.
y = kx+m
Does this help further?
http://dan.iel.fm/emcee/current/user/line/
--
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+unsubscribe@googlegroups.com.
To post to this group, send email to lmfi...@googlegroups.com.
Visit this group at https://groups.google.com/group/lmfit-py.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/8d0f6b01-f655-43f3-abc6-684d9ebb40f6%40googlegroups.com.
def d_L(x, Om, M):
def integrand(xes, Om):
return float(1.0/(np.sqrt(Om*(1+xes)**3.0+(1-Om))))
int_res = [ integr.quad(integrand, 0, xes, Om)[0]*(1+zed)/M for xes in x ]
return int_res
def func_mod(x, M, Om, mu0):
return (5*np.log10(d_L(x, Om, M)) + mu0)
mod = (mod-mus)/errs
mini = lmfit.Minimizer(lnprob, p)
print 'Running MCMC...'
res = mini.emcee(burn=300, steps=600, thin=10, nwalkers=100, params=p, float_behavior='posterior', is_weighted=True)
quantiles = np.percentile(res.flatchain['M'], [2.28, 15.9, 50, 84.2, 97.7])
fig = corner.corner(res.flatchain, labels=res.var_names, quantiles=[0.16, 0.5, 0.84], show_titles=True, title_kwargs={"fontsize": 12}, truths=list(res.params.valuesdict().values()))
--
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+unsubscribe@googlegroups.com.
To post to this group, send email to lmfi...@googlegroups.com.
Visit this group at https://groups.google.com/group/lmfit-py.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/551c2c77-554e-4a59-9350-c23e0f12aac6%40googlegroups.com.
def generative(p):
v = p.valuesdict()
return (func_mod(zeds, v['M'], v['Om'], v['mu0']))
def lnprob(p):
mod = generative(p)
mod = (mod-mus)/errs
mod *= mod
v = p.valuesdict()
mod += np.log(2*np.pi*errs**2)
return -0.5*np.sum(mod)
mini = lmfit.Minimizer(lnprob, p)
print 'Running MCMC...'
res = mini.emcee(burn=300, steps=600, thin=10, nwalkers=200, params=p, float_behavior='posterior', is_weighted=True)
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To post to this group, send email to lmfi...@googlegroups.com.
Visit this group at https://groups.google.com/group/lmfit-py.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/551c2c77-554e-4a59-9350-c23e0f12aac6%40googlegroups.com.