Skip to content

How to handle default arguments in fit function in curve_fit? #3463

@jokasimr

Description

@jokasimr

Currently scipp.curve_fit ignores if an argument to the model function has a default value or not:

from functools import partial

import scipp as sc


def model(x, a, b=2):
    return a * x + b


x = sc.linspace('x', 0, 10, 100)
y = model(x, a=0.5, b=2)
da = sc.DataArray(y, coords={'x': x})

popt, _ = sc.curve_fit(['x'], model, da, p0={'a': 1.0})
# Both a and b are among the parameters
#DataGroup(sizes={}, keys=[
#    b: DataArray({}),
#   a: DataArray({}),
#])

This is different from the scipy.optimize.curve_fit implementation where default arguments are ignored.

It would be good to do the same thing everywhere. I don't really see strong reasons for doing it either way. It's conceptually simpler (imo) to just say that the function doesn't care about if an argument has a default value or not. But it can also lead to surprises, for example when using partial since keyword arguments set by partial can still be overridden, and thus using partial with scipp.curve_fit does nothing.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions