resuming fminsearch from where it's left

3 次查看(过去 30 天)
Hi everyone,
I am using fminsearch on simulink real-time system. It's called once in a while not peridoically but can say roughly every 1 s.
My real time sampling period is 1 ms. However, fminsearch takes about 2.5-3.5 ms causing system overload. That's not a problem for me because I don't need the optimizer result in the next 10 mseconds.
My problem is that there are some tasks that has to be executed every 1 ms. When overload occurs, this cannot be fulfilled for the next 3 iterations.
As a resolution, I was think of limiting the max number of function evaluations and max number of iterations to a value satisfying 1 ms execution period. Then, starting fminsearch from where it's left at the previous step. Currently, an optimization is completed in nearly 150 function evaluations.
However, I can't manage to change MaxFunEvals and MaxIter. By default, they are both set as '200*numberofvariables'. Matlab doesn't allow me to change MaxFunEvals or MaxIter to 50 (for example), It gives an error. So I tried '50*numberofvariables' but that doesn't limit the number of function evaluations to 50. What's the proper way of doing this?

回答(1 个)

Alan Weiss
Alan Weiss 2016-12-5
To set options, set an options structure using optimset, and then make sure that you pass the options structure to fminsearch, as in this example. Don't use optimset inside a loop.
You can definitely set MaxFunEvals and MaxIter to positive integer values. If you find that you cannot, then you are most likely not passing the options structure to fminsearch.
Alan Weiss
MATLAB mathematical toolbox documentation
  2 个评论
Gorkem
Gorkem 2016-12-5
编辑:Gorkem 2016-12-5
so you are saying that I can do the following?
options = optimset('MaxFunEvals',50,'MaxIter',50);
x = fminsearch(fun,x0,options);
Alan Weiss
Alan Weiss 2016-12-5
Alan Weiss
MATLAB mathematical toolbox documentation

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Nonlinear Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by