Newton method to optimize function, error

2 visualizzazioni (ultimi 30 giorni)
Hey guys,
im trying to use the newton method for optimizing my following function. I also used the Grid-search method, this worked totaly fine.
Now here is my try with the Newton method:
Imax=100; % Anzahl an maximalen Iterationen
tol=1;
i=1; % Zähler der Schleife
f=[diff(logL,b);diff(logL,y);diff(logL,A);diff(logL,B)]; % Partielle Ableitungen von logL
J=[diff(f,b) diff(f,y) diff(f,A) diff(f,B)]; % Aufstellen der Jacobi-Matrix
X=zeros(Imax,length(J)); % Matrix erstellen
X(1,:)= [27 3 0.04 0.3]; % Startwerte für 1.Iteration
while tol>=1e-9 % Toleranz
% Einsetzen der Werte für Startwertvariablen in Gleichung
fvar=subs(f,{'b' 'y' 'A' 'B'},{X(i,1) X(i,2) X(i,3) X(i,4)});
f_var=subs(J,{'b' 'y' 'A' 'B'},{X(i,1) X(i,2) X(i,3) X(i,4)});
% Evaluieren für Werte für Startwertvariablen
fvalue=eval(fvar);
f_value=eval(f_var);
if max(max(isnan(f_value))) == 1
break
end
% Neuer X Lösungsvektor
*| |*X(i+1,:)=([X(i,1) X(i,2) X(i,3) X(i,4)]'-f_value\fvalue)';*||*
% Abweichung zwischen neuen und alten Werten
tol=abs([X(i,1) X(i,2) X(i,3) X(i,4)] - [X(i+1,1) X(i+1,2) X(i+1,3) X(i+1,4)]);
if i>Imax % Abbruchkriterium
break
end
i=i+1;
end
fprintf('Endergebnis : '); % Endergebnis
[X(i,1) X(i,2) X(i,3) X(i,4)]
Im getting the error message:
> In zwei_parametrig_ohneAB_NEWTON_VERFAHREN (line 54)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.698726e-31.
> In zwei_parametrig_ohneAB_NEWTON_VERFAHREN (line 54)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 7.517962e-30.
> In zwei_parametrig_ohneAB_NEWTON_VERFAHREN (line 54)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.202871e-28.
> In zwei_parametrig_ohneAB_NEWTON_VERFAHREN (line 54)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.924598e-27.
> In zwei_parametrig_ohneAB_NEWTON_VERFAHREN (line 54)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.079253e-26.
> In zwei_parametrig_ohneAB_NEWTON_VERFAHREN (line 54)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.926967e-25.
And after that, MATLAB gives me "wrong" solutions:
-0.0000 -102.4938 108.4393 -217.2624
By googling the error message i know, that there must be something wrong with my matrix i have marked in the code below. Where is the problem?
Your sincerly, Ronald Singer
  1 Commento
Jan
Jan il 3 Ago 2017
Note: "any(isnan(f_value(:)))" is nicer than "max(max(isnan(f_value))) == 1".

Accedi per commentare.

Risposta accettata

Matt J
Matt J il 3 Ago 2017
Modificato: Matt J il 3 Ago 2017
It would help to know what logL looks like.
The message means that your Hessian matrices f_value are close to singular and therefore difficult to invert. You should examine them when the warning is triggered,
>> dbstop if warning
Possibly, you have landed in a region where logL is approximately flat everywhere making the Hessian approximately equal to zero(4). I also notice that you are not doing any line search steps. For non-quadratic function minimization, line searches are needed to assure convergence of Newton's method.
  10 Commenti
Ronald Singer
Ronald Singer il 3 Ago 2017
Is it possible to tell Matlab, in which Range of each parameter it should search? I tried it with assume, but it won't listen to me :P
Matt J
Matt J il 3 Ago 2017
Modificato: Matt J il 3 Ago 2017
Not with regular Newton's method. You can do it with fmincon() and other Optimization Toolbox solvers.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Matrix Computations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by