필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
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
Sean de Wolski
Sean de Wolski 2013년 5월 24일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Alan Weiss
Alan Weiss 2013년 5월 24일
편집: Alan Weiss 2013년 5월 24일
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
Jamal Ahmad
Jamal Ahmad 2013년 5월 24일
편집: Matt J 2013년 5월 24일
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)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2013년 5월 24일
편집: Matt J 2013년 5월 24일
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
Jamal Ahmad
Jamal Ahmad 2013년 5월 26일
편집: Matt J 2013년 5월 27일
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 2013년 5월 27일
편집: Matt J 2013년 5월 27일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Audio Processing Algorithm Design에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by