Skip to content

Commit

Permalink
DOC: updates for new fit_report output
Browse files Browse the repository at this point in the history
  • Loading branch information
reneeotten committed Mar 20, 2018
1 parent 3d0caea commit f02bc9e
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 192 deletions.
Binary file modified doc/_images/emcee_corner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
227 changes: 113 additions & 114 deletions doc/builtin_models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -310,18 +310,18 @@ which prints out the results::
# function evals = 27
# data points = 401
# variables = 3
chi-square = 29.99432
reduced chi-square = 0.07536
chi-square = 29.9943157
reduced chi-square = 0.07536260
Akaike info crit = -1033.77437
Bayesian info crit = -1021.79248
[[Variables]]
sigma: 1.23218358 +/- 0.007374 (0.60%) (init= 1.35)
center: 9.24277047 +/- 0.007374 (0.08%) (init= 9.25)
amplitude: 30.3135620 +/- 0.157126 (0.52%) (init= 43.62238)
fwhm: 2.90157055 +/- 0.017366 (0.60%) == '2.3548200*sigma'
height: 9.81457817 +/- 0.050872 (0.52%) == '0.3989423*amplitude/max(1.e-15, sigma)'
[[Correlations]] (unreported correlations are < 0.250)
C(sigma, amplitude) = 0.577
sigma: 1.23218359 +/- 0.00737496 (0.60%) (init = 1.35)
amplitude: 30.3135620 +/- 0.15712686 (0.52%) (init = 43.62238)
center: 9.24277047 +/- 0.00737496 (0.08%) (init = 9.25)
fwhm: 2.90157056 +/- 0.01736670 (0.60%) == '2.3548200*sigma'
height: 9.81457817 +/- 0.05087283 (0.52%) == '0.3989423*amplitude/max(1.e-15, sigma)'
[[Correlations]] (unreported correlations are < 0.250)
C(sigma, amplitude) = 0.577

We see a few interesting differences from the results of the previous
chapter. First, the parameter names are longer. Second, there are ``fwhm``
Expand Down Expand Up @@ -360,19 +360,18 @@ we try gives results that are worse::
# function evals = 23
# data points = 401
# variables = 3
chi-square = 53.75354
reduced chi-square = 0.13506
Akaike info crit = -799.83032
Bayesian info crit = -787.84844
chi-square = 53.7535387
reduced chi-square = 0.13505914
Akaike info crit = -799.830322
Bayesian info crit = -787.848438
[[Variables]]
sigma: 1.15483925 +/- 0.013156 (1.14%) (init= 1.35)
center: 9.24438944 +/- 0.009276 (0.10%) (init= 9.25)
amplitude: 38.9727644 +/- 0.313861 (0.81%) (init= 54.52798)
fwhm: 2.30967850 +/- 0.026313 (1.14%) == '2.0000000*sigma'
height: 10.7421156 +/- 0.086339 (0.80%) == '0.3183099*amplitude/max(1.e-15, sigma)'
[[Correlations]] (unreported correlations are < 0.250)
C(sigma, amplitude) = 0.709

sigma: 1.15483925 +/- 0.01315659 (1.14%) (init = 1.35)
center: 9.24438944 +/- 0.00927619 (0.10%) (init = 9.25)
amplitude: 38.9727645 +/- 0.31386183 (0.81%) (init = 54.52798)
fwhm: 2.30967850 +/- 0.02631318 (1.14%) == '2.0000000*sigma'
height: 10.7421156 +/- 0.08633945 (0.80%) == '0.3183099*amplitude/max(1.e-15, sigma)'
[[Correlations]] (unreported correlations are < 0.250)
C(sigma, amplitude) = 0.709

