How do I address "Error using barrier (line 31) Gradient at initial point contains Inf, NaN, or complex values. Fmincon cannot continue."
이전 댓글 표시
I have created an output function that I am using with fmincon that provides a gradient as an output. When optimizing, I keep getting the following error:
----------------------------------------------
Error using barrier (line 31)
Gradient at initial point contains Inf, NaN, or complex values. Fmincon cannot continue.
Error in fmincon (line 799)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
Error in loop_gradtest>(parfor body) (line 13)
wts_out(:,i) = fmincon(@(x)utility_gradtest(x,score_param1,
score_param2,rets),x,[],[],[mean(returns_grid_parallel)*12;ones(1,size(returns_grid_parallel,2))],[.05;1],double(limits_min(:,2)),double(limits_max(:,2)),[],fmin_options);
Error in loop_gradtest (line 9)
parfor i=1:10000;
------------------------------------------------------------
The function gradtest is used to all another function, utility_gradtest that is used to calculate maximum (min negative) utility given a vector of weights. In this function, using finite differencing, I calculate a gradient that is then supplied as part of the output for utility_gradtest.
I've used the following input in setting my options:
fmin_options = optimset('Algorithm','interior-point','GradObj','on','MaxFunEvals',10000,'MaxIter',500,'TolCon',10e-16,'TolX',10e-16,'Display','off','UseParallel',true);
Do I need to incorporate error handling capability to account for when the gradient contains an undefined point?
댓글 수: 6
Nick Hobbs
2015년 8월 12일
편집: Nick Hobbs
2015년 8월 12일
What is your gradient function and initial point? From the error message, it is likely the case that the gradient is returning a value that fmincon cannot work with. If you can determine the value the gradient is producing for fmincon, it may be possible to handle the issue by fixing the gradient before it is returned in the function.
Walter Roberson
2015년 8월 13일
We will probably need to see utility_gradtest() and anything it calls, and knowing something about the initial x and the other variables being passed into utility_gradtest would help.
J. Womack
2015년 8월 14일
Walter Roberson
2015년 8월 14일
At the command line command
dbstop if naninf
and run your program. If it stops in the debugger then you encountered a nan or inf and you will be able to explore the values in the debugger to see what is happening. If it does not stop in the debugger but gives you the barrier problem anyhow then you encountered a complex value and you can start debugging around that.
I would point out as a matter of efficiency that your code calculates some subexpressions multiple times. You should calculate them and store them in variables and use them as needed. In particular I notice mean(returns_grid_parallel).*12)'.*x) and cov(returns_grid_parallel) being repeated
My pure speculation is that you are ending up with a 0 / 0 situation.
J. Womack
2015년 8월 14일
Walter Roberson
2015년 8월 15일
Did you have a 0/0 or was it an inf*0 ?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!