Is there any other alternative fuction that I can use instead of fminunc?.

Dear all,
I am using the function fminunc as I want to find the mode and the hessian matrix of a function. I use Matlab 2009 but I get an error related to this function
??? Error using ==> roots at 28
Input to ROOTS must not contain NaN or
Inf. Error in ==>
lineSearch>globalMinimizerOfPolyInInterval
at 304
stationaryPoint = roots([3*coeff(1)
2*coeff(2) coeff(3)]); Error in ==>
lineSearch>pickAlphaWithinInterval at 279
z =
globalMinimizerOfPolyInInterval(zlb,zub,coeff); Error in ==> lineSearch>sectioningPhase at
193
alpha =
pickAlphaWithinInterval(brcktEndpntA,brcktEndpntB,a,b,f_a,fPrime_a,f_b,fPrime_b); Error in ==> lineSearch at 55
[alpha,f_alpha,grad,exitflag,funcCount]
= sectioningPhase(funfcn, ... Error in ==> fminusub at 208
[alpha,f,grad,exitflagLnSrch,funcCountLnSrch]
= ... Error in ==> fminunc at 376
[x,FVAL,GRAD,HESSIAN,EXITFLAG,OUTPUT] =
fminusub(funfcn,x, ... Error in ==> testxa2 at 252
[xxx,fval,exitflag,output,gradient,H]=fminunc('modeA,x00,options,...
Is there any other alternative fuction that I can use instead of fminunc?. The function produces no error in Matlab2012 but only in matlab 2009
thank you

Antworten (3)

Hi Salva,
You could use fminsearch or fminbnd, two derivative-free optimizers. However, given that the error is thrown when the input to roots() is invalid, it would probably be better to catch that error before entering roots. You could put a check in your globalMinimizerOfPolyInInterval() function prior to calling roots() that checks that coeff(1:3) are all not NaN or Inf. Something like:
if all(isfinite(coeffs(1:3)),
stationaryPoint = roots([3*coeff(1) 2*coeff(2) coeff(3)]);
else
%do something to force the optimizer to reject this solution
end

2 Kommentare

thank you Matt. It seems that the
else
%do something to force the optimizer to reject this solution
is the most important of all.
Any suggestion for
%do something to force the optimizer to reject this solution?
thankss
Any comments are welcome
thanks

Melden Sie sich an, um zu kommentieren.

Walter Roberson
Walter Roberson am 23 Sep. 2012
If you use an options structure that turns on function value checking, then the minimization will stop at the point that inf or NaN is produced.

3 Kommentare

thanks walter. could you please be more specific ?
thanks
You appear to already be constructing options, so include 'FunValCheck', 'on' when constructing the options.
thank you walter. Actually, I am looking the opposite. I want the process to continue even when the point that is being produced is inf or NaN (as in matlab2012)
thanks

Melden Sie sich an, um zu kommentieren.

fmincon's Interior-Point algorithm can recover from inf and nan output.
doc fmincon

8 Kommentare

Thank you sean
When I used the "fminunc" function I constructed the following setup.
options=optimset('LargeScale','off','display','off','TolFun',0.0001,'TolX',0.0001,...
'GradObj','off', 'Hessian','off','DerivativeCheck','off');
[xxx,fval,exitflag,output,gradient,H]=fminunc('CES_mode7cutDCfree1sem',x00,options,...
ka, fff2,fff3,fff4,fff5,fff6, vsigt2);
where the output i am interested i is xxx which is the mode of the function and H which is the Hessian. ka, fff2,fff3,fff4,fff5,fff6 and vsigt2 are inputs that I obtain from previous steps
What kind of setup should i use for the "fmincon" function?
I tried something like
options = optimset('Algorithm','interior-point',...
'Hessian','user-supplied','HessFcn',@hessianfcn);
[xxx, H]=fmincon('CES_mode7cutDCfree1sem',x00,options,...
ka, fff2,fff3,fff4,fff5,fff6, vsigt2);
but I get the following error
??? Error using ==> fmincon at 232
FMINCON only accepts inputs of data type
double.
Error in ==> les3 at 309
[xxx,
H]=fmincon('CES_mode7cutDCfree1sem',x00,options,...
Any help is greately appreciated
What is the class() of the various inputs? Convert them to double before passing to fmincon
fmincon(@fun,double(x0),double(A),double(etc...)
Sabbas
Sabbas am 27 Sep. 2012
Bearbeitet: Sabbas am 27 Sep. 2012
HI Sean,
THe various inputs are already in double format. THe function that I want to maximize is 'CES_mode7cutDCfree1sem'. and the various inputs are ka, fff2,fff3,fff4,fff5,fff6 and vsigt2 all of which are in double format. I am trying to find where the mistake is but I can not
thank you
dbstop if error
Will stop when the error is thrown and you can traverse the stack to see what variables are what where.
thanks Sean. would it be possible to still use fminunc but avoid this error that occurs when I get extreme values
You could write a wrapper function to wrap around your objective function that would spit out large values relative to the inputs when a NaN or inf occurs. But this adds a discontinuity which these solvers aren't really designed to be able to handle.
The real question: Why don't you want to use fmincon's IP algorithm? It's super-awesome.
The reason is that I do not know how to set it up!
Well since you don't need constraints you can ignore all of those inputs, just put some lower and upper bounds on your variables and use it just like fminunc
fmincon(foo,x0,[],[],[],[],lb,ub,options);

Melden Sie sich an, um zu kommentieren.

Tags

Gefragt:

am 20 Sep. 2012

Community Treasure Hunt

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

Start Hunting!

Translated by