Anda di halaman 1dari 10

Perbandingan Metode Descent Direction dalam

Pencarian Solusi Optimum Lokal Fungsi


Griewank Orde Dua
Nahrul Mubarok (20121009)
September 4, 2022

Kajian Metode
Descent Direction
Salah satu metode utama dalam mencari nilai minimum suatu fungsi f se-
cara numerik adalah membentuk suatu barisan xi dengan suatu tebakan awal
x0 dan aturan

xi+1 = xi + αi pi (1)
untuk suatu arah pi dan konstanta αi . Arah pi yang membuat barisan xi
konvergen ke nilai minimum disebut sebagai descent direction. Ada beberapa
metode pemilihan descent direction yang akan diuji, antara lain :
• Steepest descent direction
Pada metode ini, dipilih pi = −∇f (xi ). Berdasarkan Teorema Taylor,
f (xi + αi pi ) dapat ditulis dalam bentuk

f (xi + αi pi ) = f (xi ) + αi pTi ∇f (xi ) + O(2 ) (2)

Karena pi = −∇f (xi ), didapat pTi ∇f (xi ) < 0 dan f (xi + αi pi ) < f (xi )
dan didapatkan pi merupakan descent direction.
• Metode Newton
Pada metode ini, dipilih pi = ∇2 f (xi )∇f (xi ). Arah ini merupakan de-
scent direction saat ∇2 f (xi ) definit positif. Dalam kasus tersebut, didapat
bahwa

∇f (xi )pi = −pTi + ∇2 f (xi )pi ≤ −σi kpi k (3)

Jika nilai ∇f (xi ) tidak nol, maka ∇f(xi )pi < 0 dan pi merupakan descent
direction.

1
• Metode Quasi-Newton
Pada metode ini, dipilih pi = Bk ∇f (xi ) dengan matriks Bk merupakan
approksimasi dari ∇2 f (xi ) yang diperbarui tiap iterasinya. Dalam laporan
ini, akan digunakan metode symmetric-rank-one (SR1) untuk memper-
barui nilai Bk . Metode SR1 didefinisikan dengan aturan

(yk − Bk sk )(yk − Bk sk )T
Bk+1 = Bk + (4)
(yk − Bk sk )T sk

dengan sk = xk+1 − xk dan yk = ∇f (xk+1 ) − ∇f (xk ).

Line Search Method


Pencarian nilai α1 akan dilakukan secara tidak eksak dengan memanfaatkan
kriteria Wolfe. Kriteria Wolfe membuat nilai α1 yang cukup untuk menurunkan
nilai f berikutnya dan memilih gradien yang tidak terlalu bernilai negatif. Se-
cara matematis, kriteria Wolfe dapat ditulis dalam dua persamaan

f (xi + αi pi ) ≤ f (xi ) + βαi ∇fiT pi (5)


T
∇f (xi + αi pi ) pi ≥ δ∇fiT pi (6)

Algoritma
Dengan metode descent direction dan line search yang telah dijelaskan se-
belumnya, akan dicari nilai minimum dari fungsi Griewank orde 2

x2i xi
f (x1 , x2 ) = Σ2i=1 − Πcos( √ ) + 1 (7)
4000 i
Algoritma 1 adalah algoritma yang akan digunakan dalam mencari nilai min-
imum dari fungsi Griewank orde 2. Dalam algoritma tersebut, diberikan pili-
han metode mana yang diinginkan dalam mencari solusi optimum, yaitu ketiga
metode yang dijelaskan dalam bagian sebelumnya. Khusus untuk metode Quasi-
Newton, iterasi pertama tidak memiliki perbedaan dengan metode Newton un-
tuk menentukan nilai B0
Fungsi Line Search adalah fungsi yang digunakan untuk mencari nilai α
secara tidak eksak dengan menggunakan kondisi Wolfe. Algoritma dari fungsi
tersebut persis seperti apa yang tercantum dalam buku pegangan.
Algoritma akan dijalankan dengan nilai β = 10−4 , δ = 0.9 dan  = 10−3
menggunakan bahasa Python dan kodenya dapat dilihat dalam lampiran di
bagian akhir laporan.