with the plot shown on the right in the figure above. The tails are now
too big, and the value for :math:`\chi^2` almost doubled. A Voigt model
Expand All @@ -390,19 +389,19 @@ with all the rest of the script as above. This gives::
# function evals = 23
# data points = 401
# variables = 3
chi-square = 14.54486
reduced chi-square = 0.03654
chi-square = 14.5448627
reduced chi-square = 0.03654488
Akaike info crit = -1324.00615
Bayesian info crit = -1312.02427
[[Variables]]
amplitude: 35.7554145 +/- 0.138613 (0.39%) (init= 65.43358)
sigma: 0.73015626 +/- 0.003684 (0.50%) (init= 0.8775)
center: 9.24411149 +/- 0.005054 (0.05%) (init= 9.25)
gamma: 0.73015626 +/- 0.003684 (0.50%) == 'sigma'
fwhm: 2.62951907 +/- 0.013269 (0.50%) == '3.6013100*sigma'
height: 10.2203968 +/- 0.030094 (0.29%) == 'amplitude*wofz((1j*gamma)/(sigma*sqrt(2))).real/(sigma*sqrt(2*pi))'
[[Correlations]] (unreported correlations are < 0.250)
C(amplitude, sigma) = 0.651
center: 9.24411150 +/- 0.00505482 (0.05%) (init = 9.25)
sigma: 0.73015627 +/- 0.00368460 (0.50%) (init = 0.8775)
amplitude: 35.7554146 +/- 0.13861321 (0.39%) (init = 65.43358)
gamma: 0.73015627 +/- 0.00368460 (0.50%) == 'sigma'
fwhm: 2.62951907 +/- 0.01326940 (0.50%) == '3.6013100*sigma'
height: 10.2203969 +/- 0.03009415 (0.29%) == 'amplitude*wofz((1j*gamma)/(sigma*sqrt(2))).real/(sigma*sqrt(2*pi))'
[[Correlations]] (unreported correlations are < 0.250)
C(sigma, amplitude) = 0.651

which has a much better value for :math:`\chi^2` and the other
goodness-of-fit measures, and an obviously better match to the data as seen
Expand Down Expand Up @@ -441,21 +440,21 @@ which gives::
# function evals = 23
# data points = 401
# variables = 4
chi-square = 10.93018
reduced chi-square = 0.02753
chi-square = 10.9301767
reduced chi-square = 0.02753193
Akaike info crit = -1436.57602
Bayesian info crit = -1420.60017
[[Variables]]
amplitude: 34.1914737 +/- 0.179468 (0.52%) (init= 65.43358)
sigma: 0.89518908 +/- 0.014154 (1.58%) (init= 0.8775)
center: 9.24374847 +/- 0.004419 (0.05%) (init= 9.25)
gamma: 0.52540198 +/- 0.018579 (3.54%) (init= 0.7)
fwhm: 3.22385341 +/- 0.050974 (1.58%) == '3.6013100*sigma'
height: 10.0872204 +/- 0.034821 (0.35%) == 'amplitude*wofz((1j*gamma)/(sigma*sqrt(2))).real/(sigma*sqrt(2*pi))'
[[Correlations]] (unreported correlations are < 0.250)
C(sigma, gamma) = -0.928
C(amplitude, gamma) = 0.821
C(amplitude, sigma) = -0.651
sigma: 0.89518909 +/- 0.01415450 (1.58%) (init = 0.8775)
amplitude: 34.1914737 +/- 0.17946860 (0.52%) (init = 65.43358)
center: 9.24374847 +/- 0.00441903 (0.05%) (init = 9.25)
gamma: 0.52540199 +/- 0.01857955 (3.54%) (init = 0.7)
fwhm: 3.22385342 +/- 0.05097475 (1.58%) == '3.6013100*sigma'
height: 10.0872204 +/- 0.03482129 (0.35%) == 'amplitude*wofz((1j*gamma)/(sigma*sqrt(2))).real/(sigma*sqrt(2*pi))'
[[Correlations]] (unreported correlations are < 0.250)
C(sigma, gamma) = -0.928
C(amplitude, gamma) = 0.821
C(sigma, amplitude) = -0.651

and the fit shown on the right above.

