You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I assume that the current behavior is intended, so I consider this a feature request.
By default, all model function arguments are turned into model parameters unless they are an independent variable or they have a non-numeric default value. Those arguments with a default value get turned into parameters with that as their initial value. However, when explicitly choosing the parameters using param_names, this stops being true and one has to set all initial values manually which feels redundant.
It would be really nice if the initial values were derived from the default argument values even when using param_names.
A Minimal, Complete, and Verifiable example
importlmfitdeffoo(x, a=3, b=5, s=1):
returna+s*b*x**2print("\nDefault behavior:")
mdl=lmfit.Model(foo)
params=mdl.make_params()
forpname, parinparams.items():
print(pname, par)
print("\nExplicitly choosing parameter names:")
mdl=lmfit.Model(foo, param_names=['a', 'b'])
params=mdl.make_params()
forpname, parinparams.items():
print(pname, par)
print("\nWe have to explicitly set the initial values:")
mdl=lmfit.Model(foo, param_names=['a', 'b'])
mdl.set_param_hint('a', value=3)
mdl.set_param_hint('b', value=5)
params=mdl.make_params()
forpname, parinparams.items():
print(pname, par)
print("\nIn this particular case, we could cheat by using True instead of 1, but that's very hacky:")
deffoo(x, a=3, b=5, s=True):
returna+s*b*x**2mdl=lmfit.Model(foo)
params=mdl.make_params()
forpname, parinparams.items():
print(pname, par)
Output:
Default behavior:
a <Parameter 'a', value=3, bounds=[-inf:inf]>
b <Parameter 'b', value=5, bounds=[-inf:inf]>
s <Parameter 's', value=1, bounds=[-inf:inf]>
Explicitly choosing parameter names:
a <Parameter 'a', value=-inf, bounds=[-inf:inf]>
b <Parameter 'b', value=-inf, bounds=[-inf:inf]>
We have to explicitly set the initial values:
a <Parameter 'a', value=3, bounds=[-inf:inf]>
b <Parameter 'b', value=5, bounds=[-inf:inf]>
In this particular case, we could cheat by using True instead of 1, but that's very hacky:
a <Parameter 'a', value=3, bounds=[-inf:inf]>
b <Parameter 'b', value=5, bounds=[-inf:inf]>
Version information
Python: 3.9.18 | packaged by conda-forge | (main, Aug 30 2023, 03:40:31) [MSC v.1929 64 bit (AMD64)]
lmfit: 1.2.2, scipy: 1.11.3, numpy: 1.26.0,asteval: 0.9.31, uncertainties: 3.1.7
The text was updated successfully, but these errors were encountered:
lmfit
locked and limited conversation to collaborators
Nov 7, 2023
Description
I assume that the current behavior is intended, so I consider this a feature request.
By default, all model function arguments are turned into model parameters unless they are an independent variable or they have a non-numeric default value. Those arguments with a default value get turned into parameters with that as their initial value. However, when explicitly choosing the parameters using
param_names
, this stops being true and one has to set all initial values manually which feels redundant.It would be really nice if the initial values were derived from the default argument values even when using
param_names
.A Minimal, Complete, and Verifiable example
Output:
Version information
The text was updated successfully, but these errors were encountered: