MATLAB Answers

0

Question regarding passing input arguments in fmincon

Asked by Deepa Maheshvare on 23 Apr 2019
Latest activity Edited by Deepa Maheshvare on 26 Apr 2019
Hi All,
I am solving an optimization problem.There are no equality constraints in my model. I want to pass ODEs as constraint to fmincon using,non-linear constraint, nlcon argument .
The function model contains odes
function dz = model(t, z, c)
dz(1) = ..
dz(2) = ..
I'd like to ask how the ode intergrator has to be called in the place of nlcon in fmincon(@objective,p0,A,b,Aeq,beq,lb,ub,nlcon).
%p0 = Initial Value of Parameters
A = [];
b = [];
Aeq = [];
beq = [];
nlcon = ode45(@(t,z)model(t,z,x), tSpan, z0); % Is this correct?
p = fmincon(@objective,p0,A,b,Aeq,beq,lb,ub,nlcon);
Since the ode function is already called in nlcon , is it required to call the function model again inside the objective function?
function cost = objective(c,time_exp,expZ,tSpan,z0)
sol = ode45(@(t,z)model(t,z,c), tSpan, z0); % Is this step required?
ModelZ = deval(sol, time_exp);
cost = ModelZ-expZ;
Any help would be highly appreciated.

  14 Comments

The bounds lb and ub refered to in "nonlincon" do not store bounds for the parameters, but for the solution vector of your ODE (you wrote you wanted to restrict the values of the solution at all times to be in a certain range). If you want to use bounds for the parameters as well, you can do this directly in the call to "fmincon".
Note that lb, ub are of the same size as z0 in "nonlincon", not of the same size as the parameter vector x.
Note also that you should allocate c as
c = zeros(2*n*m,1);
before entering the double loop.
And set
ceq = [];
at the end of the function.
Hi Torsten,
Thanks a ton for all the clarifications.
Since my model is in xml file , I am using SimBiology toolbox .I have created a model object using
modelObj = sbmlimport('Model.xml')
cs = getconfigset(modelObj);
cs.SolverType = 'ode15s';
cs.StopTime = 24;
[t, x, names] = sbiosimulate(modelObj);
There is a function call available for parameter estimation in SimBiology toolbox.
sbiofit(model,estimatedParam,'fmincon')
However, I am not sure how the input arguments of the estimation method,fmincon, has to be passed.I have a confusion here,
I've already specified p0,lb,ub in estimatedParam array with properties Name, InitialValue and Bounds
estimatedParams = estimatedInfo(paramsToEstimate,'InitialValue',ParameterInitialValues,'Bounds',ParameterBounds)
Moreover, for the other arguments that have to be passed in the function call to fmincon,
fmincon(@objective,p0,A,b,Aeq,beq,lb,ub,nlcon)
p0 , lb,ub are already defined in estimatedParam in sbiofit(model,estimatedParam,'fmincon')
I'm not sure how to set up A=[],b=[],Aeq=[],beq = [] and define nlcon since the model is in xml format.
Could you please provide some suggestions on how to proceed?
Sorry, but I don't have experience with the SimBiology toolbox.

Sign in to comment.

1 Answer

Answer by Alan Weiss
on 23 Apr 2019

I am not sure that I understand what you mean by "I want to pass ODEs as a constraint to fmincon." What about the ODE solution is a constraint? Do you want the minimum value of the solution to be above zero? Do you want the ODE solution to lie in a certain box? Once you explicitly define what you mean by the ODE solution is a "constraint," then I think that the answer to your question will be obvious. You will solve the ODE, get sol, and then write the constraint in terms of sol, maybe fun(deval(sol,tspan)) for some appropriate function fun and set of times tspan.
Alan Weiss
MATLAB mathematical toolbox documentation

  4 Comments

Show 1 older comment
I still do not understand precisely what you are trying to do, so cannot give you a very detailed answer.
If you want your steady-state values to be in a certain range, then you probably want to restrict deval(sol,lasttime), where lasttime is the final time. But if you just want to restrict the steady-state, then probably you shouldn't solve an ODE anyway, just the steady-state equations, which would be an fsolve call, finding the location where dz = zeros(size(z0)).
Maybe you want to restrict the values of the solution at all times to be in a certain range, not just the final values. In that case, you would set constraints on deval(sol,tspan), where tspan is the set of times that you want to restrict.
Maybe you are trying to fit your ODE solution to some observed (measured) values as a function of time. In that case, follow the procedures in this example.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Hi,
I'm sorry , I haven't explained it clearly.
"Maybe you are trying to fit your ODE solution to some observed (measured) values as a function of time."
No, the experimental measurements are all steady state values. For example , for the variable z1, there are 5 experimental studies that report the steady state value from experiment(z1_exp1,z1_exp2,z1_exp3,z1_exp4,z1_exp5). This gives me a range i.e. bound
z1_max and z1_min.
With z1_max and z1_min as the constraint , I wish to do the following
" restrict the values of the solution at all times to be in a certain range, not just the final values".Therefore, I am not sure whether it is appropriate to use lsqcurvefit ,used in the suggestions provided,for my problem.
Sorry, I am unable to understand what you are trying to do, so this will be my last reply. I suggest that you write out equations or inequalities describing your constraint. Seriously, write them down. Then, given those equations or inequalities, you can write a corresponding nonlinear constraint function in fmincon syntax, restricting the result by using deval on the solution at relevant times. If you don't understand what I am suggesting, sorry, maybe someone else can help.
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.