Académique Documents
Professionnel Documents
Culture Documents
Ingeniera Elctrica
Optimizacin (minimizacin)
de funciones sin condiciones
Jos Luis de la Fuente OConnor
jldelafuente@etsii.upm.es
Clase_minimi_sincond_11.pdf
1/76
ndice
El problema
Condiciones de mnimo
Mtodos de direccin de descenso
Mtodo del gradiente o de la mxima pendiente
Mtodo de Newton
Mtodo de los gradientes conjugados
Mtodos cuasi Newton
Mtodos de regin de confianza
2/76
El problema
Dar solucin a
minimizar f W Rn ! R
La funcin f se supone continua en algn conjunto abierto de
Rn, con derivadas parciales continuas hasta segundo orden en ese
abierto.
3/76
= Ejemplos
(x x )
2
ueminimizer,
x f
, see
La funcin
.x/Figure
D .x1.1.x /2 tiene un nico punto donde
alcanza el mnimo, x .
re
1.1: y = (x x )2 .
NTRODUCTION
ne minimizer.
2
x*
La
funcinf (x)
f .x/
2 cos.x
/ tiene
mnimos
en x =
The
function
=D
2 cos(x
x )x has
infinitely
manylocales
minimizers:
xD
x ,Cwhere
2a. p is an integer; see Figure 1.2.
2p
x +
y
4/76
(x) D
= 0.015(x
2 cos(x
x ) mnimo
has a unique
glo
The
La function
funcin ff .x/
0;015.x xx )/2tiene
un
nico
global
it also has several socalled local minimizers, ea
minimizer,
x . Besides
x y muchos
mnimosthat,
locales.
giving the minimal function value inside a certain region, see Figure 1.3.
y
x*
Condiciones de mnimo
Definicin Una funcin f W Rn ! R se dice convexa si cumple que
f .x C y/ f .x/ C f .y/
para todo
0.
193
x; y 2 Rn y todo ; 2 R, con C D 1, 0,
f
convex
6/76
x/:
f (y)
f (x) + f (x)T (y x)
(x, f (x))
7/76
x T r 2f .x/x 0;
Ejemplo: la funcin
convexa.
Convex functions
f (x, y)
0
2
2
1
0
y
0 2
8/76
rf .x / D 0:
Un punto x que cumple
estacionario de f .x/.
x
x
es un punto estacionario y
es un mnimo local.
r 2f .x / es definida positiva,
point that there exists one line through xs , with the property that if we follo
thedistintos
f -value along
this looks
like a local minimu
the
Sevariation
pueden of
dar
casos the
de line,
mnimos
locales.
whereas there exists another line through xs , indicating a local maximize
c) saddle point
a) minimum
b) maximum
2 wesee
Figure
With a 2-dimensional
1. El primero
es 1.5:
un mnimo
local y r fx.x
/ essurfaces
definida
z = f (x) near a stationary point.
positiva.
2. El segundo es un mximo local y
negativa.
r 2f .x / es definida
2
11/76
10
10
30
25
20
20
15
10
10
0
5
0
12/76
f .x kC1/ < f .x k / ;
mediante el clculo de una direccin de descenso en la que
moverse con este objetivo.
kC1
xx(k+1)
(k)
kpp
k
ppk(k)
(k)
xx
k
13/76
if (p no existe) or (t ol)
f ound WD true
else
WD amplitud de paso .x; p/
x WD x C p
end
k WD k C 1
end
Se diferencian unos de otros en el clculo de
p.
14/76
rf .x/T p < 0:
El descenso relativo de la funcin en p es
f .x/
f .x C p/
D
kpk
rf .x/T p
D
kpk
15/76
p
D
Line search methods
rf .x/
Iteration: xk+1 = xk + k pk , where k is the step length (how far to move along pk ), k > 0; pk
is the search direction.
3
2.5
1.5
xk
1
2
pk
1.5
0.5
0.5
1.5
2
16/76
'./ D f .x C p/:
Se puede hacerlo estrictamente o de forma inexacta, a un coste
en clculos menor. En cualquier caso, hay que garantizar con
algn indicador que
f .x C p/ < f .x/;
es decir que la funcin decrezca suficientemente.
17/76
Hay
que
evitar
pasos muy largos: en la funcin x , por ejemplo,
h las
isdirecciones
too
long,
p D . 1/kC1 y los pasos D 2 C 3=2
2
kC1
2.5
1.5
0.5
0
2
1.5
0.5
0.5
1.5
18/76
2.5
1.5
0.5
0
2
1.5
0.5
0.5
1.5
2
19/76
@f .x C p/
@f .x C p/
@f .x C p/
p1 C
p2 C : : : C
pn
@x1
@x2
@xn
rf .x C p/T p:
(x + tx)
f .x Cfp/
ements
T
(x) C
+ tf
(x).x/
x
f f.x/
rf
p
tD=00
0t0
f (x) + tf (x)T x
t
El9.1criterio
de Armijo
establece
cumplir
igure
Backtracking
line search.
The curveque
shows fdebe
, restricted
to the el
lineque
ver which we search. The lower dashed line shows the linear extrapolation
T
f , and the upper dashed
has aslope
a factor
of .x/
smaller.
f .x line
C p/
f .x/
C %rf
p; The
acktracking condition is that f lies below the upper dashed line, i.e., 0
t0donde
.
% 2 .0; 1/ es una constante a elegir. Garantiza que la
funcin decrece razonablemente.
21/76
El de Goldstein que
rf .x C p/T p rf .x/T p;
donde 2 .; 1/. Es decir que el decrecimiento cualitativo
previsible en el nuevo punto sea mayor que una fraccin dada del
existente en el actual.
El mtodo inexacto ms extendido para calcular la amplitud de
paso se conoce como backtracking .
Comienza con un paso completo, D 1, y lo va reduciendo
mediante un factor constante, , 2 .0; 1/, hasta que se
cumpla el criterio de Armijo.
Funciona slo si f .x C p/0D0 D rf .x/T p < 0 (direccin de
descenso).
22/76
f .x/.
pD
gD
rf .x/
if (p no existe) or (t ol)
f ound WD true
else
WD amplitud de paso .x; p/ con backtracking
x WD x C p
end
k WD k C 1
end
Tiene convergencia lineal.
23/76
Resolvamos
f .x/ D e x1C3x2
0;1
C e x1
3x2 0;1
Ce
x1 0;1
D 0:
function [x f] = Maxima_pendiente_unc(fun,x0)
% Maxima_pendiente_unc: Mtodo de la mxima pendiente
rho = 0.1; beta = 0.5;
f1=0; maxit = 100; x = x0;
% Parmetros y partida
for i=1:maxit
% Proceso iterativo
[f g] = fun(x);
if (abs(f-f1) < 1e-10), break, end
p = -g; alpha = 1;
for k=1:10
% Backtracking de amplitud de paso
xnew = x+alpha*p; fxnew = fun(xnew);
if fxnew < f + alpha*rho*g*p
break
else alpha = alpha*beta;
end
end
x = x + alpha*p; f1=f;
fprintf(%4.0f %13.8e %13.8e %13.8e %13.8e\n,i,x,f,alpha);
end
function [f g]= objfun_min1(x)
A = [1 3; 1 -3; -1 0]; b = -0.1*[1; 1; 1];
f = sum(exp(A*x+b)); if nargout<2, return, end
g = A*exp(A*x+b);
24/76
>> [x f]=Maxima_pendiente_unc(@objfun_min1,[-1;1])
1 -1.26517900e+000 -2.50497831e-001 9.16207023e+000 6.25000000e-002
2 -6.29000734e-001 6.51924176e-002 3.86828053e+000 2.50000000e-001
3 -4.50514899e-001 -7.72284882e-002 2.68052760e+000 2.50000000e-001
4 -4.21089848e-001 2.38719166e-002 2.60419641e+000 1.25000000e-001
5 -3.97610304e-001 -8.05335008e-003 2.56942254e+000 1.25000000e-001
6 -3.65030711e-001 1.39821003e-002 2.56295544e+000 2.50000000e-001
7 -3.59263955e-001 -5.78404615e-003 2.56080796e+000 1.25000000e-001
8 -3.55227870e-001 2.43800662e-003 2.55966300e+000 1.25000000e-001
9 -3.52463501e-001 -1.04150522e-003 2.55939647e+000 1.25000000e-001
10 -3.48696568e-001 1.93956544e-003 2.55931730e+000 2.50000000e-001
11 -3.48020112e-001 -8.46703041e-004 2.55929408e+000 1.25000000e-001
12 -3.47557873e-001 3.70439501e-004 2.55927350e+000 1.25000000e-001
13 -3.47243091e-001 -1.62316050e-004 2.55926873e+000 1.25000000e-001
14 -3.47028931e-001 7.11957301e-005 2.55926742e+000 1.25000000e-001
15 -3.46737604e-001 -1.33695923e-004 2.55926699e+000 2.50000000e-001
16 -3.46685147e-001 5.87394995e-005 2.55926683e+000 1.25000000e-001
17 -3.46649462e-001 -2.58117184e-005 2.55926673e+000 1.25000000e-001
18 -3.46625190e-001 1.13436901e-005 2.55926671e+000 1.25000000e-001
19 -3.46592176e-001 -2.13150939e-005 2.55926670e+000 2.50000000e-001
20 -3.46586231e-001 9.36927894e-006 2.55926670e+000 1.25000000e-001
21 -3.46582187e-001 -4.11844758e-006 2.55926670e+000 1.25000000e-001
22 -3.46579437e-001 1.81036718e-006 2.55926670e+000 1.25000000e-001
23 -3.46577566e-001 -7.95799575e-007 2.55926670e+000 1.25000000e-001
x =
-0.346577566436640
-0.000000795799575
f =
2.559266696682093
25/76
10
error
10
inexacta: backtracking
10
10
10
15
10
10
15
k
20
25
26/76
27/76
funcCount:
stepsize:
firstorderopt:
algorithm:
message:
9
1
1.8773e-007
medium-scale: Quasi-Newton line search
[1x85 char]
>>
28/76
Mtodo de Newton
Consideremos ahora el desarrollo en serie de Taylor de f .x/
hasta segundo orden:
1 T 2
3
f .x C p/ D f .x/ C rf .x/ p C p r f .x/ p C O kpk ;
2
T
6
6
6
6
6
2
D r f .x / D 6
6
6
6
4
@ f .x/
@ f .x/ @ f .x/
@2 x1 @x1 @x2
@x1 @xn 7
7
7
2
2
2
@ f .x/ @ f .x/
@ f .x/ 7
7
@x2 @x1 @2 x2
@x2 @xn 7
7
:::
:::
:::
:::
7
7
@2 f .x/ @2 f .x/
@2 f .x/ 5
@xn @x1 @xn @x2
@2 xn
la matriz Hessiana.
29/76
rf .x/ C r 2f .x/p D g C H p D 0
cuya solucin es la direccin de Newton hacia el ptimo.
Si la matriz H D r 2f .x/ es definida positiva x T H x > 0 para
cualquier x 0, la direccin de Newton es una direccin de
descenso pues
0 < pT H p D
pT g;
f .x/:
Hp D
if (p no existe) or (t ol)
f ound WD true
else
WD amplitud de paso .x; p/ con backtracking
x WD x C p
end
k WD k C 1
end
31/76
0;1
C e x1
>> [x f]=Newton_unc(@objfun_min2,[-1;1])
1 -5.23625188e-002 3.53998022e-001 9.16207023e+000
2 -1.05634526e-001 1.05820897e-001 3.73378771e+000
3 -3.18485379e-001 2.52139713e-002 2.71665315e+000
4 -3.45138214e-001 7.18724132e-004 2.56404324e+000
5 -3.46572427e-001 1.03191597e-006 2.55927231e+000
x =
-0.346572427027644
0.000001031915967
f =
2.559266696666079
>>
3x2 0;1
Ce
x1 0;1
1.00000000e+000
1.00000000e+000
1.00000000e+000
1.00000000e+000
1.00000000e+000
33/76
10
error
10
10
10
10
15
10
0.5
1.5
2.5
k
3.5
4.5
function [x f i] = Newton_mp(fun,x)
% Mtodo hbrido Newton-mxima pendiente
global h
rho = 0.1; beta = 0.5; % Parmetros de line search
maxit = 100; h=sqrt(eps);
for i=1:maxit
% Proceso iterativo
[f g H] = fun(x);
[R npd] = chol(H); % Cholesky comprueba si H es definida positiva
if ~npd
p = -R\(R\g);
% Direccin de Newton_mp
else
p = -g;
% Direccin de mxima pendiente
end
if abs(p*g)<1e-8, break, end
alpha = 1;
for k=1:10
% Backtracking de amplitud de paso
xnew = x+alpha*p;
fxnew = fun(xnew);
if fxnew < f+alpha*rho*g*p, break
else alpha=alpha*beta;
end
end
x = x + alpha*p;
fprintf(%4.0f %13.8e %13.8e %13.8e %13.8e %4.0f\n,i,x,f,alpha,npd);
end
36/76
7.81250e-003
1.00000e+000
2.50000e-001
1.00000e+000
5.00000e-001
1.00000e+000
5.00000e-001
1.00000e+000
5.00000e-001
1.00000e+000
1.00000e+000
1.00000e+000
1.00000e+000
1.00000e+000
1
0
0
0
0
0
0
0
0
0
0
0
0
0
37/76
1
f .x C p/ ' M.p/ f .x/ C pT c C pT Bp;
2
donde c 2 Rn y la matriz B 2 Rnn es simtrica.
Un modelo as puede ser el desarrollo en serie de Taylor hasta
segundas derivadas, o una aproximacin adecuada.
La idea es utilizar esos modelos para calcular direcciones de
descenso con amplitudes de paso D 1 en entornos de ese modelo
de confianza y modulables.
38/76
1
pNa mKn M.p/ C p T p;
p
2
donde es el parmetro de amortiguacin. El trmino
1
pT p D 12 kpk2 penaliza pasos largos.
2
El paso de regin de confianza, como
of mk m.p/
Contornos contours
del modelo
Paso
regin
Trustde
region
step de
confianza
contours of f de f .x/
Contornos
40/76
%D
f .x/ f .x C p/
;
M.0/ M.p/
end
Es importante que los factores 2 y 3 de esta estrategia no hagan
oscilar demasiado .
41/76
end
Otra estrategia para bastante usada es:
if % > 0
WD mKax 13 ; 1
else
WD 2
end
.2%
1/3
42/76
1
.p/ D mKn M.p/ C pT p:
p
2
La condicin necesaria de mnimo, r .p/ D 0, hace que la
direccin pNa sea la solucin de
0
.h/ D M 0.h/ C p D 0:
.B C I/ pNa D
c:
.H C I/ pNa D
g:
Si es muy grande,
pNa
1
g;
44/76
f .x/:
WD mKax 31 ; 1 .2% 1/3
x WD x C p
else
WD 2
end
end
k WD k C 1
end
45/76
function [x f k] = Newton_amortiguado(fun,x)
% Mtodo de Newton amortiguado con paso completo
k = 1; kmax = 500; eps1=1e-8; eps2=1e-12; n=length(x);
[f g H] = fun(x); ng = norm(g,inf); mu = 1; found = ng<=eps1;
while ~found
posdef = 0;
while ~posdef
[R p] = chol(H+mu*eye(n));
% Cholesky comprueba si H es definida positiva
if p, mu=2*mu; else posdef = 1; end
end
p = -R\(R\g); nh = norm(p);
% Clculo de paso
if nh <= eps2*(eps2+norm(x)), found = 2;
% ptimo
else
% Modificar regin de confianza
xnew = x + p; dL = -p*g-p*(H*p)/2;
[fn gn Hn] = fun(xnew); df = f-fn; r=df/dL;
if r>0
x = xnew; f = fn; g = gn; H = Hn;
ng = norm(g,inf);
mu = mu*max(1/3,1-(2*r-1)^3);
else
mu = mu*2;
end
k = k + 1;
if ng <= eps1, found = 1; elseif k > kmax, found = 3; end
fprintf(%4.0f %13.8e %13.8e %13.8e %13.8e\n,k,x,f,mu);
end
end
46/76
f .x/ D 0;5x12.x12=6 C 1/
x2 arctan.x2/
0;5 ln.x22 C 1/
>> [x f k] =Newton_amortiguado(@fun5_2,[2;2])
2 1.22222222e+000 1.07737607e+000 1.43392805e+000
3 5.74640142e-001 4.41028668e-002 1.75164488e-001
4 1.32066691e-001 4.36656594e-003 8.75568971e-003
5 6.09495146e-003 1.55898129e-004 1.85864837e-005
6 7.44750479e-005 1.90119424e-006 2.77507370e-009
7 3.05225879e-007 7.79177968e-009 4.66421303e-014
8 4.18117642e-010 1.06736708e-011 8.75251085e-020
x =
1.0e-009 *
0.418117641894218
0.010673670797581
f =
8.752510847988606e-020
k =
8
3.33333333e-001
1.11111111e-001
3.70370370e-002
1.23456790e-002
4.11522634e-003
1.37174211e-003
4.57247371e-004
47/76
p es la solucin de
1
prc mKn M.p/ f .x/ C g T p C pT Bp
kpk
2
si y slo si p es factible y existe un escalar 0 tal que se cumplen
las siguientes condiciones
.B C I/p D g;
. kpk/ D 0 y
.B C I/ es semidefinida positiva.
B es la matriz Hessiana, r 2f .x/, o una aproximacin.
La segunda condicin de complementariedad establece que o
D 0 o kpk D .
48/76
2
3
Contornos
contours
of m
p*1
p*2
del modelo
M.p/
p*3
p D
Bp
gD
rM.p/:
g, acotada a
wherede Cauchy
Punto
if gkT Bk gk 0;
k que minimiza
(4.12)
Es la solucin
el modelo
lineal de Mk .p/ en
una
min gk 3 /(k gkT Bk gk ), 1
otherwise.
iteracin k. Concretamente
k
Figure 4.3 illustrates the Cauchy
in which Bk is positive
gk;
pck point
D for a subproblem
denite. In this example, pk lies strictly inside thekg
trust
k kregion.
C
k D
mKn kg k k =
k g Tk B k g k
;1
si
k
k
T
g k Bg k
> 0:
contours of del
mk
Contornos
modelo
Mk .p/
ppkCck
gk
gk
51/76
DogLeg
Hemos visto que si la matriz B del modelo M.p/ es definida
positiva, su mnimo es pB D B 1g. Es decir p./ D p B , cuando
kpB k.
Si es grande con respecto a pB , la condicin kpk hace que
el trmino cuadrtico del modelo M.p/ tenga poco efecto en su
solucin. En este caso, se puede aproximar
p ./
g
:
kgk
p./
B
p
(paso
completo)
pB ( full
step )
( unconstrained
along g)g
pU : pmnimo
en la min
direccin
U
dogleg path
direccin DogLeg
Figure 4.4
(4.14)
53/76
p U C .
1/ pB
2
p U
D 2 :
e_1
e_2\n],xstring);
xc = x0; [fc gc Hc] = fun(xc);
disp([ 0, sprintf( %12.4e,[xc,fc]),sprintf( %10.2e,Delta)]);
for k=1:Kmax
% Modelo Newton: -(gc*pN + 0.5*pN*Hc*pN);
pN
= - Hc\gc;
% Direccin de Newton
pNlen = (pN*pN)^0.5; gHg = gc*Hc*gc;
if pNlen <= Delta
% Punto Newton dentro regin
xt = xc + pN;
else
% Fuera: encontrar el mnimo mediante mxima
%
pendiente del Model Newton
pSD
= -(gc*gc)/gHg*gc;
pSDlen = (pSD*pSD)^0.5;
if pSDlen>=Delta
% Newton y mp fuera regin: usa punto Cauchy
xt = xc - Delta*gc/(gc*gc)^0.5;
else
% mp dentro regin y Newton fuera: usa DogLeg
%
en lmite regin de linea uniendolos
pN_pSD = pN-pSD;
a = pN_pSD*pN_pSD; b = 2*pN_pSD*pSD; c = pSD*pSD - Delta^2;
t = (-b+(b^2-4*a*c)^0.5)/2/a;
xt = xc + pSD + t*pN_pSD;
end
end
[fn gn Hn] = fun(xt);
% Nuevo punto obtenido en Reg. Con.
dx = xt - xc; df = fn - fc;
redfun = -df;
% Reduccin obtenida en funcin
repred = -gc*dx-0.5*dx*Hc*dx; % Reduccin predicha modelo Newton
rho
= redfun/repred;
% Ganancia
e1 = max(abs(pN)./max([abs(xt);eps2*ones(size(xt))]));
e2 = max((abs(gn).*abs(xt))/ max([abs(fn),eps2]));
if e1<eps1 || e2<eps2, break, end
if rho>0
% Buena ganancia; aceptar punto actual
xn=xt; xc=xt; fc=fn; gc=gn; Hc=Hn;
if rho<0.25, Delta = 0.25*norm(dx); end
if rho>0.75 && norm(dx,2)>((1-eps)*Delta),
Delta = min([2*Delta;Dmax]);
end
disp([sprintf(%3d,k), sprintf( %12.4e,[xn,fn]),...
sprintf( %10.2e,Delta),sprintf( %6.4f,norm(dx)/Delta),...
sprintf( %7.3f,rho),sprintf( %8.1e,e1),...
sprintf( %8.1e,e2)]);
if e1<eps1 || e2<eps2, break, end
else
xn = xc;
% Reduccin de funcin mala; seguir igual
end
end
disp([ptimo: x =,sprintf( %22.16e,xc),.]);
disp([Funcin: f(x) =,sprintf( %22.16e,fc),.]);
56/76
f .x/ D 0;5x12.x12=6 C 1/
x2 arctan.x2/
0;5 ln.x22 C 1/
>> [x f]=Dogleg_UBC_yo(@fun5_2,[2;2]);
k
x_k(1)
x_k(2)
f(x_k)
Delta
|dx|/Del
0
2.0000e+000
2.0000e+000
4.7429e+000
5.00e-001
1
1.5135e+000
1.8846e+000
2.8658e+000
1.00e+000 0.5000
2
5.8687e-001
1.5086e+000
1.0754e+000
2.00e+000 0.5000
3 -4.1104e-001 -2.2464e-001
1.1188e-001
4.00e+000 0.5000
4 -3.9606e-002
7.4824e-003
8.1253e-004
4.00e+000 0.1095
5 -4.1354e-005 -2.7927e-007
8.5513e-010
4.00e+000 0.0101
6 -4.7149e-014
1.4505e-020
1.1115e-027
4.00e+000 0.0000
ptimo: x = -4.7148815071357958e-014 1.4505439221729893e-020.
Funcin: f(x) = 1.1115053813167661e-027.
ro
e_1
e_2
1.040
1.233
0.781
1.045
1.001
1.000
2.8e+000
2.6e+000
2.1e+000
1.0e+000
1.0e+000
1.0e+000
1.4e+000
1.4e+000
1.6e+000
1.9e+000
1.1e-001
1.5e-019
57/76
pD
rf .x/ C ppr
rf .x/T rf .x/
D
rf .xpr /T rf .xpr /
La de Polak y Ribire, posteriormente, en 1971:
rf .x/
T
rf .xpr / rf .x/
rf .xpr /T rf .xpr /
59/76
f .x/:
Dados La funcin
x WD x C p.
60/76
2 2
x1
f .x/ D 100 x2
0.5
15
0.4
4
0.3
15
x2
2
1
1
5
10
0.1
5
43
10
10
x1/2:
15
0.2
3 4
10
0.1
C .1
15
10
3
4
0.2
5
15
10
10
0.3
15
15
0.4
0.5
0.5
0.4
0.3
0.2
0.1
0
x
0.1
0.2
0.3
0.4
0.5
61/76
function [x f] = Grad_Conjugados_unc(fun,x,par)
% Mtodo de los gradientes conjugados para minimizar f(x)
rho = 0.01; beta = 0.1;
% Parmetros de line search
maxit = 1000;
[f g]= fun(x); ppr=-g; gpr=g; pbeta=0;
% Comienzo con mx. pendiente
for i=1:maxit
% Proceso iterativo
if i>1
[f g] = fun(x);
if
par==1, pbeta=(g*g)/(gpr*gpr);
% Fletcher-Reeves
else
pbeta=((g-gpr)*g)/(gpr*gpr); % Polak-Rivire
end
end
p = -g+pbeta*ppr;
if (norm(g,inf) < 1e-6), break, end
% Condicin de mnimo
alpha = 1;
for k=1:10
% Backtracking amplitud de paso
xnew = x+alpha*p; fxnew = fun(xnew);
if fxnew <= f + alpha*rho*g*p
break
else alpha = alpha*beta;
end
end
x = x + alpha*p; ppr=p; gpr=g;
fprintf(%4.0f %13.8e %13.8e %13.8e %13.8e\n,i,x,f,alpha);
end
function [f g] = objfun_min3(x) % Rosenbrock
f = 100*(x(2)-x(1)^2)^2+(1-x(1))^2; if nargout<2, return, end
g = [-200*(x(2)-x(1)^2)*2*x(1)-2*(1-x(1));200*(x(2)-x(1)^2)];
62/76
ergence Properties
36
x2
2
x2
1
100
30
10
3
0.3
1
1.5
1.5 x
1
0.5
1.2
x1
Figure
Contours of Rosenbrocks
function. 1e5del listado, la convergencia es
Con
la 4.2:
tolerancia
y los parmetros
ctionla
hasde
one la
minimizer
x = [1, 1]> (marked by a + in the
figure) with
1e10
f
tabla.
||f||
= 0, and there is a valley with sloping bottom following the parabola
1e15
2
0
20
30
40
50
x1 . Most optimization algorithms will try to follow this valley.
Thus,10
Mtodo
Nmero
iteraciones
thePolakRibi`
2nd
derable amount of iteration steps is needed, if we take
x0 in4.3:
Figure
ere method with soft line search
nt.
applied
to
Rosenbrocks
function.
PolakRibire
103
iterates
xk .
we give the number of iteration steps and evaluations of fTop:
(x) and
f 0 (x)
FletcherReeves
514
pplying Algorithm 4.6 on this function. In all cases we use the starting
63/76
Probad
>> [x f] = Grad_Conjugados_unc(@objfun_min3,[-1.2;1],1)
1 -9.84400000e-001 1.08800000e+000 2.42000000e+001 1.00000000e-003
2 -1.01771362e+000 1.06810987e+000 5.35291158e+000 1.00000000e-003
513 1.00000141e+000 1.00000283e+000 2.00451765e-012 1.00000000e-004
x =
1.000001414780674
1.000002834445620
f =
2.003988012156511e-012
>> [x f] = Grad_Conjugados_unc(@objfun_min3,[-1.2;1],2)
1 -9.84400000e-001 1.08800000e+000 2.42000000e+001 1.00000000e-003
2 -9.84399999e-001 1.08800000e+000 5.35291158e+000 1.00000000e-010
102 1.00000121e+000 1.00000243e+000 1.47631065e-012 1.00000000e-003
x =
1.000001212679899
1.000002430217752
f =
1.472951080761591e-012
64/76
pD
r f .x/
rf .x/
se utilizara
pD
donde
H rf .x/;
DFP
H son:
H kC1 D H k
H k y k y Tk H k
sk sTk
C T :
T
y k H ky k
y k sk
H kC1 D H k C 1 C
donde
y Tk H k y k
y Tk sk
y k D rf .x kC1/
sk sTk
y Tk sk
sk y Tk H k
rf .x k / y sk D x kC1
H k y k sTk
y Tk sk
:
x k D k pk
66/76
Dados
f .x/.
H k rf .x k /.
2. Calcular la amplitud de paso, k , en esa direccin.
3. Calcular el nuevo punto x kC1 WD x k C k p k .
4. Calcular H kC1.
Obtener
pk D
67/76
En Matlab:
function [x i f nfeval] = quasi_newton_1(fun,x,metodo)
% Mtodo cuasi Newton
rho = 0.01; beta = 0.1;
% Parmetros de line search
[f g] = fun(x); H=eye(length(x)); eps1=1e-5; eps2=1e-8;
maxit = 1000; nfeval = 1;
for i=1:maxit
xp = x; gp = g;
p = -H*g; nh = norm(p);
% Nueva direccin: cuasi Newton
if norm(g,inf)<eps1 || nh <= eps2*(eps2 + norm(x)), break, end
alpha = 1;
for k=1:10
% Backtracking amplitud de paso
xnew = x+alpha*p;
fxnew = fun(xnew); nfeval = nfeval+1;
if fxnew < f+alpha*rho*g*p, break
else alpha=alpha*beta;
end
end
x = x + alpha*p; s = x - xp; ns = norm(s);
[f g] = fun(x);
y = g - gp; ys = y*s; nfeval = nfeval+1;
if ys > sqrt(eps)*ns*norm(y)
% Recalcular H
v = H*y; yv = y*v;
if metodo == 1
% DFP
H = H - (v/yv)*v + (s/ys)*s;
else
% BFGS
H = H + (1+yv/ys)*(s*s)/ys - (s*v+v*s)/ys;
end
end
end
68/76
70/76
16
17
18
19
20
21
22
25
Iteration
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Func-count
26
27
29
30
31
33
34
35
37
38
39
41
42
43
44
45
46
0.940886
0.719844
0.409164
0.259747
1
1
1
0.0842377
f(x)
0.238901
0.2102
0.18249
0.15856
0.0893558
0.0726393
0.0413887
0.0221877
0.0126281
0.00703352
0.00203299
0.00109124
8.941e-005
7.16329e-006
4.44047e-007
1.49386e-008
9.03834e-013
Step-size
1
1
0.584225
1
1
0.438248
1
1
0.405833
1
1
0.5
1
1
1
1
1
3.17
5.15
5.73
5.01
First-order
optimality
1.06
1.22
3.33
2.91
0.756
3.18
2.3
0.491
1.98
1.35
0.194
0.874
0.14
0.0804
0.0222
0.00263
1.65e-005
72/76
73/76
75/76
76/76