Cancel objective function evaluation in Optimization

Dear Matlab Users,
Background:
I want to fit a model to my experimental data by using optimizers from Optimization Toolbox (so far I tried fminunc and fmincon). Thus, in the objective function I use a complex Matlab Model (including ODE) to get simulation results for all my experimental data points and then calculate the mean error between experimental and simulation data. The design variables are 5 input parameters to the simulation model. Due to the influence of the "real world" in my experimental data the objective function is non-smooth and not differentiable.
Problem:
The optimization algorithms sooner or later suggest a configuration of the design variables which leads to extremely long calculations within the ODE or a divergence in the simulation model. Even when setting physically reasonable upper and lower bounds for each design variable, some combinations of design variables will always lead to a physically impossible simulation (divergence or endless calculation time).
Is there a way to catch these cases and tell the optimization algorithm to try a new configuration of design variables and re-evaluate the objective function within the iteration? I can't find anything regarding this in the MATLAB help or forum, although this should be a common issue in optimization?
So far I can only use fminsearch optimization, as no big changes in the design variables are being done here.
Love to hear from some experts.
Best regards
Malte

댓글 수: 4

the objective function is non-smooth and not differentiable.
But the ode*() part itself: is that part twice differentiable? You need twice differentiable for the mathematics of ode45() and similar function. If it is but not then ode45() and similar will usually not notice, and will instead give possibly wrong answers; if it is but not then ode45() and similar will not always notice.
Hi Walter,
thanks for your response. I'm not sure if I got your answer right, but the problem is not within the ode. It is more a general problem, that the optimizer will sooner or later propose design variables, for which the simulation model can not be solved.
When the model cannot be solved, does the model get stuck in the ode ("extremely long calculations within the ODE" you said), or does the ODE produce nan or inf, or does the ODE finish normally but the optimizer is having trouble locating feasible points, or does the ODE finish normally but the optimizer is having trouble finding improvements over a configuration you would say is poor but techically within the constraints ?
The strategies are different for the different cases.
The model is getting stuck in the ode.

댓글을 달려면 로그인하십시오.

 채택된 답변

Malte Semmel
Malte Semmel 2021년 12월 3일

1 개 추천

The build-in event location functionalitiy of the ode can be used to force the ode to quit after a certain time. See answer of Jared Barber in this thread:

추가 답변 (1개)

Alan Weiss
Alan Weiss 2021년 12월 2일
편집: Alan Weiss 2021년 12월 2일
I think that you can write an output function for the ODE solver that will halt the solver if it takes too long or reaches too large a value. Something like the following (this is untested code, take it with a large grain of salt):
function status = myOutputFcn(t,y,flag)
persistent tm
status = 0;
switch flag
case 'init'
tm = tic;
case 'done'
% Nothing to do here
else
elapsed = toc(tm);
if elapsed > 5 % or any other time that is too large
status = 1; % stop the ODE solver
end
if norm(y) > 1e3 % or any other size that is too large
status = 1
end
end
Call the ODE solver with options:
options = odeset('OutputFcn',@myOutputFcn)
like this:
[t,y] = ode45(odefun,tspan,y0,options)
Then if you find that your ODE solver bailed through the output function you can set the objective function to NaN. Or maybe create a nonlinear constraint function that takes a positive value, such as the time or size of the ODE solution when it gets halted.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

댓글 수: 1

I think I found a similar solution to what you meant, Alan:
The build-in event location functionalitiy of the ode can be used to force the ode to quit after a certain time. See answer of Jared Barber in this thread:

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

질문:

2021년 12월 2일

답변:

2021년 12월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by