lmfit/lmfit-py — pull request #147 by newville (2014-11-03 02:43:22+00:00)
Title: add ExpressionModel(): a Model derived from a user-supplied expression

This PR adds an `ExpressionModel` class that creates a `Model` from a user-supplied expression. Essentially any python expression is supported, and many built-in functions (including the majority of numpy ufuncs, the majority of python builtins, and the functions in the `lineshapes` modules) are available for creating expressions. For example

```python
from lmfit.models import ExpressionModel
mod = ExpressionModel('alpha * exp(-x*beta) * sin(x * gamma)')
```
will create a Model with parameters `alpha`, `beta`, and `gamma` -- the default independent variable is `x`, though this can be set explicitly to something else.

This uses the `asteval` module (also used for constraint expressions), with each `ExpressionModel` getting its own asteval interpreter. `ExpressionModel` also allows an `init_script` argument, which gives a Python (well, as supported by asteval -- no imports) script to be run prior to parsing the user-supplied expression. With this, a user can build fairly complex models.

The main advantage of this approach is that the model can be defined at run-time, so that (for example) a GUI fitting program might allow users to build their own fitting models with this class.

The PR includes changes (perhaps initial version?) to the documentation as well as code.