Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
Show older comments
I 'll be working on the nonlinear program with fmincon as follows:
>> load('JIRIOT_base.mat')
>> options = optimoptions('fmincon',
'Display','iter','Algorithm','interior-point');
>> [x,fval,exitflag,output,lambda] =
fmincon(@(x)mindistance(x,xo),xo,A,b,Aeq,beq,lb,[],[],options)
Then, error messages occurred as follows:
error: barrier (line 22)
Caused by:
Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
error:fmincon (line 905)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = barrier(funfcn,X,A,B,Aeq,Beq, l,u,confcn,options.HessFcn, ...
my objective function code is as follows:
>>function y = mindistance(x,xo) % objective function
>>y = sum(abs(xo(1:14386,1)).*(x(1:14386,1)./xo(1:14386,1)).*(log(x(1:14386,1)./xo(1:14386,1))-1)+1);
I guess there are many zeros in 'JIRIOT_base.mat'file. I attached the matfile, so please tell me how to solve my program.
Accepted Answer
More Answers (1)
Walter Roberson
on 20 Jan 2014
At the MATLAB command prompt, command
dbstop if caught error
and run your program. It should stop in your mindistance function and tell you what error it encountered there.
If you have any 0's in your x0 then the division by 0 in the log() term is going to give NaN there, and log(NaN) would be NaN. That would be multiplied by something to the left, giving NaN at that position. Then, sum() of a term that includes NaN is going to give NaN, so if there is even one 0 in your x0, your entire right hand side is going to give NaN. One would presume that that is not what you would want, but we cannot guess what result you would like if there is a 0 in your x0.
Question: your code fragment
abs(xo(1:14386,1)).*(x(1:14386,1)./xo(1:14386,1))
the xo in numerator and denominator are going to cancel out except for their sign (because of the abs()) so would that not be
sign(x0(1:14386,1)) .* x(1:14386,1)
except that the sign() version is better behaved at 0 ?
8 Comments
Michiya
on 20 Jan 2014
Michiya
on 20 Jan 2014
Walter Roberson
on 20 Jan 2014
That bit about LargeScale is probably spurious, something in the options processing that you should not have to care about. You can construct default options using http://www.mathworks.com/help/optim/ug/optimoptions.html and that might get further. Or when you get to that breakpoint, you can use
dbcont
to go on to the next. Keep going until you hit something about your function (e.g. index out of range)
Michiya
on 20 Jan 2014
Walter Roberson
on 20 Jan 2014
To avoid confusion at the moment, command
dbclear
Now put a breakpoint in at the "y =" line in mindistance and run the program. When it stops, copy the right hand side of the line and paste it to the command window, and see what it executes to. If it gives NaN like I suspect, then show us the output of
find(x0 == 0, 5, 'first')
Michiya
on 20 Jan 2014
Walter Roberson
on 20 Jan 2014
The difficulty is 0's in x0. What would you like to have happen with them?
If you would like to remove the 0 entries of x0 and the corresponding entries of x (to avoid length problems), then logically it becomes the same as using a shorter x0 and shorter x of the same length -- no point in varying values that are going to be ignored. So...
After the load,
x0 = nonzeros(x0);
and change your function to
y = sum(sign(xo) .* x .* (log(x ./ xo)-1)+1);
Michiya
on 20 Jan 2014
Categories
Find more on Variables in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!