Stopping fminsearch immediately?

12 ビュー (過去 30 日間)
Allan Paolo
Allan Paolo 2021 年 9 月 13 日
コメント済み: Walter Roberson 2021 年 9 月 13 日
So I have fminsearch running a custom function func, with outputs A, B, and C: [A, B, C] = func(x, y, z).
I used the function fminsearch to optimize the parameters x, y, and z. My problem is that it takes too long as it gets stuck on invalid trial values for x, y, and z. I was able to determine that this happens when the trial results A, B, and C are very large. While I know that fminsearch would self-correct and that it would just re-assign values of x, y, and z, I find this very slow and I wanted to just exit fminsearch.
Therefore, I wanted it such that fminsearch would stop when A >= 1000, B >= 500, and C >= 500. I placed this on func(x, y, z):
if A >= 1000 || B >= 500 || C >= 500
A = nan
B = nan
C = nan
error('Poor x, y, and z values. Re-iterating.')
end
Sadly, while the function would exit, fminsearch would still try to continue solving the problem. Is there a way to stop fminsearch from doing this, or to accomplish my requirement that fminsearch would stop when it calculates A >= 1000 || B >= 500 || C >= 500?
Thank you very much.

採用された回答

Walter Roberson
Walter Roberson 2021 年 9 月 13 日
Also you can specify MaxFunEvals and MaxIter
  9 件のコメント
Walter Roberson
Walter Roberson 2021 年 9 月 13 日
y = 200;
options = optimset('OutputFcn', @(x,optimValues,state)output_opt(x,optimValues,state,y);
[x, Z] = fminsearch(@(x)func(x, y),[1000, 1000, 1000], options)
Walter Roberson
Walter Roberson 2021 年 9 月 13 日
[~, A, B, C] = func(x, y)
That requires recalculating everything that was calculated in func(). Using memoize() would avoid that. memoize() acts as a cache.
if stop
end
That is not needed.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOptimization についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by