diff --git a/doc/_images/emcee_corner.png b/doc/_images/emcee_corner.png index 5a5995a7e..5f3233016 100644 Binary files a/doc/_images/emcee_corner.png and b/doc/_images/emcee_corner.png differ diff --git a/doc/builtin_models.rst b/doc/builtin_models.rst index fc91c76cc..c5debd4c7 100644 --- a/doc/builtin_models.rst +++ b/doc/builtin_models.rst @@ -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`` @@ -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 @@ -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 @@ -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. @@ -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 @@ -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 @@ -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 diff --git a/doc/confidence.rst b/doc/confidence.rst index 330f2fb20..546f5e02e 100644 --- a/doc/confidence.rst +++ b/doc/confidence.rst @@ -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:: @@ -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 diff --git a/doc/fitting.rst b/doc/fitting.rst index 845424688..32d5ddb24 100644 --- a/doc/fitting.rst +++ b/doc/fitting.rst @@ -404,10 +404,10 @@ Solving with :func:`minimize` gives the Maximum Likelihood solution:: >>> mi = lmfit.minimize(residual, p, method='Nelder', nan_policy='omit') >>> lmfit.printfuncs.report_fit(mi.params, min_correl=0.5) [[Variables]] - a1: 2.98623688 (init= 4) - a2: -4.33525596 (init= 4) - t1: 1.30993185 (init= 3) - t2: 11.8240752 (init= 3) + a1: 2.98623689 (init = 4) + a2: -4.33525597 (init = 4) + t1: 1.30993186 (init = 3) + t2: 11.8240752 (init = 3) >>> plt.plot(x, y) >>> plt.plot(x, residual(mi.params) + y, 'r') @@ -461,18 +461,19 @@ You can see that we recovered the right uncertainty level on the data:: median of posterior probability distribution -------------------------------------------- [[Variables]] - a1: 3.00395737 +/- 0.148140 (4.93%) (init= 2.986237) - a2: -4.34880797 +/- 0.129770 (2.98%) (init=-4.335256) - t1: 1.32070726 +/- 0.145682 (11.03%) (init= 1.309932) - t2: 11.7701458 +/- 0.505031 (4.29%) (init= 11.82408) - noise: 0.09774012 +/- 0.004329 (4.43%) (init= 1) - [[Correlations]] (unreported correlations are < 0.100) - C(a2, t2) = 0.982 - C(a2, t1) = -0.935 - C(t1, t2) = -0.892 - C(a1, t1) = -0.507 - C(a1, a2) = 0.203 - C(a1, t2) = 0.163 + a1: 2.99342394 +/- 0.15851315 (5.30%) (init = 2.986237) + a2: -4.34384999 +/- 0.12454831 (2.87%) (init = -4.335256) + t1: 1.32338403 +/- 0.14120290 (10.67%) (init = 1.309932) + t2: 11.7962437 +/- 0.48632272 (4.12%) (init = 11.82408) + noise: 0.09761521 +/- 0.00431795 (4.42%) (init = 1) + [[Correlations]] (unreported correlations are < 0.100) + C(a2, t1) = -0.965 + C(a2, t2) = 0.959 + C(t1, t2) = -0.927 + C(a1, a2) = -0.241 + C(a1, t2) = -0.168 + C(a2, noise) = -0.116 + C(t1, noise) = 0.107 >>> # find the maximum likelihood solution >>> highest_prob = np.argmax(res.lnprob) @@ -486,17 +487,16 @@ You can see that we recovered the right uncertainty level on the data:: >>> print(p) Maximum likelihood Estimation ----------------------------- - Parameters([('a1', ), - ('a2', ), - ('t1', ), - ('t2', )]) - + Parameters([('a1', ), + ('a2', ), + ('t1', ), + ('t2', )]) >>> # Finally lets work out a 1 and 2-sigma error estimate for 't1' >>> quantiles = np.percentile(res.flatchain['t1'], [2.28, 15.9, 50, 84.2, 97.7]) >>> print("1 sigma spread", 0.5 * (quantiles[3] - quantiles[1])) >>> print("2 sigma spread", 0.5 * (quantiles[4] - quantiles[0])) - 1 sigma spread 0.145719626384 - 2 sigma spread 0.292199907106 + 1 sigma spread 0.1414604069179637 + 2 sigma spread 0.453234685099423 Getting and Printing Fit Reports =========================================== diff --git a/doc/installation.rst b/doc/installation.rst index c6c9a5e26..6f67c0e40 100644 --- a/doc/installation.rst +++ b/doc/installation.rst @@ -13,16 +13,18 @@ Downloading and Installation .. _jupyter: https://jupyter.org/ .. _matplotlib: https://matplotlib.org/ .. _dill: https://github.com/uqfoundation/dill +.. _asteval: https://github.com/newville/asteval +.. _six: https://github.com/benjaminp/six Prerequisites ~~~~~~~~~~~~~~~ -The lmfit package requires `Python`_, `NumPy`_, and `SciPy`_. +The lmfit package requires `Python`_, `NumPy`_, `SciPy`_, `asteval`_, and `six`_. Lmfit works with Python versions 2.7, 3.4, 3.5, and 3.6. Support for Python 2.6 and 3.3 ended with lmfit versions 0.9.4 and 0.9.8, respectively. Scipy version -0.17 or higher, NumPy version 1.10 or higher, and six version 1.10 or higher are -required. +0.17 or higher, NumPy version 1.10 or higher, asteval version 0.9.12 or higher, +and six version 1.10 or higher are required. In order to run the test suite, either the `nose`_ or `pytest`_ package is required. Some functionality of lmfit requires the `emcee`_ package, some diff --git a/doc/model.rst b/doc/model.rst index 68210551f..63164635a 100644 --- a/doc/model.rst +++ b/doc/model.rst @@ -152,20 +152,20 @@ components, including a :meth:`fit_report` method, which will show:: [[Model]] Model(gaussian) [[Fit Statistics]] + # fitting method = leastsq # function evals = 35 # data points = 101 # variables = 3 - chi-square = 3.40884 - reduced chi-square = 0.03478 - Akaike info crit = -336.26371 - Bayesian info crit = -328.41835 + chi-square = 3.40883599 + reduced chi-square = 0.03478404 + Akaike info crit = -336.263713 + Bayesian info crit = -328.418352 [[Variables]] - amp: 8.88021829 +/- 0.113594 (1.28%) (init= 5) - cen: 5.65866102 +/- 0.010304 (0.18%) (init= 5) - wid: 0.69765468 +/- 0.010304 (1.48%) (init= 1) - [[Correlations]] (unreported correlations are < 0.100) - C(amp, wid) = 0.577 - + amp: 8.88021830 +/- 0.11359492 (1.28%) (init = 5) + cen: 5.65866102 +/- 0.01030495 (0.18%) (init = 5) + wid: 0.69765468 +/- 0.01030495 (1.48%) (init = 1) + [[Correlations]] (unreported correlations are < 0.100) + C(amp, wid) = 0.577 As the script shows, the result will also have :attr:`init_fit` for the fit with the initial parameter values and a :attr:`best_fit` for the fit with @@ -871,28 +871,29 @@ which prints out the results:: [[Model]] (Model(gaussian) + Model(line)) [[Fit Statistics]] + # fitting method = leastsq # function evals = 46 # data points = 101 # variables = 5 - chi-square = 2.57856 - reduced chi-square = 0.02686 - Akaike info crit = -360.45702 - Bayesian info crit = -347.38142 + chi-square = 2.57855517 + reduced chi-square = 0.02685995 + Akaike info crit = -360.457020 + Bayesian info crit = -347.381417 [[Variables]] - amp: 8.45931061 +/- 0.124145 (1.47%) (init= 5) - cen: 5.65547872 +/- 0.009176 (0.16%) (init= 5) - wid: 0.67545523 +/- 0.009916 (1.47%) (init= 1) - slope: 0.26484403 +/- 0.005748 (2.17%) (init= 0) - intercept: -0.96860201 +/- 0.033522 (3.46%) (init= 1) - [[Correlations]] (unreported correlations are < 0.100) - C(slope, intercept) = -0.795 - C(amp, wid) = 0.666 - C(amp, intercept) = -0.222 - C(amp, slope) = -0.169 - C(cen, slope) = -0.162 - C(wid, intercept) = -0.148 - C(cen, intercept) = 0.129 - C(wid, slope) = -0.113 + amp: 8.45931062 +/- 0.12414515 (1.47%) (init = 5) + cen: 5.65547873 +/- 0.00917678 (0.16%) (init = 5) + wid: 0.67545524 +/- 0.00991686 (1.47%) (init = 1) + slope: 0.26484404 +/- 0.00574892 (2.17%) (init = 0) + intercept: -0.96860202 +/- 0.03352202 (3.46%) (init = 1) + [[Correlations]] (unreported correlations are < 0.100) + C(slope, intercept) = -0.795 + C(amp, wid) = 0.666 + C(amp, intercept) = -0.222 + C(amp, slope) = -0.169 + C(cen, slope) = -0.162 + C(wid, intercept) = -0.148 + C(cen, intercept) = 0.129 + C(wid, slope) = -0.113 and shows the plot on the left. @@ -979,25 +980,24 @@ binary operator. A full script using this technique is here: which prints out the results:: [[Model]] - (Model(jump) Model(gaussian)) + (Model(jump) Model(gaussian)) [[Fit Statistics]] # fitting method = leastsq - # function evals = 27 + # function evals = 23 # data points = 201 # variables = 3 - chi-square = 21.48845 - reduced chi-square = 0.10853 - Akaike info crit = -443.39364 - Bayesian info crit = -433.48373 + chi-square = 21.6932855 + reduced chi-square = 0.10956205 + Akaike info crit = -441.486726 + Bayesian info crit = -431.576811 [[Variables]] - mid: 5 (fixed) - sigma: 0.62393255 +/- 0.012818 (2.05%) (init= 1.5) - center: 4.52795480 +/- 0.009261 (0.20%) (init= 3.5) - amplitude: 0.62852927 +/- 0.001783 (0.28%) (init= 1) - [[Correlations]] (unreported correlations are < 0.100) - C(center, amplitude) = 0.339 - C(sigma, amplitude) = 0.276 - + mid: 5 (fixed) + center: 4.52495463 +/- 0.00937255 (0.21%) (init = 3.5) + sigma: 0.62328669 +/- 0.01297258 (2.08%) (init = 1.5) + amplitude: 0.62362920 +/- 0.00179096 (0.29%) (init = 1) + [[Correlations]] (unreported correlations are < 0.100) + C(center, amplitude) = 0.338 + C(sigma, amplitude) = 0.276 and shows the plots: diff --git a/doc/whatsnew.rst b/doc/whatsnew.rst index 18ca10c1f..688a246ec 100644 --- a/doc/whatsnew.rst +++ b/doc/whatsnew.rst @@ -11,6 +11,17 @@ significant to the use and behavior of the library. This is not meant to be a comprehensive list of changes. For such a complete record, consult the `lmfit github repository`_. + +.. _whatsnew_099_label: + +Version 0.9.9 Release Notes +========================================== +Lmfit now uses the asteval (https://github.com/newville/asteval) package +instead of distributing its own copy. The minimum required asteval version +is 0.9.12, which is available on PyPi. If you see import errors related to +asteval, please make sure that you actually have the latest version installed. + + .. _whatsnew_096_label: Version 0.9.6 Release Notes diff --git a/lmfit/model.py b/lmfit/model.py index 8d88578c0..71bee9be3 100644 --- a/lmfit/model.py +++ b/lmfit/model.py @@ -1816,7 +1816,7 @@ def plot(self, datafmt='o', fitfmt='-', initfmt='--', xlabel=None, Keyword arguments for the axes for the fit plot. fig_kws : dict, optional Keyword arguments for a new figure, if there is one being created. - sinitial conditions for the fithow_init : bool, optional + show_init : bool, optional Whether to show the initial conditions for the fit (default is False). Returns