summaryrefslogtreecommitdiff
path: root/lmfit.egg-info/PKG-INFO
blob: 3693dc6b628cf3ac021e398c26d698d0823b9104 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
Metadata-Version: 2.1
Name: lmfit
Version: 1.1.0
Summary: Least-Squares Minimization with Bounds and Constraints
Home-page: https://lmfit.github.io//lmfit-py/
Author: LMFit Development Team
Author-email: matt.newville@gmail.com
License: BSD 3-Clause
Project-URL: Source, https://github.com/lmfit/lmfit-py
Project-URL: Changelog, https://lmfit.github.io/lmfit-py/whatsnew.html
Project-URL: Documentation, https://lmfit.github.io/lmfit-py/
Project-URL: Tracker, https://github.com/lmfit/lmfit-py/issues
Keywords: curve-fitting,least-squares minimization
Platform: any
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.7
Description-Content-Type: text/x-rst
Provides-Extra: dev
Provides-Extra: doc
Provides-Extra: test
Provides-Extra: all
License-File: LICENSE
License-File: AUTHORS.txt

LMfit-py
========

.. image:: https://dev.azure.com/lmfit/lmfit-py/_apis/build/status/lmfit.lmfit-py?branchName=master
    :target: https://dev.azure.com/lmfit/lmfit-py/_build/latest?definitionId=1&branchName=master

.. image:: https://codecov.io/gh/lmfit/lmfit-py/branch/master/graph/badge.svg
  :target: https://codecov.io/gh/lmfit/lmfit-py

.. image:: https://img.shields.io/pypi/v/lmfit.svg
   :target: https://pypi.org/project/lmfit

.. image:: https://img.shields.io/pypi/dm/lmfit.svg
   :target: https://pypi.org/project/lmfit

.. image:: https://img.shields.io/badge/docs-read-brightgreen
   :target: https://lmfit.github.io/lmfit-py/

.. image:: https://zenodo.org/badge/4185/lmfit/lmfit-py.svg
   :target: https://zenodo.org/badge/latestdoi/4185/lmfit/lmfit-py

.. _LMfit mailing list: https://groups.google.com/group/lmfit-py


Overview
---------

LMfit-py provides a Least-Squares Minimization routine and class with a simple,
flexible approach to parameterizing a model for fitting to data.

LMfit is a pure Python package, and so easy to install from source or with
``pip install lmfit``.

For questions, comments, and suggestions, please use the `LMfit mailing list`_.
Using the bug tracking software in GitHub Issues is encouraged for known
problems and bug reports. Please read
`Contributing.md <.github/CONTRIBUTING.md>`_ before creating an Issue.


Parameters and Fitting
-------------------------

LMfit-py provides a Least-Squares Minimization routine and class with a simple,
flexible approach to parameterizing a model for fitting to data. Named
Parameters can be held fixed or freely adjusted in the fit, or held between
lower and upper bounds. In addition, parameters can be constrained as a simple
mathematical expression of other Parameters.

To do this, the programmer defines a Parameters object, an enhanced dictionary,
containing named parameters::

    fit_params = Parameters()
    fit_params['amp'] = Parameter(value=1.2, min=0.1, max=1000)
    fit_params['cen'] = Parameter(value=40.0, vary=False)
    fit_params['wid'] = Parameter(value=4, min=0)

or using the equivalent::

    fit_params = Parameters()
    fit_params.add('amp', value=1.2, min=0.1, max=1000)
    fit_params.add('cen', value=40.0, vary=False)
    fit_params.add('wid', value=4, min=0)

The programmer will also write a function to be minimized (in the least-squares
sense) with its first argument being this Parameters object, and additional
positional and keyword arguments as desired::

    def myfunc(params, x, data, someflag=True):
        amp = params['amp'].value
        cen = params['cen'].value
        wid = params['wid'].value
        ...
        return residual_array

For each call of this function, the values for the ``params`` may have changed,
subject to the bounds and constraint settings for each Parameter. The function
should return the residual (i.e., ``data-model``) array to be minimized.

The advantage here is that the function to be minimized does not have to be
changed if different bounds or constraints are placed on the fitting Parameters.
The fitting model (as described in myfunc) is instead written in terms of
physical parameters of the system, and remains remains independent of what is
actually varied in the fit. In addition, which parameters are adjusted and which
are fixed happens at run-time, so that changing what is varied and what
constraints are placed on the parameters can easily be modified by the user in
real-time data analysis.

To perform the fit, the user calls::

    result = minimize(myfunc, fit_params, args=(x, data), kws={'someflag':True}, ....)

After the fit, a ``MinimizerResult`` class is returned that holds the results
the fit (e.g., fitting statistics and optimized parameters). The dictionary
``result.params`` contains the best-fit values, estimated standard deviations,
and correlations with other variables in the fit.

By default, the underlying fit algorithm is the Levenberg-Marquardt algorithm
with numerically-calculated derivatives from MINPACK's lmdif function, as used
by ``scipy.optimize.leastsq``. Most other solvers that are present in ``scipy``
(e.g., Nelder-Mead, differential_evolution, basinhopping, etctera) are also
supported.