Builtinmodels - nistgaussΒΆ

builtinmodels nistgauss
[[Model]]
    ((Model(gaussian, prefix='g1_') + Model(gaussian, prefix='g2_')) + Model(exponential, prefix='exp_'))
[[Fit Statistics]]
    # fitting method   = leastsq
    # function evals   = 46
    # data points      = 250
    # variables        = 8
    chi-square         = 1247.52821
    reduced chi-square = 5.15507524
    Akaike info crit   = 417.864631
    Bayesian info crit = 446.036318
    R-squared          = 0.99648654
[[Variables]]
    exp_amplitude:  99.0183278 +/- 0.53748593 (0.54%) (init = 162.2102)
    exp_decay:      90.9508853 +/- 1.10310778 (1.21%) (init = 93.24905)
    g1_amplitude:   4257.77360 +/- 42.3836478 (1.00%) (init = 2000)
    g1_center:      107.030956 +/- 0.15006851 (0.14%) (init = 105)
    g1_sigma:       16.6725772 +/- 0.16048381 (0.96%) (init = 15)
    g1_fwhm:        39.2609181 +/- 0.37791049 (0.96%) == '2.3548200*g1_sigma'
    g1_height:      101.880230 +/- 0.59217173 (0.58%) == '0.3989423*g1_amplitude/max(1e-15, g1_sigma)'
    g2_amplitude:   2493.41735 +/- 36.1697789 (1.45%) (init = 2000)
    g2_center:      153.270102 +/- 0.19466802 (0.13%) (init = 155)
    g2_sigma:       13.8069464 +/- 0.18679695 (1.35%) (init = 15)
    g2_fwhm:        32.5128735 +/- 0.43987320 (1.35%) == '2.3548200*g2_sigma'
    g2_height:      72.0455941 +/- 0.61722243 (0.86%) == '0.3989423*g2_amplitude/max(1e-15, g2_sigma)'
[[Correlations]]
  +---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+
  | Variable      | exp_amplitude | exp_decay     | g1_amplitude  | g1_center     | g1_sigma      | g2_amplitude  | g2_center     | g2_sigma      |
  +---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+
  | exp_amplitude | +1.0000       | -0.6946       | +0.1478       | -0.0467       | +0.0218       | +0.2821       | +0.0331       | +0.1714       |
  | exp_decay     | -0.6946       | +1.0000       | -0.5074       | +0.1055       | -0.2520       | -0.4270       | -0.1514       | -0.2329       |
  | g1_amplitude  | +0.1478       | -0.5074       | +1.0000       | +0.4183       | +0.8243       | -0.3071       | +0.6477       | -0.4010       |
  | g1_center     | -0.0467       | +0.1055       | +0.4183       | +1.0000       | +0.5075       | -0.6689       | +0.6205       | -0.6520       |
  | g1_sigma      | +0.0218       | -0.2520       | +0.8243       | +0.5075       | +1.0000       | -0.4915       | +0.6842       | -0.4826       |
  | g2_amplitude  | +0.2821       | -0.4270       | -0.3071       | -0.6689       | -0.4915       | +1.0000       | -0.4763       | +0.8154       |
  | g2_center     | +0.0331       | -0.1514       | +0.6477       | +0.6205       | +0.6842       | -0.4763       | +1.0000       | -0.4889       |
  | g2_sigma      | +0.1714       | -0.2329       | -0.4010       | -0.6520       | -0.4826       | +0.8154       | -0.4889       | +1.0000       |
  +---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+

# <examples/doc_builtinmodels_nistgauss.py>
import matplotlib.pyplot as plt
import numpy as np

from lmfit.models import ExponentialModel, GaussianModel

dat = np.loadtxt('NIST_Gauss2.dat')
x = dat[:, 1]
y = dat[:, 0]

exp_mod = ExponentialModel(prefix='exp_')
pars = exp_mod.guess(y, x=x)

gauss1 = GaussianModel(prefix='g1_')
pars.update(gauss1.make_params(center=dict(value=105, min=75, max=125),
                               sigma=dict(value=15, min=0),
                               amplitude=dict(value=2000, min=0)))

gauss2 = GaussianModel(prefix='g2_')
pars.update(gauss2.make_params(center=dict(value=155, min=125, max=175),
                               sigma=dict(value=15, min=0),
                               amplitude=dict(value=2000, min=0)))

mod = gauss1 + gauss2 + exp_mod

init = mod.eval(pars, x=x)
out = mod.fit(y, pars, x=x)

print(out.fit_report(correl_mode='table'))

fig, axes = plt.subplots(1, 2, figsize=(12.8, 4.8))
axes[0].plot(x, y)
axes[0].plot(x, init, '--', label='initial fit')
axes[0].plot(x, out.best_fit, '-', label='best fit')
axes[0].legend()

comps = out.eval_components(x=x)
axes[1].plot(x, y)
axes[1].plot(x, comps['g1_'], '--', label='Gaussian component 1')
axes[1].plot(x, comps['g2_'], '--', label='Gaussian component 2')
axes[1].plot(x, comps['exp_'], '--', label='Exponential component')
axes[1].legend()

plt.show()
# <end examples/doc_builtinmodels_nistgauss.py>

Total running time of the script: (0 minutes 0.410 seconds)

Gallery generated by Sphinx-Gallery