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

7 views (last 30 days)
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
Sean de Wolski
Sean de Wolski on 24 May 2013
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

Alan Weiss
Alan Weiss on 24 May 2013
Edited: Alan Weiss on 24 May 2013
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
Jamal Ahmad
Jamal Ahmad on 24 May 2013
Edited: Matt J on 24 May 2013
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)

Matt J
Matt J on 24 May 2013
Edited: Matt J on 24 May 2013
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
Jamal Ahmad
Jamal Ahmad on 26 May 2013
Edited: Matt J on 27 May 2013
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
Matt J
Matt J on 27 May 2013
Edited: Matt J on 27 May 2013
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.

Categories

Find more on Audio Processing Algorithm Design in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!