Replies: 4 comments 1 reply
-
I actually have a working implementation of multi-signal fitting, used by me and a few colleagues since several years. I have hesitated to contribute it to lmfit because it relies on some Initially, my implementation was mixed with some custom models in an even larger Python file, which would make the scope of a patch huge, but I had started worked on creating a slightly cleaner branch and considering how to present it to the community. The recent mailing list question and you opening this discussion thread spurred me to spend an evening to prepare something I can share here. As it is an add-on rather than a change within the package, I simply attach two files here instead of making a pull request (zipped since .py-upload wasn't allowed). global_fit.zip contains global_fit.py which has the implementation but I would recommend to start reading demo_global_fit.py that has several examples of how it would be used. In your draft above, I think your In practice, I and my colleagues typically have data where each submodel fits 1D-signals of the same length, using the same independent variable array. Specifically, we have time-resolved mass spectra from pump–probe scans, and if you select the the ion yield for a handful of ion masses, this gives a handful of equally long signals as function of a common time coordinate. Instead of using the general Parts of my hackish implementation of |
Beta Was this translation helpful? Give feedback.
-
@erik-mansson Thanks. I gave your global fit a brief read but not (yet?) a more careful study. I think there is a lot of overlap with PrefixWrapper and what I sketched out. I think we can make a new class or two specifically for this. The idea of a "DataSet" that has a Model is sort of independent of multi-dataset fitting, but would make it a lot easier. And a "DataSet" might be useful even as a single thing. In my downstream codes for analysis and fitting, there is a loose definition of a "Data Group" - basically an empty container that expects naming conventions. But that allows a) multiple models to be perserved for a data set (compare Gaussian to Voigt, say) as a "fit history" for that data set. That sort of organization isn't too hard to expect that downstream apps would just naturally do that. But, if we had a DataSet class with this partially builtin, that might be useful (say, to be saved and re-loaded). One thing I would like to not have to assume is that Data Sets are the same length or shape, which I believe But, again, thanks! I think that is very helpful, and I'll look more closely at your code. |
Beta Was this translation helpful? Give feedback.
-
After having looked back at my code and at your ideas, I find three orthogonal topics:
My outlooks:
|
Beta Was this translation helpful? Give feedback.
-
@erik-mansson Thanks. I am pretty sure we want some sort of With A An example use case would be to creata Dataset A, fit that, then create Dataset B, and fit that. Then, a MultiDataset with Datasets A and B could be made, and a combined Parameters based on the best-fit Parameters for the datasets. Constraints could then be put on some of the parameters, and then the combined fit could be done. So having that ability to run a fit on a single Dataset seem important to me. I am wary of using |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
There was a question and suggestion (https://groups.google.com/g/lmfit-py/c/9fxjGs5TpPo/m/J7K_7QVrDAAJ ) to be be able to use Model for fitting multiple datasets. I think we should try to support this, and propose that we make a few new classes:
class DataSet
could have components ofdata
: the numeric datamodel
: an instance of aModel
(including composites, etc)label
: a string tag for the data that will be used for parameter names, so must match 'variable name' rules.model
(say,x
ortheta
)This
DataSet
could have methodsfit
,make_params
,eval
,guess
, and other methods associated withModel
andModelResult
. Maybe evenplot
?That is, we have been careful to have
Model
be generic, but if we make aDataSet
that has aModel
, I think that's OK.class MultipleDataSets
could then just be a dictionary ofDataSets
, keyed bylabel
and also with methods dsfit
,make_params
,eval
.Here, parameters would be prefixed with the DataSet tag (and maybe model component tags). As a near concrete example, let's say there is a Line+Gaussian model for some temperature-dependent data, and one expects the
center
andsigma
to move with temperature, but maybe in some expected (say, linear with temperature) way.So, if you have Datasets with tags ('temp050', 'temp100', 'temp150', 'temp200', 'temp250', 'temp300'), you would end up with Parameters names like
temp100_center
,temp150_sigma
,temp200_amplitude
, and so forth.By default, each of the Parameters would be independent, but the user could then impose constraints, perhaps something like:
The result of the fit could then have a ModelResult per DataSet, as well as an overall ModelResult.
Does this seem reasonable? Comments? Suggestions?
Beta Was this translation helpful? Give feedback.
All reactions