--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/ff67ca37-e1b1-436e-8a34-c56e3f09a31an%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/CA%2B7ESbrJs%2B-Nu1qmW0DwTLdnH%3Dn7yQSQXoQbAz2TZdskK85aRw%40mail.gmail.com.
Thank you for replying to my question.I have a very big equation with almost 20 parameters that are provided automatically, so I should drive equation by sympy and then pass it to lmfit to fit it and find parameters.
Automatically drived parameters is hard to passe explicitly in a function. Can I pass my func model by callable instance of a class??
Or as I found in lmfit documents, the lambdifed sympy expression can be passed to model. Can I use this approach for very big equation??
Than you MattCan I ask how nonindependent variables (x) can be passed in function using **kwargs?
As you stated:
from lmfit import Model, Parameters
def my_poly(x, **params):
val= 0.0
parnames = sorted(params.keys())
for i, pname in enumerate(parnames):
val += params[pname]*x**i
return val
my_model = Model(my_poly)
# Parameter names and starting values
params = Parameters()
params.add('C00', value=-10)
params.add('C01', value= 5)
params.add('C02', value= 1)
params.add('C03', value= 0)
params.add('C04', value= 0)
x = np.linspace(-20, 20, 101)
y = -30.4 + 7.8*x - 0.5*x*x + 0.03 * x**3 + 0.009*x**4
y = y + np.random.normal(size=len(y), scale=0.2)
out = my_model.fit(y, params, x=x)
In fact I need to pass independent variables x1, x2, ... in similar way to parameters. Will it be possible?
--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/CA%2B7ESbrSAzO%2BTFgJWeNuH2Qm0RiARLX5qNqsP2%3DEmWRzkYTXTA%40mail.gmail.com.
I just have a dictionary of independent variables.How can pass them in function, both parameters and independent variables that are dictionaries.
--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/CA%2B7ESbo3bvAEt4TAsDiy1zhRiTt9HdpoXnp%3DDcOr%2BWYP596-zw%40mail.gmail.com.
Dear MattCan I use minmization instead to fit, to find my parameters, this way there's is no need to pass the independent variables explicitly and parameters can be passed using kwargs.
Dear MattThanks for considering.I've tried to examine all the known fitting package in python like symfit, scipy, lmfit to consider my issue which is:wrapping a code which gets, expr, list_var, list_para, dict_data, do some fitting and gives fitted parameters.Because all the named inputs are changing dynamically based on user input, so seemingly it is impossible to define or write fit_function explicitly:def fit_function(expr, list_var, list_para, dict_data(key_var,list_data) ) ->list_para:
AS a function to be used for any expression, any number of variables/parameters.Please let me know weather I'm not going in right way, so any suggestion eagerly will be welcomed.RegardsOn Wednesday, August 3, 2022 at 10:27:00 PM UTC+4:30 Matt Newville wrote:On Wed, Aug 3, 2022 at 12:10 PM Zohreh Karimzadeh <z.kari...@gmail.com> wrote:Dear MattCan I use minmization instead to fit, to find my parameters, this way there's is no need to pass the independent variables explicitly and parameters can be passed using kwargs.Yes. Using `minimize` you would have to manage any concept like "the data" or "independent parameters" on your own, inside the objective function.Please read the docs and study the examples. If you have follow-up questions, include actual code and ask questions about that.--Matt
--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/ae98e75f-d64f-4268-9024-2bf96aa2e396n%40googlegroups.com.
Dear Matt
Thanks for considering.I've tried to examine all the known fitting package in python like symfit, scipy, lmfit to consider my issue which is:wrapping a code which gets, expr, list_var, list_para, dict_data, do some fitting and gives fitted parameters.Because all the named inputs are changing dynamically based on user input, so seemingly it is impossible to define or write fit_function explicitly:def fit_function(expr, list_var, list_para, dict_data(key_var,list_data) ) ->list_para:
AS a function to be used for any expression, any number of variables/parameters.Please let me know weather I'm not going in right way, so any suggestion eagerly will be welcomed.Regards
On Wednesday, August 3, 2022 at 10:27:00 PM UTC+4:30 Matt Newville wrote:On Wed, Aug 3, 2022 at 12:10 PM Zohreh Karimzadeh <z.kari...@gmail.com> wrote:Dear MattCan I use minmization instead to fit, to find my parameters, this way there's is no need to pass the independent variables explicitly and parameters can be passed using kwargs.Yes. Using `minimize` you would have to manage any concept like "the data" or "independent parameters" on your own, inside the objective function.Please read the docs and study the examples. If you have follow-up questions, include actual code and ask questions about that.--Matt
--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/ae98e75f-d64f-4268-9024-2bf96aa2e396n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/49926874-208d-4a25-ae69-88fdadf1a076n%40googlegroups.com.
Dear Matt
Based on the lmfit documentation on github it is unclear whether more than one independent variable can be passed in mod.eval(params, ???) or not.
I'm looking forward to hearing from you.
from lmfit.models import ExpressionModel
expr = 'off + amp * exp(-x/x0) * sin(x*phase)'
mod = ExpressionModel(expr)
from numpy import exp, linspace, sin
off=0.25, amp=1.0, x0=2.0, phase=0.04
x = linspace(0, 10, 501)
params = mod.make_params(??????)x1=x1_vals, ...y = mod.eval(params, ???)
out = mod.fit(y, params, x=x)It worked pretty nice. As can be seen in code my first issue is done since the expr can be passed this way(green background color)
while I'm wondering if there is any way to do the following stuff:1. How params can be passed instead writing explicitly since it will be my user input.(Even after parsing expression or using evalast it should be passed not in the way is shown here.yellow background)
2. What if I have more than one independent variable that again needs to be passed not explicitly like params.(gray background)
--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/CA%2B7ESbq1c59c53-LhOep1TySA1erYxcwQJa%2BtNQH3gKVjhVK7A%40mail.gmail.com.
Dear Matt
--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/CA%2B7ESbqB2SdLig83%2By3ohiQ6Ft6SnB1Le89XB6Oo0L-8RBbx_A%40mail.gmail.com.