MATLAB Answers

How can I require an optimization function to only consider a step successful if it decreases the cost function by a user-defined amount?

2 views (last 30 days)
F Yung
F Yung on 2 Oct 2020
Answered: Alan Weiss on 5 Oct 2020
I am running a patternsearch optimization routine in Matlab 2020b with a user-defined cost function. This routine is using a search method in addition to polling and I've set it to an iterative display so I can see the function value at each iteration. My frustration is that sometimes the search method identifies a node that only decreases the cost function by .1-1% and considers this a "successful search". While technically true, I would like to define a number MinDecrease such that the routine considers any step under that value a failure. For example, I would like to input a MinDecrease of 10 and even if the optimization finds a node that reduces the cost function by 9.9, it considers it a failure and switches to polling new points.
I understand that this may be embedded somehow in an output function but I'm not entirely sure how to incorporate it. Any help or guidance is appreciated.

Answers (1)

Alan Weiss
Alan Weiss on 5 Oct 2020
I think that you can accomplish what you want by using a custom search function. The syntax of a search function is
function [successSearch,xBest,fBest,funccount] = ...
searchfcntemplate(fun,x,A,b,Aeq,beq,lb,ub, ...
Here, the successSearch output is entirely under your control, and you can set it to false if the search did not satisfy whatever criterion you like, such as an insufficient decrease in fBest compared to optimValues.fval. In other words, take whatever search method you currently use, save its code in a file with a new name, modify the code as you like, and set patternsearch options to call the new search method.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

Community Treasure Hunt

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

Start Hunting!

Translated by