2
Algorithm 1 Algoritma optimisasi fungsi Griewank orde 2
Require: x0 , β, δ, , Metode descent direction, Fungsi Griewank orde 2 f
if Metode = Steepest then
p0 ← −∇f (x0 )
else if Metode = Newton or Metode = Quasi-Newton then
p0 ← −∇2 f (x0 )−1 ∇f (x0 )
B0 ← ∇2 f (x0 )
end if
α0 ← Line Search(x0 , p0 , αmax , β, δ)
x1 ← x0 + α0 p0
if Metode = Quasi-Newton then
B1 merupakan perbaruan dari B0 dengan metode SR1
end if
i←1
while kxi+1 − xi k ≥  do
if Metode = Steepest then
pi ← −∇f (xi )
else if Metode = Newton then
pi ← −∇2 f (xi )−1 ∇f (xi )
else if Metode = Quasi-Newton then
pi ← −Bi−1 ∇f (x0 )
end if
αi ← Line Search(xi , pi , αmax , β, δ)
xi+1 ← xi + αi pi
if Metode = Quasi-Newton then
Bi+1 merupakan perbaruan dari Bi dengan metode SR1
end if
i←i+1
end while

3
Hasil dan Pembahasan
Gambar 1 adalah kontur dari fungsi Griewank orde dua di domain S =
[−5, 5] × [−5, 5] dengan keterangan kontur yang berwarna lebih gelap menan-
dakan nilai fungsi yang semakin kecil. Dari gambar tersebut, terlihat bahwa
terdapat lima daerah yang diperkirakan memiliki titik minimum lokal. Oleh
karena itu, akan dicari lima titik minimum lokal tersebut dengan tebakan awal
x0 adalah (0, 4, 0, 4), (4, 4), (4, −4), (−4, −4), dan (−4, 4).

Kemudian, perhatikan bahwa ∇2 f bukan merupakan fungsi definit positif di do-


main S karena terdapat x tertentu sehingga det(∇2 f ) bernilai negatif. Akibat-
nya, metode Newton baru bisa digunakan di subdomain dari S yang membuat
∇2 f definit positif.

Figure 1: Kontur Fungsi Griewank Orde 2

Metode (0,4, 0,4) (4,4) (4,-4) (-4, -4) (-4, 4)


Steepest 18 18 18 18 18
Newton 9 9 9 9 9
Quasi-Newton 27 30 26 30 26

Table 1: Banyak iterasi yang diperlukan Algoritma 1 untuk mencapai nilai yang
konvergen

Berdasarkan tabel 1, didapat bahwa metode Newton memiliki laju kekonverge-


nan yang lebih cepat dibandingkan dengan metode lainnya, bahkan lebih cepat
daripada metode Quasi-Newton. Salah satu alasan utama terjadinya hal ini
adalah karena fungsi yang ingin dicari nilai optimumnya masih memilki vari-
abel yang tidak terlalu banyak. Tabel 2 menunjukkan nilai minimum lokal dari
masing-masing percobaan dan Gambar 2, Gambar 3, dan Gambar 4 menun-
jukkan ilustrasi mengenai prediksi posisi minimum lokal.

4
Metode (0,4, 0,4) (4,4) (4,-4) (-4, -4) (-4, 4)
−6
Steepest 1.3791 × 10 0.0073982 0.0073982 0.0073982 0.0073982
Newton 2.8468 × 10−7 0.0073963 0.0073963 0.0073963 0.0073963
Quasi-Newton 1.59902 × 10−7 0.0074121 0.0074068 0.0074121 0.0074068

Table 2: Nilai minimum lokal fungsi Griewank orde dua keluaran dari Algoritma
1

