I am working with the lmfit python package https://lmfit.github.io/lmfit-py/ for fitting data to a specified non-linear function within certain permitted ranges of variation for some parameters (which is mainly why I found lmfit attractive).
Generally the two important lines of code for lmfit are;
def fcn2min(params, x_data, y_data):
result = minimize(fcn2min, params, args=(x_data, y_data))
My application is to perform a global fit across 36 graphs of data. The catch is that a few parameters are not being fitted for (vary=None), are known quantities, and vary across all 36 graphs but remain the same within their own graph. Currently I am trying to implment the following syntax in order to pass these known parameters with their associated x_data and y_data points.
def fcn2min(params, x_data, y_data, known_params):
result = minimize(fcn2min, params, args=(x_data, y_data, known_params))
Here x_data, y_data, and known_params are arrays of the same length. x_data and y_data consists of a single arrays of all 36 graphs, and known_params is a three column array with repeating entries for those parameters that are fixed in each graph.
At the moment the program is running pretty slow (30 minutes till execution is finished). Also at the moment the fitted curve is the same for all graphs, whereas I want it to fit each local graph with the known parameters and fit to only the global parameters.
I would like to ask if am I doing this properly? I see why minimize() would need a reference to the y_data to be fitted, but why does fcn2min() need y_data as an input? Could my fitting program get confused whether it is fitting the y_data or the known_params array? Is there a better way to do this through lmfit or should I look for another numerical package?