Skip to content

Commit

Permalink
move more material to README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jwuttke committed Mar 26, 2019
1 parent b5411be commit a1c1928
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 27 deletions.
80 changes: 61 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This is the home page of **lmfit**,
a self-contained C library for Levenberg-Marquardt
least-squares minimization and curve fitting.


# Background information

## History
Expand Down Expand Up @@ -37,30 +38,17 @@ the preferred form of citation is:

Joachim Wuttke: lmfit – a C library for Levenberg-Marquardt least-squares minimization and curve fitting. Version [], retrieved on [] from https://jugit.fz-juelich.de/mlz/lmfit.

# Usage
## Contact

* Concise documentation is available in form of manual pages:
* [lmfit(7)](http://apps.jcns.fz-juelich.de/man/lmfit.html): Summary.
* [lmmin2(3)](http://apps.jcns.fz-juelich.de/man/lmmin2.html):
Generic routine for minimizing whatever sum of squares.
* [lmmin(3)](http://apps.jcns.fz-juelich.de/man/lmmin.html):
Simpler legacy API without error estimates.
* [lmcurve(3)](http://apps.jcns.fz-juelich.de/man/lmcurve.html):
Simpler interface for fitting a parametric function f(x;p) to a data set y(x).
* Sample code:
* [curve fitting with lmcurve()]()
* [surface fitting as example for minimization with lmmin()]()
* [nonlinear equations solving with lmmin()]()
* Application questions:
* Constraining parameters
* Weighing data points
* Language bindings:
* https://github.com/jvail/lmfit.js by Jan Vaillant
For bug reports or suggestions, contact the maintainer: [email protected].

# Installation

## From source

Get the latest source archive (tgz) from
[Repository > Tags](https://jugit.fz-juelich.de/mlz/lmfit/tags).

Build&install are based on CMake. Out-of-source build is enforced. After unpacking the source, go to the source directory and do:

```
Expand All @@ -70,4 +58,58 @@ cmake ..
ctest
make
make install
```
```

## RPM Binaries

* https://apps.fedoraproject.org/packages/lmfit maintained by Miro Hrončok
* http://fr2.rpmfind.net/linux/rpm2html/search.php?query=lmfit

## Language bindings:

* https://github.com/jvail/lmfit.js by Jan Vaillant


# Usage

## Manual pages:

* [lmfit(7)](http://apps.jcns.fz-juelich.de/man/lmfit.html): Summary.
* [lmmin2(3)](http://apps.jcns.fz-juelich.de/man/lmmin2.html):
Generic routine for minimizing whatever sum of squares.
* [lmmin(3)](http://apps.jcns.fz-juelich.de/man/lmmin.html):
Simpler legacy API without error estimates.
* [lmcurve(3)](http://apps.jcns.fz-juelich.de/man/lmcurve.html):
Simpler interface for fitting a parametric function f(x;p) to a data set y(x).

## Sample code:
* [curve fitting with lmcurve()](http://apps.jcns.fz-juelich.de/doku/sc/lmfit:basic-curve-fitting-example)
* [surface fitting as example for minimization with lmmin()](http://apps.jcns.fz-juelich.de/doku/sc/lmfit:surface-fitting-example)
* [nonlinear equations solving with lmmin()](http://apps.jcns.fz-juelich.de/doku/sc/lmfit:nonlinear-equations-example)


# FAQ

## How to constrain parameters?

In many applications, it is desirable to impose constraints like p0>=0 or 10<p1<10.

In lmfit, there is no explicit for mechanism for this, and it is unlikely that I will ever add one: In my experience, it is sufficient to mimick constraints by variable transform or by adding a penalty to the sum of squares. Variable transform seems to be the better solution.

In the above examples: To enforce p0'>0, use e.g. p0'=exp(p0) or p0'=p0^2. To enforce -10<p1'<10, use p1'=10*tanh(p1).

## How to weigh data points?

In least-squares curve fitting, data points _y_(_x_) are approximated by function values _f_(_x_;**p**). Sometimes, one wants to assign data points a weight _w_(_x_). One then has to minimize the sum of squares of _w_*(_y_-_f_).

### How to implement

This can be implemented easily by copying _lmcurve.h_ and _lmcurve.c_, and modifying them in obvious ways, just introducing a new parameter _w_.

### How to choose weights

Assuming that data points _y_(_x_) follow Gaussian distributions with standard deviations _dy_(_x_), the appropriate weight is _w_(_x_) = 1 / _dy_(_x_).

### How to deal with Poisson-distributed data

Least-squares fitting is not justified for Poisson-distributed data -- except if the data are large enough (say, on average _y_ of the order of 10 or larger) so that the Poisson distribution is reasonably well approximated by a Gaussian with standard deviation _dy_=sqrt(_y_). When experimental data have on average too low values _y_ per channel, they should be binned into fewer channels with better statistics before any least-squares fitting.
4 changes: 2 additions & 2 deletions man/lmcurve.pod
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ Documentation: Creative Commons Attribution Share Alike

<a href="http://apps.jcns.fz-juelich.de/man/lmmin.html"><b>lmmin</b>(3)</a>
<p>
Homepage: <a href="http://apps.jcns.fz-juelich.de/lmfit">http://apps.jcns.fz-juelich.de/lmfit</a>
Homepage: <a href="https://jugit.fz-juelich.de/mlz/lmfit">https://jugit.fz-juelich.de/mlz/lmfit</a>

=end html

=begin man

\fBlmmin\fR(3)
.PP
Homepage: http://apps.jcns.fz-juelich.de/lmfit
Homepage: https://jugit.fz-juelich.de/mlz/lmfit

=end man

Expand Down
4 changes: 2 additions & 2 deletions man/lmfit.pod
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ Documentation: Creative Commons Attribution Share Alike
<a href="http://apps.jcns.fz-juelich.de/man/lmmin.html"><b>lmmin</b>(3)</a>
<a href="http://apps.jcns.fz-juelich.de/man/lmmin2.html"><b>lmmin2</b>(3)</a>
<p>
Homepage: <a href="http://apps.jcns.fz-juelich.de/lmfit">http://apps.jcns.fz-juelich.de/lmfit</a>
Homepage: <a href="https://jugit.fz-juelich.de/mlz/lmfit">https://jugit.fz-juelich.de/mlz/lmfit</a>

=end html

=begin man

\fBlmcurve\fR(3), \fBlmmin\fR(3), \fBlmmin2\fR(3)
.PP
Homepage: http://apps.jcns.fz-juelich.de/lmfit
Homepage: https://jugit.fz-juelich.de/mlz/lmfit

=end man

Expand Down
4 changes: 2 additions & 2 deletions man/lmmin.pod
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ Documentation: Creative Commons Attribution Share Alike
<a href="http://apps.jcns.fz-juelich.de/man/lmmin2.html"><b>lmmin2</b>(3)</a>,
<a href="http://apps.jcns.fz-juelich.de/man/lmcurve.html"><b>lmcurve</b>(3)</a>
<p>
Homepage: <a href="http://apps.jcns.fz-juelich.de/lmfit">http://apps.jcns.fz-juelich.de/lmfit</a>
Homepage: <a href="https://jugit.fz-juelich.de/mlz/lmfit">https://jugit.fz-juelich.de/mlz/lmfit</a>

=end html

Expand All @@ -305,7 +305,7 @@ Homepage: <a href="http://apps.jcns.fz-juelich.de/lmfit">http://apps.jcns.fz-jue
\fBlmcurve\fR(3)
.PP

Homepage: http://apps.jcns.fz-juelich.de/lmfit
Homepage: https://jugit.fz-juelich.de/mlz/lmfit

=end man

Expand Down
4 changes: 2 additions & 2 deletions man/lmmin2.pod
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ Documentation: Creative Commons Attribution Share Alike
<a href="http://apps.jcns.fz-juelich.de/man/lmmin.html"><b>lmmin</b>(3)</a>
<a href="http://apps.jcns.fz-juelich.de/man/lmcurve.html"><b>lmcurve</b>(3)</a>
<p>
Homepage: <a href="http://apps.jcns.fz-juelich.de/lmfit">http://apps.jcns.fz-juelich.de/lmfit</a>
Homepage: <a href="https://jugit.fz-juelich.de/mlz/lmfit">https://jugit.fz-juelich.de/mlz/lmfit</a>

=end html

Expand All @@ -318,7 +318,7 @@ Homepage: <a href="http://apps.jcns.fz-juelich.de/lmfit">http://apps.jcns.fz-jue
\fBlmcurve\fR(3)
.PP

Homepage: http://apps.jcns.fz-juelich.de/lmfit
Homepage: https://jugit.fz-juelich.de/mlz/lmfit

=end man

Expand Down

0 comments on commit a1c1928

Please sign in to comment.