I have a relatively complex plot which I would like to model. The model consists of two 'phases'/components which have been measured experimentally, however the ratio of these components is unknown. The data is shown in the image: where some combination of the orange and green curves make up the blue curve.
Complex curve and two components
The model is defined as:
Model = A * (z1 * 0.3 * y1 + z2 * 0.7 * y2) + D
where A is an overall scaling, z1 and z2 are the individual scalings for y1 and y2 which are the components. D is an offset.
I have tried to use the lmfit minimise function by defining the fit parameters and residual like so:
import lmfit
from lmfit import Minimizer, Parameters, report_fit
fit_params = Parameters()
fit_params.add('A', value=1.00, min=0, max=1)
fit_params.add('z1', value=1, min=0, max=1)
fit_params.add('z2', value=1, min=0, max=1)
fit_params.add('D', value=0.00, min=-5, max=5)
def residual(pars, x, data = total_scatter_expt):
Data = total_scatter_expt
Model = A * (z1 * 0.3 * y1 + z2 * 0.7 * y2) + D
return model - data
Because y1 and y2 are also functions it's no entirely clear to me what my x is in the residual or in the minimisation line. For this I have used the x values on the graph in the picture.
out = minimize(residual, fit_params, args=(x,))
print(fit_report(out))
This has led to the error
TypeError: can't multiply sequence by non-int of type 'float'
I'm not sure whether this problem would be best described as a deconvolution or perhaps fitting functions of functions. Any help would be appreciated.