Skip to content

Commit f6aa1d9

Browse files
authored
Merge pull request #614 from lmfit/doc_emcee_fixes
doc and emcee_example fixes
2 parents f7b48b7 + 2d6ba40 commit f6aa1d9

File tree

4 files changed

+261
-83
lines changed

4 files changed

+261
-83
lines changed

doc/builtin_models.rst

+22-11
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,35 @@ All the models listed below are one-dimensional, with an independent
3434
variable named ``x``. Many of these models represent a function with a
3535
distinct peak, and so share common features. To maintain uniformity,
3636
common parameter names are used whenever possible. Thus, most models have
37-
a parameter called ``amplitude`` that represents the overall height (or
38-
area of) a peak or function, a ``center`` parameter that represents a peak
39-
centroid position, and a ``sigma`` parameter that gives a characteristic
40-
width. Many peak shapes also have a parameter ``fwhm`` (constrained by
41-
``sigma``) giving the full width at half maximum and a parameter ``height``
42-
(constrained by ``sigma`` and ``amplitude``) to give the maximum peak
43-
height.
37+
a parameter called ``amplitude`` that represents the overall intensity (or
38+
area of) a peak or function and a ``sigma`` parameter that gives a
39+
characteristic width.
4440

4541
After a list of built-in models, a few examples of their use are given.
4642

4743
Peak-like models
4844
-------------------
4945

5046
There are many peak-like models available. These include
51-
:class:`GaussianModel`, :class:`LorentzianModel`, :class:`VoigtModel` and
52-
some less commonly used variations. The :meth:`guess`
53-
methods for all of these make a fairly crude guess for the value of
54-
``amplitude``, but also set a lower bound of 0 on the value of ``sigma``.
47+
:class:`GaussianModel`, :class:`LorentzianModel`, :class:`VoigtModel`,
48+
:class:`PseudoVoigtModel`, and some less commonly used variations. Most of
49+
these models are *unit-normalized* and share the same parameter names so
50+
that you can easily switch between models and interpret the results. The
51+
``amplitude`` parameter is the multiplicative factor for the
52+
unit-normalized peak lineshape, and so will represent the strength of that
53+
peak or the area under that curve. The ``center`` parameter will be the
54+
centroid ``x`` value. The ``sigma`` parameter is the characteristic width
55+
of the peak, with many functions using :math:`(x-\mu)/\sigma` where
56+
:math:`\mu` is the centroid value. Most of these peak functions will have
57+
two additional parameters derived from and constrained by the other
58+
parameters. The first of these is ``fwhm`` which will hold the estimated
59+
"Full Width at Half Max" for the peak, which is often easier to compare
60+
between different models than ``sigma``. The second of these is ``height``
61+
which will contain the maximum value of the peak, typically the value at
62+
:math:`x = \mu`. Finally, each of these models has a :meth:`guess` method
63+
that uses data to make a fairly crude but usually sufficient guess for the
64+
value of ``amplitude``, ``center``, and ``sigma``, and sets a lower bound
65+
of 0 on the value of ``sigma``.
5566

5667
:class:`GaussianModel`
5768
~~~~~~~~~~~~~~~~~~~~~~~~~~~

doc/confidence.rst

+19-8
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,20 @@ parameters and set it manually:
106106
result.params[p].stderr = abs(result.params[p].value * 0.1)
107107

108108

109-
An advanced example
110-
-------------------
109+
.. _label-confidence-advanced:
110+
111+
An advanced example for evaluating confidence intervals
112+
---------------------------------------------------------
111113

112114
Now we look at a problem where calculating the error from approximated
113-
covariance can lead to misleading result -- two decaying exponentials. In
114-
fact such a problem is particularly hard for the Levenberg-Marquardt
115-
method, so we first estimate the results using the slower but robust
116-
Nelder-Mead method, and *then* use Levenberg-Marquardt to estimate the
117-
uncertainties and correlations.
115+
covariance can lead to misleading result -- the same double exponential
116+
problem shown in :ref:`label-emcee`. In fact such a problem is particularly
117+
hard for the Levenberg-Marquardt method, so we first estimate the results
118+
using the slower but robust Nelder-Mead method. We can then compare the
119+
uncertainties computed (if the ``numdifftools`` package is installed) with
120+
those estimated using Levenberg-Marquardt around the previously found
121+
solution. We can also compare to the results of using ``emcee``.
122+
118123

119124
.. jupyter-execute::
120125
:hide-code:
@@ -168,7 +173,13 @@ Plots of the confidence region are shown in the figures below for ``a1`` and
168173
plt.show()
169174

170175
Neither of these plots is very much like an ellipse, which is implicitly
171-
assumed by the approach using the covariance matrix.
176+
assumed by the approach using the covariance matrix. The plots actually
177+
look quite a bit like those found with MCMC and shown in the "corner plot"
178+
in :ref:`label-emcee`. In fact, comparing the confidence interval results
179+
here with the results for the 1- and 2-:math:`\sigma` error estimated with
180+
``emcee``, we can see that the agreement is pretty good and that the
181+
asymmetry in the parameter distributions are reflected well in the
182+
asymmetry of the uncertainties
172183

173184
The trace returned as the optional second argument from
174185
:func:`conf_interval` contains a dictionary for each variable parameter.

0 commit comments

Comments
 (0)