[Python] Fitting multidimensional data with Python symfit ODEModel

Discussão em 'Python' iniciado por Stack, Setembro 11, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to fit the parameters of an ODE to data with two dimensions, which should generally be possible, according to the example Fitting multidimensional datasets.

    This is my failed attempt so far

    import symfit as sf
    import numpy as np

    # data
    x = np.arange(0,19)
    data = 10e-4 * np.array([8,10,12,11,10,15,25,37,46,40,43,35,27,14,8,10,13,9,10])
    data2 = 10e-3 * np.array([0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0])

    # model
    t, mp, inp = sf.variables('t, mp, inp')
    tau, w = sf.parameters('tau, w')
    model = {sf.D(mp, t): (-mp + inp * w) / tau }

    # fitting
    ode_model = sf.ODEModel(model, initial={inp: data2[0], t: 0.0, mp: data[0]})
    fit = sf.Fit(ode_model, inp=data2, t=x, mp=data)
    fit_result = fit.execute()


    It seems I'm not correctly defining inp in the model definition. I'm getting the following error TypeError: got an unexpected keyword argument 'inp' . I suspect that I'm making a mistake in providing inp as named_data to sf.Fit() as ist does not appear to be an independent variable in the model documentation sf.Fit()

    This is the full error message:

    /usr/local/lib/python3.10/dist-packages/symfit/core/fit.py in __init__(self, model, objective, minimizer, constraints, absolute_sigma, *ordered_data, **named_data)
    372 # Bind as much as possible the provided arguments.
    373 signature = self._make_signature()
    --> 374 bound_arguments = signature.bind_partial(*ordered_data, **named_data)
    375
    376 # Select objective function to use. Has to be done before calling

    /usr/lib/python3.10/inspect.py in bind_partial(self, *args, **kwargs)
    3191 Raises `TypeError` if the passed arguments can not be bound.
    3192 """
    -> 3193 return self._bind(args, kwargs, partial=True)
    3194
    3195 def __reduce__(self):

    /usr/lib/python3.10/inspect.py in _bind(self, args, kwargs, partial)
    3173 arguments[kwargs_param.name] = kwargs
    3174 else:
    -> 3175 raise TypeError(
    3176 'got an unexpected keyword argument {arg!r}'.format(
    3177 arg=next(iter(kwargs))))

    TypeError: got an unexpected keyword argument 'inp'


    Could someone help? Thank you so so much :)

    Continue reading...

Compartilhe esta Página