Figure 2: Aproksimasi Nilai Minimum Fungsi Griewank dengan Metode Steepest


Descent Direction

Figure 3: Aproksimasi Nilai Minimum Fungsi Griewank dengan Metode Newton

Figure 4: Aproksimasi Nilai Minimum Fungsi Griewank dengan Metode Quasi-


Newton

Kesimpulan dan Saran


Berdasarkan hasil dan pembahasan di bagian sebelumnya, untuk tebakan
awal x0 yang sama, dapat disimpulkan bahwa metode Newton adalah metode
5
yang memiliki laju kekonvergenan yang lebih cepat dalam mencari solusi mini-
mum fungsi Griewank orde dua. Laporan ini akan lebih baik apabila algoritma
untuk metode Newton dimodifikasi supaya bisa berjalan dengan baik walaupun
matriks ∇2 f (xi ) bukan matriks definit positif.

6
Lampiran
Lampiran 1 : Kode Python Algoritma 1

x = []
B = []
#P i l i h x 0
x . append ( np . a r r a y ( [ − 4 , 4 ] ) )
#I n i s i a l i s a s i n i l a i −n i l a i dan metode
eps = 0.001
beta = 0.0001
delta = 0.9
method = ” Quasi−Newton”

#Program i t e r a s i pertama
i f method == ” S t e e p e s t ” :
p = −d g r i e w a n k ( x [ 0 ] )
B . append ( [ [ 1 , 0 ] , [ 0 , 1 ] ] )
e l i f method == ”Newton” or method == ” Quasi−Newton” :
p = −np . l i n a l g . i n v ( d 2 g r i e w a n k ( x [ 0 ] ) ) @ d g r i e w a n k ( x [ 0 ] )
B . append ( d 2 g r i e w a n k ( x [ 0 ] ) )

a l p h a = L i n e S e a r c h ( x [ 0 ] , p , alpha max =1)


x new = x [ 0 ] + a l p h a ∗p
x . append ( x new )

i f method == ” Quasi−Newton” :
s k = x [1] − x [ 0 ]
y k = d griewank ( x [1]) − d griewank ( x [ 0 ] )
f = y k−B [ 0 ] @s k
B new = B [ 0 ] +( f . r e s h a p e ( 2 , 1 ) @ f . r e s h a p e ( 1 , 2 ) ) / f @ s k
B . append ( B new )

i = 1
while np . l i n a l g . norm ( x [ i ]−x [ i −1])>= e p s :
i f method == ” S t e e p e s t ” :
p = −d g r i e w a n k ( x [ i ] )
B . append ( [ [ 1 , 0 ] , [ 0 , 1 ] ] )
e l i f method == ”Newton” :
p = −np . l i n a l g . i n v ( d 2 g r i e w a n k ( x [ i ] ) ) @ d g r i e w a n k ( x [ i ] )
B . append ( d 2 g r i e w a n k ( x [ i ] ) )
e l i f method == ” Quasi−Newton” :
p = −np . matmul (B [ i ] , d g r i e w a n k ( x [ i ] ) )

a l p h a = L i n e S e a r c h ( x [ i ] , p , alpha max =1)


x new = x [ i ]+ a l p h a ∗p

7
x . append ( x new )
print ( x new )

i f method == ” Quasi−Newton” :
s k = x [ i +1]−x [ i ]
y k = d g r i e w a n k ( x [ i +1])− d g r i e w a n k ( x [ i ] )
f = y k − B [ i ] @s k
B new = B [ i ] +( f . r e s h a p e ( 2 , 1 ) @ f . r e s h a p e ( 1 , 2 ) ) / f @ s k
B . append ( B new )
i += 1

Lampiran 2 : Kode Python Algoritma Program Line Search

def L i n e S e a r c h ( x , p , alpha max =1):


