Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.

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

The purpose of the xo argument in fmincon(fun,xo,...) is that it, in Mathworks' words, "starts at xo and attempts to find a minimum x". In view of this it makes no sense to also include xo as an argument in the objective function, 'fun', itself as you have done here. It should be exclusively an estimate of where 'fmincon' should start in its iterations to a final minimum value and should not appear in the objection function.

1 Comment

I put mistaking for accepting this answer. I accept Water Robertson's answer. I'm sorry.

Sign in to comment.

More Answers (1)

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

Thanks for your answer, Walter. I corrected the code as follows:
sign(x0(1:14386,1)) .* x(1:14386,1)
But, other error messages occurred.
>>Breakpoints Caught error has hit optimget> optimgetfast of line 102. Error:
referring to field 'LargeScale' that does not exist.
102 value = options.(name);
So, could you teach me another suitable advice for solving above this program?
Michiya
I attached the mindistance.m file. This is my objectivefunction file.
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)
Walter,
Thanks for your comment and advice. When I get to the break point, I used
>>dbcont
to go on the next. And the another message replied.
Error: barrier (line 22) Objective function is undefined at initial point. 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, ...
I cannot understand with my current possibility how to solve it.
So, anyway, thank you very much for your kindful help.
Michiya
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')
Walter,
Thanks for your advice.
When it stops, I copy the right hand side of "y=" of the objective function, and
paste it to the command window, and put find(x0 == 0, 5, 'first')
on command window.
ans =
74
79
83
86
98
I guess the above answer is NaN of x0 in 'JIRIOT_base.mat'file. Is there a method for excluding NaN from x0 ?
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);
Thank you for your advice. Your answer is the best.

Sign in to comment.

Categories

Tags

Asked:

on 20 Jan 2014

Commented:

on 20 Jan 2014

Community Treasure Hunt

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

Start Hunting!