Expand Down Expand Up @@ -506,26 +505,26 @@ results, which gives::
# function evals = 51
# data points = 201
# variables = 5
chi-square = 646.80593
reduced chi-square = 3.30003
Akaike info crit = 244.91702
Bayesian info crit = 261.43354
chi-square = 526.476967
reduced chi-square = 2.68610698
Akaike info crit = 203.543438
Bayesian info crit = 220.059962
[[Variables]]
line_slope: 1.93785312 +/- 0.096710 (4.99%) (init= 0)
line_intercept: 11.6526810 +/- 0.287875 (2.47%) (init= 10.5004)
step_amplitude: 112.586043 +/- 0.678081 (0.60%) (init= 134.1271)
step_sigma: 0.66513459 +/- 0.011306 (1.70%) (init= 1.428571)
step_center: 3.12604686 +/- 0.005360 (0.17%) (init= 2.5)
[[Correlations]] (unreported correlations are < 0.100)
C(line_slope, step_amplitude) = -0.878
C(step_amplitude, step_sigma) = 0.561
C(line_slope, step_sigma) = -0.453
C(line_intercept, step_center) = 0.425
C(line_slope, line_intercept) = -0.309
C(line_slope, step_center) = -0.233
C(line_intercept, step_sigma) = -0.137
C(line_intercept, step_amplitude) = -0.120
C(step_amplitude, step_center) = 0.108
line_intercept: 11.6336538 +/- 0.25986140 (2.23%) (init = 11.41635)
line_slope: 2.06801103 +/- 0.08730814 (4.22%) (init = 0)
step_sigma: 0.66708191 +/- 0.01028666 (1.54%) (init = 1.428571)
step_amplitude: 111.878321 +/- 0.61242795 (0.55%) (init = 133.7451)
step_center: 3.12524684 +/- 0.00487627 (0.16%) (init = 2.5)
[[Correlations]] (unreported correlations are < 0.100)
C(line_slope, step_amplitude) = -0.878
C(step_sigma, step_amplitude) = 0.561
C(line_slope, step_sigma) = -0.454
C(line_intercept, step_center) = 0.425
C(line_intercept, line_slope) = -0.308
C(line_slope, step_center) = -0.233
C(line_intercept, step_sigma) = -0.138
C(line_intercept, step_amplitude) = -0.121
C(step_amplitude, step_center) = 0.108

with a plot of

Expand Down Expand Up @@ -570,33 +569,33 @@ The fit results printed out are::
# data points = 250
# variables = 8
chi-square = 1247.52821
reduced chi-square = 5.15508
Akaike info crit = 417.86463
Bayesian info crit = 446.03632
reduced chi-square = 5.15507524
Akaike info crit = 417.864631
Bayesian info crit = 446.036318
[[Variables]]
exp_amplitude: 99.0183282 +/- 0.537487 (0.54%) (init= 162.2102)
exp_decay: 90.9508861 +/- 1.103105 (1.21%) (init= 93.24905)
g1_sigma: 16.6725753 +/- 0.160481 (0.96%) (init= 15)
g1_center: 107.030954 +/- 0.150067 (0.14%) (init= 105)
g1_amplitude: 4257.77318 +/- 42.38336 (1.00%) (init= 2000)
g1_fwhm: 39.2609137 +/- 0.377905 (0.96%) == '2.3548200*g1_sigma'
g1_height: 101.880231 +/- 0.592170 (0.58%) == '0.3989423*g1_amplitude/max(1.e-15, g1_sigma)'
g2_sigma: 13.8069484 +/- 0.186794 (1.35%) (init= 15)
g2_center: 153.270100 +/- 0.194667 (0.13%) (init= 155)
g2_amplitude: 2493.41770 +/- 36.16947 (1.45%) (init= 2000)
g2_fwhm: 32.5128783 +/- 0.439866 (1.35%) == '2.3548200*g2_sigma'
g2_height: 72.0455934 +/- 0.617220 (0.86%) == '0.3989423*g2_amplitude/max(1.e-15, g2_sigma)'
[[Correlations]] (unreported correlations are < 0.500)
C(g1_sigma, g1_amplitude) = 0.824
C(g2_sigma, g2_amplitude) = 0.815
C(exp_amplitude, exp_decay) = -0.695
C(g1_sigma, g2_center) = 0.684
C(g1_center, g2_amplitude) = -0.669
C(g1_center, g2_sigma) = -0.652
C(g1_amplitude, g2_center) = 0.648
C(g1_center, g2_center) = 0.621
C(g1_sigma, g1_center) = 0.507
C(exp_decay, g1_amplitude) = -0.507
exp_decay: 90.9508860 +/- 1.10310509 (1.21%) (init = 93.24905)
exp_amplitude: 99.0183283 +/- 0.53748735 (0.54%) (init = 162.2102)
g1_center: 107.030954 +/- 0.15006786 (0.14%) (init = 105)
g1_sigma: 16.6725753 +/- 0.16048161 (0.96%) (init = 15)
g1_amplitude: 4257.77319 +/- 42.3833645 (1.00%) (init = 2000)
g1_fwhm: 39.2609138 +/- 0.37790530 (0.96%) == '2.3548200*g1_sigma'
g1_height: 101.880231 +/- 0.59217100 (0.58%) == '0.3989423*g1_amplitude/max(1.e-15, g1_sigma)'
g2_center: 153.270101 +/- 0.19466743 (0.13%) (init = 155)
g2_sigma: 13.8069484 +/- 0.18679415 (1.35%) (init = 15)
g2_amplitude: 2493.41771 +/- 36.1694731 (1.45%) (init = 2000)
g2_fwhm: 32.5128783 +/- 0.43986659 (1.35%) == '2.3548200*g2_sigma'
g2_height: 72.0455934 +/- 0.61722094 (0.86%) == '0.3989423*g2_amplitude/max(1.e-15, g2_sigma)'
[[Correlations]] (unreported correlations are < 0.500)
C(g1_sigma, g1_amplitude) = 0.824
C(g2_sigma, g2_amplitude) = 0.815
C(exp_decay, exp_amplitude) = -0.695
C(g1_sigma, g2_center) = 0.684
C(g1_center, g2_amplitude) = -0.669
C(g1_center, g2_sigma) = -0.652
C(g1_amplitude, g2_center) = 0.648
C(g1_center, g2_center) = 0.621
C(g1_center, g1_sigma) = 0.507
C(exp_decay, g1_amplitude) = -0.507