#I n i s i a l i s a s i n i l a i a l p h a
a l p h a = [ 0 , alpha max / 2 ]
i = 1
while i <=1000:
#J i k a s y a r a t d e s c e n t cukup t i d a k t e r p e n u h i a t a u n i l a i p h i ( a l p h a i )
#l e b i h b e s a r d a r i p h i ( a l p h a i −1) , e k s e k u s i f u n g s i
#zoom ( a l p h a i −1, a l p h a i )
i f p h i ( x , p , a l p h a [ i ]) > p h i ( x , p ,0)+ b e t a ∗ a l p h a [ i ] ∗ d p h i ( x , p , 0 ) or
( p h i ( x , p , a l p h a [ i ]) > p h i ( x , p , a l p h a [ i −1]) and i >1):
return zoom ( [ a l p h a [ i −1] , a l p h a [ i ] ] , x , p )
break
#J i k a c u r v a t u r e c o n d i t i o n t e r p e n u h i , a l p h a i menjadi o u t p u t
i f abs ( d p h i ( x , p , a l p h a [ i ]))<=− d e l t a ∗ d p h i ( x , p , 0 ) :
return a l p h a [ i ]
break
#J i k a c u r v a t u r e c o n d i t i o n t i d a k t e r p e n u h i dan g r a d i e n d a r i p h i ( a l p h a i )
#p o s i t i f , e k s e k u s i f u n g s i zoom ( a l p h a i , a l p h a i −1)
i f d p h i ( x , p , a l p h a [ i ]) >=0:
return zoom ( [ a l p h a [ i ] , a l p h a [ i − 1 ] ] , x , p )
break
#J i k a k e t i g a k o n d i s i d i a t a s t i d a k t e r p e n u h i , p i l i h a l p h a i +1
#n i l a i t e r t e n t u d i s e l a n g ( a l p h a i , alpha max )
a l p h a . append ( ( a l p h a [ i ]+ alpha max ) / 2 )
i += 1

Lampiran 3 : Kode Python Algoritma Program Zoom

def zoom ( alpha , x , p ) :


#a l p h a b e r u p a l i s t b e r i s i [ a l p h a l o , a l p h a h i ] .
i = 1

8
while i <=1000:
print ( a l p h a )
i f a l p h a [ 0 ] != 0 and a l p h a [ 1 ] != 0 :
#p r i n t (”AA”)
#Cari a l p h a n e w yang merupakan t i t i k minimum i n t e r p o l a s i k u b i k p h i
#d i s e l a n g [ 0 , max( a l p h a l o , a l p h a h i ) ]

mat = np . a r r a y ( [ [ a l p h a [ 0 ] ∗ ∗ 2 , − a l p h a [ 1 ] ∗ ∗ 2 ] ,
[− a l p h a [ 0 ] ∗ ∗ 3 , a l p h a [ 1 ] ∗ ∗ 3 ] ] )

vec = np . a r r a y ( [ p h i ( x , p , a l p h a [ 1 ] ) − p h i ( x , p ,0) − d p h i ( x , p , 0 ) ∗ a l p h a [ 1 ] ,
p h i ( x , p , a l p h a [ 0 ] ) − p h i ( x , p ,0) − d p h i ( x , p , 0 ) ∗ a l p h a [ 0 ] ] )

c o e f f = np . matmul ( mat , vec ) /


( a l p h a [ 0 ] ∗ ∗ 2 ∗ a l p h a [ 1 ] ∗ ∗ 2 ∗ ( a l p h a [1] − a l p h a [ 0 ] ) )

alpha new = (− c o e f f [ 1 ] + np . s q r t ( c o e f f [1]∗∗2 −3∗ c o e f f [ 0 ] ∗ d p h i ( x , p , 0 ) ) )


/(3∗ c o e f f [ 0 ] )

else :
#p r i n t (”AB”)
idx = alpha . index (0)
i f i d x == 0 :
alpha0 = alpha [ 1 ]
e l i f i d x == 1 :
alpha0 = alpha [ 0 ]
alpha new = ( d p h i ( x , p , 0 ) ∗ a l p h a 0 ∗ ∗ 2 )
/ ( 2 ∗ ( p h i ( x , p , a l p h a 0 )− p h i ( x , p ,0) − d p h i ( x , p , 0 ) ∗ a l p h a 0 ) )

