0

I'm having the following error :

lsqcurvefit stopped because the size of the current step is less than
the default value of the step size tolerance.

The step size tolerance is default (1e-6). The problem is I'm working with huge functions in X (a step in X = 1e7). The lsqcurvefit does not converge at all, as you could guess.

How can I modify the step so it might converge more easily?

Here's the creation of the Lorentzien:

Gamma=[4e6 4e6 4e6];
C=1;
m=0;
Amplitude=[1.5 5];
Width=[0.15 0.25];
Offset=[1 2];
GuessC=Offset;

Aub = 2e7;
Alb = 5e6;
NUub = FreqR*0.999;
NUlb = FreqR*0.800;


for i=1:Nombre
    Ampl(i,1) = Alb + (Aub-Alb).*rand;
    Ampl(i,2) = Alb + (Aub-Alb).*rand;
    Ampl(i,3) = Alb + (Aub-Alb).*rand;
    Pic1 = RoundTo(NUlb + (NUub-NUlb).*rand,-6);
    Pic2 = RoundTo(NUlb + (NUub-NUlb).*rand,-6);
    Pic3 = RoundTo(NUlb + (NUub-NUlb).*rand,-6);

    T0=[Ampl(i,1) Ampl(i,2) Ampl(i,3)];
    nurG(i,1) = min([Pic1 Pic2 Pic3]);
    nurG(i,2) = median([Pic1 Pic2 Pic3]);
    nurG(i,3) = max([Pic1 Pic2 Pic3]);
    X1=nurG(i,1)-FreqR*0.025:FreqR*0.0003:FreqR;
    N=length(X1);
    Y1=zeros(1,N);

    for j=1:N   
       Y1(j)=(2*T0(1)/pi)*(Gamma(1)/(4*(X1(j)-nurG(i,1))^2+Gamma(1)^2))+(2*T0(2)/pi)*(Gamma(2)/(4*(X1(j)-nurG(i,2))^2+Gamma(2)^2))+(2*T0(3)/pi)*(Gamma(3)/(4*(X1(j)-nurG(i,3))^2+Gamma(3)^2))+C+m*randn();
    end

XP1 = X1/(FreqR*0.009);

Frequency=[nurG(i,1)/(FreqR*0.009) nurG(i,3)/(FreqR*0.009)];
GuessP11=(Width./(2*pi)).*(Amplitude-Offset);
GuessP21=Frequency;
GuessP31=Width.^2/4;
GuessP12=(Width./(2*pi)).*(Amplitude-Offset);
GuessP22=Frequency;
GuessP32=Width.^2/4;
GuessP13=(Width./(2*pi)).*(Amplitude-Offset);
GuessP23=Frequency;
GuessP33=Width.^2/4;

[yprime params resnorm residual]=lorentzfit3(XP1,Y1,[],[GuessP11(1) GuessP21(1) GuessP31(1) GuessP12(1) GuessP22(1) GuessP32(1) GuessP13(1) GuessP23(1) GuessP33(1) GuessC(1); GuessP11(2) GuessP21(2) GuessP31(2) GuessP12(2) GuessP22(2) GuessP32(2) GuessP13(2) GuessP23(2) GuessP33(2) GuessC(2)]);

In lorentzfit3, there is a series of if to see if the Guess are right. But I'll skip that part. The Guess gives an idea where to start looking.

[params resnorm residual] = lsqcurvefit(@lfun3c,p0,x,y,lb,ub,optimset('MaxFunEvals',200000,'MaxIter',10000,'TolFun',1e-18));
yprime = lfun3c(params,x);

end % MAIN

function F = lfun3c(p,x)
F = p(1)./((x-p(2)).^2+p(3)) + p(4)./((x-p(5)).^2+p(6)) + p(7)./((x-p(8)).^2+p(9)) + p(10);
end % LFUN3C
4

1 回答 1

1

您可以重写您的函数,以便它采用更合理的缩放参数:

function f = myfun(x)
f = myBigFun(1e7 * x);

myBigFun 是您的原始函数 - 但现在 myfun 有一个 x 可以在更小的步骤范围内缩放。

当您查看函数返回的值时,这也是一个好主意。有时优化无法看到您感兴趣的顺序的变化,因此再次将函数的输出缩放到“合理范围”有助于确保“事物正常运行”。

另一件通常有意义的事情,特别是当您的最佳值是“在一个非常大的数字附近”时,是重新定位您的函数:不是从 1000000 探索到 1000001,而是将您的函数居中,因此您正在搜索 -0.5 之间的值和 0.5

只是一些可以帮助你的想法......

于 2013-03-18T14:27:10.853 回答