We get a very good fit to this problem (described at the NIST site as of
average difficulty, but the tests there are generally deliberately challenging) by
Expand Down Expand Up @@ -647,33 +646,33 @@ but in few steps, and without any bounds on parameters at all::
# data points = 250
# variables = 8
chi-square = 1247.52821
reduced chi-square = 5.15508
Akaike info crit = 417.86463
Bayesian info crit = 446.03632
reduced chi-square = 5.15507524
Akaike info crit = 417.864631
Bayesian info crit = 446.036318
[[Variables]]
exp_amplitude: 99.0183269 +/- 0.537489 (0.54%) (init= 94.53724)
exp_decay: 90.9508890 +/- 1.103104 (1.21%) (init= 111.1985)
g1_sigma: 16.6725765 +/- 0.160482 (0.96%) (init= 14.5)
g1_center: 107.030955 +/- 0.150068 (0.14%) (init= 106.5)
g1_amplitude: 4257.77343 +/- 42.38364 (1.00%) (init= 3189.648)
g1_fwhm: 39.2609166 +/- 0.377906 (0.96%) == '2.3548200*g1_sigma'
g1_height: 101.880229 +/- 0.592172 (0.58%) == '0.3989423*g1_amplitude/max(1.e-15, g1_sigma)'
g2_sigma: 13.8069461 +/- 0.186795 (1.35%) (init= 15)
g2_center: 153.270101 +/- 0.194669 (0.13%) (init= 150)
g2_amplitude: 2493.41732 +/- 36.16969 (1.45%) (init= 2818.337)
g2_fwhm: 32.5128728 +/- 0.439869 (1.35%) == '2.3548200*g2_sigma'
g2_height: 72.0455947 +/- 0.617223 (0.86%) == '0.3989423*g2_amplitude/max(1.e-15, g2_sigma)'
[[Correlations]] (unreported correlations are < 0.500)
C(g1_sigma, g1_amplitude) = 0.824
C(g2_sigma, g2_amplitude) = 0.815
C(exp_amplitude, exp_decay) = -0.695
C(g1_sigma, g2_center) = 0.684
C(g1_center, g2_amplitude) = -0.669
C(g1_center, g2_sigma) = -0.652
C(g1_amplitude, g2_center) = 0.648
C(g1_center, g2_center) = 0.621
C(g1_sigma, g1_center) = 0.507
C(exp_decay, g1_amplitude) = -0.507
exp_decay: 90.9508890 +/- 1.10310483 (1.21%) (init = 111.1985)
exp_amplitude: 99.0183270 +/- 0.53748905 (0.54%) (init = 94.53724)
g1_sigma: 16.6725765 +/- 0.16048227 (0.96%) (init = 14.5)
g1_amplitude: 4257.77343 +/- 42.3836432 (1.00%) (init = 3189.648)
g1_center: 107.030956 +/- 0.15006873 (0.14%) (init = 106.5)
g1_fwhm: 39.2609166 +/- 0.37790686 (0.96%) == '2.3548200*g1_sigma'
g1_height: 101.880230 +/- 0.59217233 (0.58%) == '0.3989423*g1_amplitude/max(1.e-15, g1_sigma)'
g2_sigma: 13.8069461 +/- 0.18679534 (1.35%) (init = 15)
g2_amplitude: 2493.41733 +/- 36.1696911 (1.45%) (init = 2818.337)
g2_center: 153.270101 +/- 0.19466905 (0.13%) (init = 150)
g2_fwhm: 32.5128728 +/- 0.43986940 (1.35%) == '2.3548200*g2_sigma'
g2_height: 72.0455948 +/- 0.61722329 (0.86%) == '0.3989423*g2_amplitude/max(1.e-15, g2_sigma)'
[[Correlations]] (unreported correlations are < 0.500)
C(g1_sigma, g1_amplitude) = 0.824
C(g2_sigma, g2_amplitude) = 0.815
C(exp_decay, exp_amplitude) = -0.695
C(g1_sigma, g2_center) = 0.684
C(g1_center, g2_amplitude) = -0.669
C(g1_center, g2_sigma) = -0.652
C(g1_amplitude, g2_center) = 0.648
C(g1_center, g2_center) = 0.621
C(g1_sigma, g1_center) = 0.507
C(exp_decay, g1_amplitude) = -0.507

