Professional Documents
Culture Documents
, ,
1 ,
, MATLAB , Newton-Raphson method
Steepest Descent method
MATLAB
MATLAB
h MATLAB i
:
min f (x)
(1)
f (x) : Rn R, , x
1 ,
1:
f (x)
5f (x) =
f (x)
x1
f (x)
x2
..
.
f (x)
xn
=0
(2)
f (x) ,
, closed-form solution
k = 0, 1, 2,
xk+1 = xk + dk
x0 , (dk ) ,
Newton-Raphson method,
:
dk = (52 f (xk ))1 5 f (xk )
(3)
52 f (x) =
2 f (x)
x1 x1
2 f (x)
x2 x1
2 f (x)
x1 x2
2 f (x)
x2 x2
2 f (x)
xn x1
2 f (x)
xn x2
..
.
..
.
...
2 f (x)
x1 xn
2 f (x)
x2 xn
..
.
2 f (x)
xn xn
(4)
Hessian matrix ,
(), ,
, :
,
dk = 5 f (x)
(5)
, ,
,
1.
f (x, y) = xex
2 y 2
:
1. X Y (grids), MATLAB
[X,Y]=meshgrid( X , Y )
X Y X Y X Y meshgrid
help meshgrid 2 [X,Y]=meshgrid(-2:2,-1:3)
X Y ,
2: meshgrid
2. X Y Z help meshgrid 3 meshgrid z =
4
f (x, y) = xex
2 y 2
X Y Z
Z = X. exp(X. 2 Y. 2);
mesh(X, Y, Z)
3. meshgrid ,
4. , mesh, surf, contour()
, ,
3: meshgrid
4 4(b) (colorbar),
, , contour
colorbar , , XY ,
, , , 4 ,
XY (x1 vs. x2 ) , ,
axis square
(a)
(b)
2.
f (x1 , x2 ) = (x1 2)4 + (x1 2)2 x22 + (x2 + 1)2
(6)
1 ,
(,contour), contour
, , ,
contour(X, Y, Z, 100)
,
, , ,
MATLAB ,
3. MATLAB fminsearch
min (x1 2)4 + (x1 2)2 x22 + (x2 + 1)2
x1 ,x2
MATLAB , : (constrained)
(unconstrained) ,
, MATLAB fminsearch,
(function) , fminsearch
,
,
, , ,
, fminsearch
MATLAB
opts=optimset(fminsearch);
opts.Display=iter;
opts.MaxFunEvals=8000;
opts.MaxIter=8000;
opts.TolFun=1e-6;
opts.TolX=1e-6;
f = @(x) (x(1) 2) 4 + (x(1) 2) 2 x(2) 2 + (x(2) + 1) 2;
[x, f val] = f minsearch(f, [0, 0], opts);
,MATLAB optimset
, , MATLAB
opts , opts
2 6
DIsplay iter, ,
, ,
8
MaxFunEvals , ,
, , , , MATLAB 200* ,
MaxIter , 200*
TolFun , ,
, ,
min
x1 ,x2
1. = {x1 , x2 R| x1 0, x2 0}
2. = {x1 , x2 R| x1 1, x2 2}
3. = {x1 , x2 R| 0 x1 1, 0 x2 2}
2
4. = {x1 , x2 R| 0 x1 , x2 2}
5. = {x1 , x2 R| x1 + x2 0.9}
6. = {x1 , x2 R| 1.5 x1 + x2 2}
7. = {x1 , x2 R|
x21 + x22 1}
8. = {x1 , x2 R|
x21 + x22 1, x1 x2 0}
,
, 0 1 ,
fminsearchcon fminsearchcon ,
[x, fval]=fminsearchcon(fun, x0, LB, UB, A, b, nonlcon, options);
fun x0 , LB, U B ,
, LB x U B,A, b , Ax b, A , b
p
nonlcon C(x) 0, x21 + x22 1,
MATLAB @(x)norm(x) 1, g = @(x)norm(x) 1, g
nonlcon ,C(x) ,
, g = @(x)[norm(x) 1; x(1) x(2)]
MATLAB optimization toolbox fmincon,
, , , fminsearchcon
fminsearchcon , ,
,
5. 5 1000 ,
= {1 , 2 , a1 , b1 , a2 , b2 }, 1 + 2 = 1
(MLE)
L() =
1000
X
i=1
max
L()
, 1 + 2 = 1 1 , 2 > 0
0 < 1 < 1 2 1 1 , 5
( x)
opts=optimset(fminsearch);
opts.Display=iter;
opts.MaxFunEvals=8000;
opts.MaxIter=8000;
opts.TolFun=1e-6;
opts.TolX=1e-6;
initial=[0.5 1 10 5 5];
LB=[0 0 0 0 0];
UB=[1 Inf Inf Inf Inf];
L = @(p) sum(log(p(1) betapdf (x, p(2), p(3)) + (1 p(1))
betapdf (x, p(4), p(5))));
[mle, f val] = f minsearchcon(L, initial, LB, U B, [ ], [ ], [ ], opts);
? ,
,
11
5:
6. (6) 5f (x) Hessian Matrix 52 f (x)
, , ,
,
Hessian Matrix
, ( 1),
,
, , , ,
6 steepest descent steepest descent
, , 15 Hessian matrix
, 18 xk1
6 , (), x
,
12
12 fprintf , C printf, ,
,
, %10.7f, (floating point)
, 7 , 2 , ,
10 , \n
6: Steepest descent
6 , steepest descent , ??
13 xk X, 14 1 ,
, 23,24
, (xk1) (xk),
,
13
7: Steepest descent :x
, , ,
, Newton-Raphson
Hessian Matrix , , steepest descent ,
, ,
xk+1 = xk + dk
14
3. dk ( (3) (5))
,
[1]
1. ,
2. Newton-Raphson method , (3),
f (xk+1 )
1
f (xk+1 ) = f (xk +dk ) = f (xk )+5f (x)T dk + dTk 52 f (x)dk +O(||dk ||3 )
2
3. Rosenbrocks Banana
f (x, y) = 100(y x2 )2 + (1 x)2
, (mesh) (contour), ,
4. , (mesh contour)
5. (3) (5) ,
, ,
, ;
, : dk , ,
15
6. MLE
n
Y
L(, ) =
i=1
where
ft (v; , ) = v 1 exp(v )
FT (u; , ) = 1 exp(u )
u, v n , UV.txt
http://web.ntpu.edu.tw/ccw/statmath/book.htm ,
7. , ,
, :
X, Y , PDF fX (x) = (x|a1 , b1 ),
fY (x) = (x|a2 , b2 ) Z
Z = XY
Z , , (a, b) Z ,
Z
min
a,b
f (z) Z PDF,
Z
f (z) =
z
1
fY (y)fX (z/y) dy
y
a, b
Hint:
quad fminsearch
Beta betapdf(x,2,2)
, (function)
8. ,
,
max
L()
L() =
N
X
i=1
f (x|, 2 ) fminsearchcon = {1 , 1 , 12 , 2 , 22 }
[1] J.E. Dennis, R.B. Schnabel, Numerical Methods for Unconstrained Optimization, Prentice Hall.
17
18