lmfit / lmfit-py

Non-Linear Least Squares Minimization, with flexible Parameter settings, based on scipy.optimize, and with many additional classes and methods for curve fitting.
https://lmfit.github.io/lmfit-py/
Other
1.04k stars 271 forks source link

Sketch for a stateless Model #107

Closed danielballan closed 9 years ago

danielballan commented 9 years ago

I think removing any state or reference to specific params from Model would actually be only a small change. Here's an sketch of how the API would shake out, expanding on remarks in #106.

result = model.fit(data, params)  # or keyword args, as now

# As now, the result stores certain useful copies of the params.
# These can be examined by the user or passed back into model.fit() later.
result.params
result.init_params

# Add this:
result.eval(x=x)  # any x, perhaps denser for prettier curve

model.eval()  # NOT VALID -- supplanted by `result.eval()`
model.eval(some_params)  # valid -- useful for exploring the model

The only downside of this is, as mentioned in #106, is less succinct auto-guessing. I kind of like this though -- it makes it clear what the model is using and makes it easy for the user to examine the auto-guessed parameters as needed.

guess = model.guess_starting_values(data)   # rename this method guess() for brevity?
model.fit(data, params=guess)

I agree we should take our time with this and collect input. I'm just jotting this down while it's on my mind.

tritemio commented 9 years ago

@newville I sent you an email with all the info, thanks!

newville commented 9 years ago

OK, I think this is complete with 0.8.0rc4 and I'm closing this issue and long discussion. Yea!