This script is in the file ``doc_builtinmodels_nistgauss2.py`` in the examples folder,
and the fit result shown on the right above shows an improved initial
Expand Down
26 changes: 13 additions & 13 deletions doc/confidence.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ starting point::
>>> result = mini.minimize()
>>> print(lmfit.fit_report(result.params))
[[Variables]]
a: 0.09943895 +/- 0.000193 (0.19%) (init= 0.1)
b: 1.98476945 +/- 0.012226 (0.62%) (init= 1)
[[Correlations]] (unreported correlations are < 0.100)
C(a, b) = 0.601
a: 0.09943896 +/- 1.9322e-04 (0.19%) (init = 0.1)
b: 1.98476945 +/- 0.01222678 (0.62%) (init = 1)
[[Correlations]] (unreported correlations are < 0.100)
C(a, b) = 0.601

Now it is just a simple function call to calculate the confidence
intervals::
Expand Down Expand Up @@ -102,15 +102,15 @@ uncertainties and correlations.
which will report::

[[Variables]]
a1: 2.98622120 +/- 0.148671 (4.98%) (init= 2.986237)
a2: -4.33526327 +/- 0.115275 (2.66%) (init=-4.335256)
t1: 1.30994233 +/- 0.131211 (10.02%) (init= 1.309932)
t2: 11.8240350 +/- 0.463164 (3.92%) (init= 11.82408)
[[Correlations]] (unreported correlations are < 0.500)
C(a2, t2) = 0.987
C(a2, t1) = -0.925
C(t1, t2) = -0.881
C(a1, t1) = -0.599
a1: 2.98622120 +/- 0.14867187 (4.98%) (init = 2.986237)
a2: -4.33526327 +/- 0.11527506 (2.66%) (init = -4.335256)
t1: 1.30994233 +/- 0.13121177 (10.02%) (init = 1.309932)
t2: 11.8240351 +/- 0.46316470 (3.92%) (init = 11.82408)
[[Correlations]] (unreported correlations are < 0.500)
C(a2, t2) = 0.987
C(a2, t1) = -0.925
C(t1, t2) = -0.881
C(a1, t1) = -0.599
95.45% 68.27% _BEST_ 68.27% 95.45%
a1: -0.27286 -0.14165 2.98622 +0.16353 +0.36343
a2: -0.30444 -0.13219 -4.33526 +0.10688 +0.19683
Expand Down
Loading

0 comments on commit f02bc9e

Please sign in to comment.