Provide gradient for fmincon when the function to minimize uses ODE

I am trying to fit a model to experimental points by using the function fmincon. The function I need to minimize is defined in a file called objfunction and is as following:
mi=zeros(n_exp,n_comp);
for i=1: n_exp
mi(i,:)=(pts_exp(i,:)-pts_mod(i,:)).^2;
end
Summin=sum(sum(mi));
Where pts_exp is a matrix obtained by solving differential equations using ode15s. I set the constraints (inequalities and bounds) and use fmincon:
[para,fval]=fmincon(@(para)objfunction(pts_exp,para,t_T_exp,n0,ordre,n_exp,n_comp,reactif,n_react),param0,A,b,Aeq,beq,lb,ub,nonlcon,options);
The vector para has 864 decision variables, all of them with lower and upper bounds and it takes around 10 minutes to optimize my problem. I know that providing the gradient and the hessian can make the code run faster but I do not know how to do it since my objective function uses a matrix given by ode15s. What I mean is that I do not have an analytical expression of my function as in f(x,y)=x+y or something like that. Is there any way of providing the gradient or making the code run faster?
Any help is greatly appreciated!

Answers (1)

Look up "sensitivity equations for ordinary differential equations".
The solution of these equations give you the derivative of the ODE solution with respect to the parameters.
Best wishes
Torsten.

4 Comments

The technique that Torsten refers to is outlined in the documentation topic Use a Gradient Evaluation Function. To do this involves solving a larger set of ODEs than the original set (you would need 864 new variables in your ODE). So it is not clear to me whether there would be a worthwhile speedup. But, if it is important to you, then you can try and see.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Thank you Torsten and Alan,
My main goal is to reduce computational time, I will take a look at the documentation. I know that computational time does not only depend on the number of variables but other factors as well, but I was wondering if the computational time I get for my number of variables, boundaries and constraints and the fact that the code involves solving ODE is considered "normal". It is my first time using fmincon so I do not know if it is possible to give an estimate on computational time.
I would like to know because in the future I might have more variables and I'd like to know if I should look at alternatives to optimize my function or if by improving my code fmincon will be a good tool to use.
Thank you
More than 864 parameters to be fitted ? You are kidding, aren't you ?
I have a set of 27 chemical reactions and 30 components and I am trying to optimize the stoichiometric coefficients as well as kinetic parameters, not all components intervene in all reactions though and I set those coefficients to zero in the vector containing the decision variables and lower and upper bounds for the optimization to zero as well, (maybe I am going the wrong way about that) so yes, I might have more than 864 parameters

Sign in to comment.

Products

Release

R2017b

Asked:

FM
on 8 Oct 2018

Commented:

FM
on 9 Oct 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!