pythondata-fittingsymfit

Global Fitting with Symfit: typestructure of dataset


I want to perform a global fitting of datasets with shared variables using symfit. I have a numpy array xdata which is common for all datasets ydata_i which are also numpy arrays.

Following the example in the documentation a can setup the variables, the parameters and the model but I fail to setup the fit: fit = Fit(model, x_1=xdata_1, x_2=xdata_2, ..., y_1=ydata_1, y_2=ydata_2, ...)

For a small number of datasets I can write the code by hand or copy/paste it but I have hundred datasets and I hope I can avoid type in the code by hand. I tried to use lists [xdata, ydata_1, ydata2, ...] or [xdata, ydata_1, xdata, ydata2, ...] or arrays but this seems not to be the right way.

Does anyone know how the structure/type of the ordered_data should look like. Thanks


Solution

  • For a large number of datasets you can use a dictionary:

    data = {'x_1': xdata_1, 'x_2': xdata_2, ..., 'y_1': ydata_1, 'y_2': ydata_2, ...}
    fit = Fit(model, **data)
    

    This way it will end up in named_data instead, which is preferred. Good luck!

    p.s. you might also want to consider using a JacobianModel or a CallableModel instead of the default model if you are working with such large models, because calculating the jacobian and hessian for such a model might be expensive and unnecessary.