#p r i n t ( a l p h a n e w )

#J i k a s y a r a t d e s c e n t cukup t i d a k t e r p e n u h i a t a u n i l a i p h i ( a l p h a n e w )
#l e b i h b e s a r d a r i p h i ( a l p h a l o ) , a l p h a n e w menjadi a l p h a h i

i f p h i ( x , p , alpha new ) > p h i ( x , p ,0)+ b e t a ∗ alpha new ∗ d p h i ( x , p , 0 ) or


p h i ( x , p , alpha new )> p h i ( x , p , a l p h a [ 0 ] ) :
a l p h a [ 1 ] = alpha new
else :
#J i k a c u r v a t u r e c o n d i t i o n t e r p e n u h i , a l p h a n e w menjadi o u t p u t .
Program zoom b e r h e n t i
i f abs ( d p h i ( x , p , alpha new))<=− d e l t a ∗ d p h i ( x , p , 0 ) :
return alpha new
break
#J i k a c u r v a t u r e c o n d i t i o n t i d a k t e r p e n u h i dan
#p h i ( a l p h a n e w ) ∗ ( a l p h a h i −a l p h a l o ) n o n n e g a t i f ,
#g a n t i a l p h a h i menjadi a l p h a l o

9
i f d p h i ( x , p , alpha new ) ∗ ( a l p h a [1] − a l p h a [ 0 ] ) > = 0 :
#p r i n t (”BC”)
alpha [ 1 ] = alpha [ 0 ]
#J i k a s y a r a t d e s c e n t t e r p e n u h i dan p h i ( a l p h a n e w )< p h i ( a l p h a 0 ) ,
#ubah a l p h a l o menjadi a l p h a n e w

a l p h a [ 0 ] = alpha new
i += 1

Lampiran 4 : Kode Python Algoritma Fungsi Griewank,


Fungsi φ Beserta Turunannya

def griewank ( x ) :
return ( x [ 0 ] ∗ ∗ 2 + x [ 1 ] ∗ ∗ 2 ) / 4 0 0 0 − np . c o s ( x [ 0 ] ) ∗ np . c o s ( x [ 1 ] / np . s q r t (2))+1

def d g r i e w a n k ( x ) :
return np . a r r a y ( [ x [ 0 ] / 2 0 0 0 + np . s i n ( x [ 0 ] ) ∗ np . c o s ( x [ 1 ] / np . s q r t ( 2 ) ) ,
x [ 1 ] / 2 0 0 0 + np . c o s ( x [ 0 ] ) ∗ np . s i n ( x [ 1 ] / np . s q r t ( 2 ) ) / np . s q r t ( 2 ) ] )

def d 2 g r i e w a n k ( x ) :
return np . a r r a y ( [ [ 1 / 2 0 0 0 + np . c o s ( x [ 0 ] ) ∗ np . c o s ( x [ 1 ] / np . s q r t ( 2 ) ) ,
−np . s i n ( x [ 0 ] ) ∗ np . s i n ( x [ 1 ] / np . s q r t ( 2 ) ) / np . s q r t ( 2 ) ] ,
[−np . s i n ( x [ 0 ] ) ∗ np . s i n ( x [ 1 ] / np . s q r t ( 2 ) ) / np . s q r t ( 2 ) ,
1/2000+np . c o s ( x [ 0 ] ) ∗ np . c o s ( x [ 1 ] / np . s q r t ( 2 ) ) / 2 ] ] )

def p h i ( x , p , a l p h a ) :
return griewank ( x+a l p h a ∗p )

def d p h i ( x , p , a l p h a ) :
return np . matmul ( d g r i e w a n k ( x+a l p h a ∗p ) , p )

10

Anda mungkin juga menyukai