Skip to content

[Bug]: CurveFit.fit() accepts incorrectly structured initial guesses and bounds #59

Description

@sepandhaghighi

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

  1. 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],
)
  1. Provide an incorrectly sized initial guess:
fit.fit(initial_guess=[1.0])
  1. Alternatively, provide incorrectly sized bounds:
fit.fit(
    bounds=(
        [1e-10],
        [np.inf],
    )
)
  1. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions