Search code examples
matlabmathematical-optimization

Issues with fminsearch in matlab


I am having some issues with fminsearch of matlab. I have defined the TolX and TolFun as following

options = optimset('TolFun',1e-8, 'TolX', 1e-8)

Then I tried to estimate the parameters of my functions using

[estimates val] = fminsearch(model, start_point,options)

However, the val is around 3.3032e-04. Even though I specified the TolFun to be 1e-8, it still terminates before that with value around 3.3032e-04. Actually, the desired value of the parameter is obtained at something around 1.268e-04. So I tried to set the TolFun. Why is it not working, it should have converged to the least value of the function isn't it?


Solution

  • There are other reasons for termination of the search, for example, max number of function evaluations, max number of iterations, etc. fminsearch provides additional output arguments that give you information about the reason for termination. You especially want the full OUTPUT argument, which provides number of iterations, termination message, etc.

    [X,FVAL,EXITFLAG,OUTPUT] = fminsearch(...) returns a structure
    OUTPUT with the number of iterations taken in OUTPUT.iterations, the
    number of function evaluations in OUTPUT.funcCount, the algorithm name 
    in OUTPUT.algorithm, and the exit message in OUTPUT.message.
    

    Another possibility is that you've gotten stuck in local minimum. There's not much to be done for that problem, except to choose a different start point, or a different optimizer.