I am using OdePkg in Octave to solve a system of stiff ODEs, e.g. by ode5r:
function yprime = myODEs(t,Y,param)
yprime = [
- param(1) * Y(1); # ODE for Y(1)
param(1) * Y(1) - param(2) Y(2) * Y(3); # ODE for Y(2)
param(2) Y(2) * Y(3) # ODE for Y(3)
# etc.
];
time_span = [1, 24] # time span of interest
Y0 = [1.0, 1.1, 1.3] # initial values for dependent variables Y
param = [7.2, 8.6, 9.5] # parameters, to be optimized
[t, Y] = ode5r(@myODEs, time_span, Y0, ..., param);
The solver stores the dependent variables Y in a matrix with respect to time t (vector):
t Y(1) Y(2) Y(3)
0.0 1.0 1.1 1.3
0.1 ... ... ...
0.5 ... ... ...
0.9 ... ... ...
... ... ... ...
4.0 ... ... ...
... ... ... ...
24.0 ... ... ...
I want to fit the parameters in param, so that the resulting variables Y best fit my reference values, e.g.:
t Y(1) Y(2) Y(3)
0.5 1.1 N/A N/A
1.0 1.9 N/A N/A
4.0 2.3 2.7 2.1
5.0 N/A 2.6 2.2
24.0 0.9 1.5 2.0
Which Octave/Matlab (other languages are welcome) routine can perform a multi-parameter (least square / spline) fit?
How is it possible to combine parameter sets for different initial values Y0 in the fit?
I would be glad if you could provide me with some hints and possibilities.
Best regards,
Simon
This should be relatively straightforward with scipy.
scipy.optimize.leastsq()takes a function that should return an array of residuals for a given parameter vector. It will minimize the sum of the squares of the residuals. To handle multiple datasets with different initial values, you just run the ODE once for each dataset, compute the residuals for each dataset/run pair, and then concatenate the residual vectors together. Here is a rough sketch: