Esempio n. 1
0
for scale_covar in (True, False):
    myfit.scale_covar = scale_covar
    print '  ====  scale_covar = ', myfit.scale_covar, ' ==='
    for sigma in (0.1, 0.2, 0.23, 0.5):
        myfit.userkws['sigma'] = sigma

        p_fit['amp_g'].value  = 10
        p_fit['cen_g'].value  =  9
        p_fit['wid_g'].value  =  1
        p_fit['line_slope'].value =0.0
        p_fit['line_off'].value   =0.0

        myfit.leastsq()
        print '  sigma          = ', sigma
        print '  chisqr         = ', myfit.chisqr
        print '  reduced_chisqr = ', myfit.redchi

        report_errors(p_fit, modelpars=p_true, show_correl=False)
        print '  =============================='

        
# if HASPYLAB:
#     fit = residual(p_fit, x)
#     pylab.plot(x, fit, 'k-')
#     pylab.show()
#




Esempio n. 2
0
xmax = 250.0
noise = random.normal(scale=0.7215, size=n)
x     = linspace(xmin, xmax, n)
data  = residual(p_true, x) + noise

fit_params = Parameters()
fit_params.add('amp', value=13.0)
fit_params.add('period', value=2)
fit_params.add('shift', value=0.0)
fit_params.add('decay', value=0.02)

out = minimize(residual, fit_params, args=(x,), kws={'data':data})

fit = residual(fit_params, x)

print ' N fev = ', out.nfev
print out.chisqr, out.redchi, out.nfree

report_errors(fit_params)


if HASPYLAB:
    pylab.plot(x, data, 'ro')
    pylab.plot(x, fit, 'b')
    pylab.show()





Esempio n. 3
0
    ("a1", 8.0, True, None, 14.0, None),
    ("c1", 5.0, True, None, None, None),
    ("w1", 0.7, True, None, None, None),
    ("a2", 3.1, True, None, None, None),
    ("c2", 8.8, True, None, None, None),
)

fit_params.add("w2", expr="2.5*w1")

myfit = Minimizer(residual, fit_params, fcn_args=(x,), fcn_kws={"data": data})

myfit.prepare_fit()

init = residual(fit_params, x)

if HASPYLAB:
    pylab.plot(x, init, "b--")

myfit.leastsq()

print " N fev = ", myfit.nfev
print myfit.chisqr, myfit.redchi, myfit.nfree

report_errors(fit_params)

fit = residual(fit_params, x)

if HASPYLAB:
    pylab.plot(x, fit, "k-")
    pylab.show()
Esempio n. 4
0
sigma = 0.021  # estimate of data error (for all data points)

myfit = Minimizer(residual,
                  pfit,
                  iter_cb=per_iteration,
                  fcn_args=(x, ),
                  fcn_kws={
                      'sigma': sigma,
                      'data': data
                  },
                  scale_covar=True)

myfit.prepare_fit()
init = residual(myfit.params, x)

if HASPYLAB:
    pylab.plot(x, init, 'b--')

myfit.leastsq()

print(' Nfev = ', myfit.nfev)
print(myfit.chisqr, myfit.redchi, myfit.nfree)

report_errors(myfit.params, modelpars=p_true)

fit = residual(myfit.params, x)

if HASPYLAB:
    pylab.plot(x, fit, 'k-')
    pylab.show()
Esempio n. 5
0
sigma = 0.021  # estimate of data error (for all data points)

myfit = Minimizer(residual, pfit, iter_cb=per_iteration,
                  fcn_args=(x,), fcn_kws={'sigma':sigma, 'data':data},
                  scale_covar=True)

myfit.prepare_fit()
init = residual(myfit.params, x)

if HASPYLAB:
    pylab.plot(x, init, 'b--')

myfit.leastsq()

print(' Nfev = ', myfit.nfev)
print( myfit.chisqr, myfit.redchi, myfit.nfree)

report_errors(myfit.params, modelpars=p_true)

fit = residual(myfit.params, x)

if HASPYLAB:
    pylab.plot(x, fit, 'k-')
    pylab.show()





Esempio n. 6
0
p_fit.add('wid_l', expr='wid_g')
p_fit.add('line_slope', value=0.0)
p_fit.add('line_off', value=0.0)

myfit = Minimizer(residual, p_fit,
                  fcn_args=(x,), fcn_kws={'data':data})

myfit.prepare_fit()
init = residual(p_fit, x)

if sys.version_info[0] == 2:
    pylab.plot(x, init, 'b--')

myfit.leastsq()

print(' Nfev = ', myfit.nfev)
print( myfit.chisqr, myfit.redchi, myfit.nfree)

report_errors(p_fit, modelpars=p_true)

fit = residual(p_fit, x)

if sys.version_info[0] == 2:
    pylab.plot(x, fit, 'k-')
    pylab.show()





Esempio n. 7
0
                      'data': data
                  })

myfit.prepare_fit()
#
for scale_covar in (True, False):
    myfit.scale_covar = scale_covar
    print '  ====  scale_covar = ', myfit.scale_covar, ' ==='
    for sigma in (0.1, 0.2, 0.23, 0.5):
        myfit.userkws['sigma'] = sigma

        p_fit['amp_g'].value = 10
        p_fit['cen_g'].value = 9
        p_fit['wid_g'].value = 1
        p_fit['line_slope'].value = 0.0
        p_fit['line_off'].value = 0.0

        myfit.leastsq()
        print '  sigma          = ', sigma
        print '  chisqr         = ', myfit.chisqr
        print '  reduced_chisqr = ', myfit.redchi

        report_errors(p_fit, modelpars=p_true, show_correl=False)
        print '  =============================='

# if HASPYLAB:
#     fit = residual(p_fit, x)
#     pylab.plot(x, fit, 'k-')
#     pylab.show()
#