what is this mean: Gradient must be provided for trust-region algorithm?

Hi,
I have matlab code, when I run it I receive this message:
Warning: Gradient must be provided for trust-region algorithm; using line-search algorithm instead. > In fminunc at 367 In false_alarm_detection_2 at 14
Local minimum found.
Optimization completed because the size of the gradient is less than the selected value of the function tolerance.
what is that mean? and how can be solved?
Thanks

1 Comment

It means the default algorithm isn't suitable for the way you've called fminunc. You can just ignore the warning, it picked a different algorithm instead.

Sign in to comment.

 Accepted Answer

fmincon options describes the restrictions for the trust-region-reflective algorithm. Including Derivatives describes how you include the derivative in the objective function definition.
To avoid the warning without including a derivative, set the Algorithm option to 'interior-point' or some other algorithm:
opts = optimset('Algorithm','interior-point');
x = fmincon(objfn,x0,[],[],[],[],lb,ub,[],opts);
Take a look at the documentation examples for more information on setting gradients and options: <http://www.mathworks.com/help/optim/constrained-optimization.html>
Alan Weiss
MATLAB mathematical toolbox documentation

1 Comment

Thank you very much for the answer.
this is the code that I have: can you please tell me how I can solve it? Thanks
clc; clear all; close all;
u = 5;
snr = 20;
pf = [10^-4 5*10^-4 10^-3 5*10^-3 10^-2 5*10^-2 10^-1 5*10^-1 10^0];
for i = 1:length(pf)
% pf(i) = gamma(u,sigma/2) / gamma(u)
% gamma(u,sigma/2) = pf(i) * gamma(u)
vall(i) = pf(i) * gamma(u);
options = optimset('tolfun',10^-10,'tolx',10^-12);
xv = fminunc(@(x)(gammainc(5,x)-(vall(i))).^2,4,options);
sig(i) = xv/2;
g=0;
h=0;
for p=0:(u-2)
gg = (1/factorial(p)) * (sig(i)./2).^p;
g = g + gg;
hh = (1/factorial(p)) * ((sig(i)*snr)/(2*(1+snr)))^p;
h = h + hh;
end
pd(i) = exp(-(sig(i)/2))*g+((1+snr)/snr)^(u-1)*(exp(-(sig(i)/(2+(1+snr))))-exp(-(sig(i)/2))*h);
pm(i) = 1 - pd(i);
end
loglog(pf,pm)

Sign in to comment.

More Answers (1)

FMINUNC seems like overkill for a 1D root finding problem. Why not just use FZERO?
xv = fzero(@(x) gammainc(5,x)- vall(i) ,4);

6 Comments

@Matt, I suggested FMINUNC in Jamal's other thread because fzero can overstep and pass a negative value into gammainc. This throws an error.
OK, but then, why not use FMINBND? Or, if you don't know an upper bound, you could do something like this
xv = fzero(@(z) gammainc(5,z.^2)- vall(i) , 2).^2;
gammainc(5,x) is a monotone decreasing function with value 1 at x=0 and value 0 at x=Inf. Jamal wants to find a value of x so that gammainc(5,x) = gamma(5)*10^0 = 24. This is impossible. It is also not possible for gamma(5)*5*10^-1 or gamma(5)*10^-1 or gamma(5)*5*10^-2.
For values y such that 0 < y < 1, it is not hard to find a value x so that gammainc(5,x) = y:
x = fzero(@(x)gammainc(5,x)-y,[0,100]);
Why? Because
gammainc(5,100) = 5.9919e-91
This is close enough to 0 for all practical purposes, and fzero will not try to step outside the initial interval [0,100].
Alan Weiss
MATLAB mathematical toolbox documentation
Many thanks for all reputable responses.
so, is there any way to find the values of sig(i) when the value of pf is between (5*10^-2 to 10^0)? according to below matlab code I get NaN, and the follwoing message appears:
Exiting fzero: aborting search for an interval containing a sign change because no sign change is detected during search. Function may not have a root.
for the values of pf between (10^-4 to 10^-2), there are solutions which are (25.661 22.297 20.691 16.333 13.965).
clc; clear all; close all;
u = 5;
pf = [10^-4 5*10^-4 10^-3 5*10^-3 10^-2 5*10^-2 10^-1 5*10^-1 10^0];
for i = 1:length(pf)
% pf(i) = gamma(u,sigma/2) / gamma(u)
% gamma(u,sigma/2) = pf(i) * gamma(u)
% gamma(5) = 24
vall(i) = pf(i) * gamma(u);
options = optimset('tolfun',10^-10,'tolx',10^-12);
xv = fzero(@(z) gammainc(5,z.^2)- vall(i) , 2).^2;
sig(i) = xv*2;
end
Thanks again
Jamal
12.830 gammainc(5,12.83) = 0.0024
11.148 gammainc(5,11.148) = 0.012
10.345 gammainc(5,10.345) = 0.024
8.166 gammainc(5,8.166) = 0.12
6.982 gammainc(5,6.982) = 0.240
I believe there must be a solution since;
K>> gammainc(5,5)
ans = 0.5595
K>> gammainc(5,4)
ans = 0.7350
K>> gammainc(5,3)
ans = 0.8753
K>> gammainc(5,2)
ans = 0.9596
K>> gammainc(5,1)
ans = 0.9933
K>> gammainc(5,0)
ans = 1
so, after gammainc(5,6.982) the result will be between 0.24 and 1
so, after gammainc(5,6.982) the result will be between 0.24 and 1
Yes, but your target values of gammainc are not between 0.24 and 1. Here is the stream of vall(i) that your code produces
vall =
0.0024 0.0120 0.0240 0.1200 0.2400 1.2000 2.4000 12.0000 24.0000
As you can see, they exceed 1 for i>=6. As Alan said, it is not possible for gammainc(5,x) to reach a value greater than 1.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!