0

次のエラーが発生しています:

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

ステップ サイズの許容誤差は既定値 (1e-6) です。問題は、私が X で巨大な関数を扱っていることです (X = 1e7 のステップ)。ご想像のとおり、lsqcurvefit はまったく収束しません。

より簡単に収束するようにステップを変更するにはどうすればよいですか?

ローレンツィエンの作成は次のとおりです。

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)]);

lorentzfit3 には、Guess が正しいかどうかを確認する一連の if があります。しかし、私はその部分をスキップします。Guess は、どこから探し始めるかのアイデアを提供します。

[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

You can rewrite your function so it takes a more reasonably scaled argument:

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

Where myBigFun is your original function - but now myfun has an x that is scaled over a smaller range of steps.

The same is a good idea when you look at the values a function returns; sometimes optimization cannot see changes of the order you are interested in, so again, scaling the output of your function to a "reasonable range" helps ensure "things behave".

Another thing that often makes sense, especially when your optimum is "somewhere around a very big number", is re-centering your function: rather than exploring from 1000000 to 1000001, you center your function so you are searching for a value between -0.5 and 0.5

Just some thoughts that should help you on your way...

于 2013-03-18T14:27:10.853 に答える