Contact details
me@sepand.tech
What happened?
CurveFit.fit() currently accepts initial_guess and bounds as sequences. The values are matched to free model parameters based on their declaration order.
This makes the API error-prone because users must know the parameter ordering, and incorrectly sized sequences are not explicitly validated before being passed to scipy.optimize.curve_fit().
Steps to reproduce
- Create a
CurveFit instance with a model containing multiple free parameters:
fit = CurveFit(
model_name="first_order",
time=[0, 1, 2, 3],
release_profile=[0, 10, 18, 25],
)
- Provide an incorrectly sized initial guess:
fit.fit(initial_guess=[1.0])
- Alternatively, provide incorrectly sized bounds:
fit.fit(
bounds=(
[1e-10],
[np.inf],
)
)
- Observe how the invalid sequences are handled by
CurveFit.fit() and ultimately scipy.optimize.curve_fit().
Expected behavior
CurveFit.fit() should use parameter-name mappings for initial_guess and bounds, for example:
fit.fit(
initial_guess={
"M0": 100.0,
"k": 0.01,
},
bounds={
"M0": (1e-10, np.inf),
"k": (1e-10, np.inf),
},
)
The method should validate the supplied parameter names and values before calling scipy.optimize.curve_fit().
Invalid, missing, or unknown parameter entries should result in a clear ValueError.
Actual behavior
CurveFit.fit() currently relies on positional sequences:
initial_guess=[1.0, 0.01]
bounds=([1e-10, 1e-10], [np.inf, np.inf])
The API does not identify parameters by name, so callers must know the internal parameter declaration order. Incorrectly sized sequences are not explicitly validated by CurveFit.fit() and may result in errors from the underlying SciPy optimizer.
Operating system
Linux
Python version
Python 3.11
Drux version
Drux 0.4
Relevant log output
Contact details
me@sepand.tech
What happened?
CurveFit.fit()currently acceptsinitial_guessandboundsas sequences. The values are matched to free model parameters based on their declaration order.This makes the API error-prone because users must know the parameter ordering, and incorrectly sized sequences are not explicitly validated before being passed to
scipy.optimize.curve_fit().Steps to reproduce
CurveFitinstance with a model containing multiple free parameters:CurveFit.fit()and ultimatelyscipy.optimize.curve_fit().Expected behavior
CurveFit.fit()should use parameter-name mappings forinitial_guessand bounds, for example:The method should validate the supplied parameter names and values before calling
scipy.optimize.curve_fit().Invalid, missing, or unknown parameter entries should result in a clear
ValueError.Actual behavior
CurveFit.fit()currently relies on positional sequences:The API does not identify parameters by name, so callers must know the internal parameter declaration order. Incorrectly sized sequences are not explicitly validated by
CurveFit.fit()and may result in errors from the underlying SciPy optimizer.Operating system
Linux
Python version
Python 3.11
Drux version
Drux 0.4
Relevant log output