Stopping fminsearch immediately?

12 visualizaciones (últimos 30 días)
Allan Paolo
Allan Paolo el 13 de Sept. de 2021
Comentada: Walter Roberson el 13 de Sept. de 2021
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 13 de Sept. de 2021
Also you can specify MaxFunEvals and MaxIter
  9 comentarios
Walter Roberson
Walter Roberson el 13 de Sept. de 2021
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 el 13 de Sept. de 2021
[~, 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Optimization en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by