overriding params in the function

18 views
Skip to first unread message

Giulio de Vito

unread,
Jun 25, 2019, 4:30:45 AM6/25/19
to lmfit-py

Hi everyone,

I use lmfit and I need to modify some parameters' values inside the fitting function:

the parameters are:

params = Parameters()
params.add('k3', value=k3guess, max=-1e-7, vary = True)
params.add('lb', value=lb, min=w[0], max=w[-1], vary = False)
params.add('mu', value=muguess, min=0, vary = True)
params.add('K', value=K, min=0, vary = False)

my fitting function is:

def firstham(w, amp, k3, lb, mu, K):

...
inside this function I have some controlling values likes:
k3=k3/2


I noticed that even thou the paramters change inside the fitting function, at the end of the fitting in fit_report I won't get the last correct parameters value, why?

Another question, in the guide it is written: **kwargs (optional) – Arguments to pass to the model function, possibly overriding params

How can I pass the params to the function?

thank you,
Giulio

Matt Newville

unread,
Jun 25, 2019, 7:27:59 AM6/25/19
to lmfit-py
On Tue, Jun 25, 2019 at 3:30 AM Giulio de Vito <giulio...@gmail.com> wrote:

Hi everyone,

I use lmfit and I need to modify some parameters' values inside the fitting function:

Why do you need to do that?


the parameters are:

params = Parameters()
params.add('k3', value=k3guess, max=-1e-7, vary = True)
params.add('lb', value=lb, min=w[0], max=w[-1], vary = False)
params.add('mu', value=muguess, min=0, vary = True)
params.add('K', value=K, min=0, vary = False)

my fitting function is:

def firstham(w, amp, k3, lb, mu, K):

...
inside this function I have some controlling values likes:
k3=k3/2


I noticed that even thou the paramters change inside the fitting function, at the end of the fitting in fit_report I won't get the last correct parameters value, why?


Well, because it reports what the fitting procedure sent to your model function.   It cannot know what you do with those values inside the model function.

If you're doing `k3 = k3/2`, why not send in a value that represents the new value of `k3`?  And maybe call *that* `k3`.


Another question, in the guide it is written: **kwargs (optional) – Arguments to pass to the model function, possibly overriding params

How can I pass the params to the function?


If you have keyword arguments in your model function, you can send them in there.  Your model function appears to not have those.

Of course, it would almost certainly help if you posted a more complete example of what you are trying to do.

--Matt 
Reply all
Reply to author
Forward
Message has been deleted
0 new messages