Kecerdasan Buatan Artificial Intelligence Informed Searching Part 1
Kecerdasan Buatan/ Artificial Intelligence Informed Searching Part 1 Rekyan Regasari Mardi Putri, ST, MT Lailil Muflikhah, S. Kom, M. Sc Imam Cholissodin, S. Si. , M. Kom M. Ali Fauzi, S. Kom, M. Kom
Pokok Bahasan 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. Best-first search Min-Max Alpha Betha Pruning Greedy best-first search A* search Heuristics Local search algorithms Hill-climbing search Simulated annealing Local beam search Genetic algorithms Latihan Individu + Tugas Kelompok
Best-First Search q Prinsip best-first search : Lakukan node expansion terhadap node di fringe yang nilai f(n)-nya paling kecil. q Ide dasar : f(n) adalah sebuah evaluation function → fungsi yang menyatakan perkiraan seberapa “bagus” sebuah node. q Kenapa perkiraan? Kalau tidak, bukan search namanya! q Implementasi: fringe adalah sebuah priority queue di mana node disortir berdasarkan f(n). q Contoh : o Uniform-cost search o Greedy (best-first) search o A* search
Heuristic Function q Kunci keberhasilan best-first search terletak di heuristic function. q Heuristic adalah : o rule of thumb o “kiat-kiat sukses”, “tips-tips keberhasilan” o informasi tambahan bagi si agent (agar lebih sukses) → informed search q Heuristic function h(n) adalah fungsi yang menyatakan estimasi cost dari n ke goal state. q Ada banyak kemungkinan heuristic function untuk sebuah masalah.
Heuristic Function q Contoh : (Romania with step costs in km) q Sebuah heuristic function untuk agent turis Rumania : h. SLD(n) = jarak straight-line distance dari n ke Bucharest.
Greedy Best-First Search q Prinsip greedy best-first search : Lakukan node expansion terhadap node di fringe yang nilai h(n)-nya paling kecil. q Greedy best-first search selalu memilih node yang kelihatannya paling dekat ke goal.
Greedy Best-First Search q Prinsip greedy best-first search : Lakukan node expansion terhadap node di fringe yang nilai h(n)-nya paling kecil. q Greedy best-first search selalu memilih node yang kelihatannya paling dekat ke goal.
Greedy Best-First Search q Prinsip greedy best-first search : Lakukan node expansion terhadap node di fringe yang nilai h(n)-nya paling kecil. q Greedy best-first search selalu memilih node yang kelihatannya paling dekat ke goal.
Greedy Best-First Search q Prinsip greedy best-first search : Lakukan node expansion terhadap node di fringe yang nilai h(n)-nya paling kecil. q Greedy best-first search selalu memilih node yang kelihatannya paling dekat ke goal.
Greedy Best-First Search q Properties of greedy best-first search : o Complete? Ya, jika state space terbatas dan pengulangan statenya ditangani. (Lihat Neamt → Oradea) o Time complexity? Secara teoritis, O(bm), tetapi heuristic function yang baik akan lebih mempercepat. o Space complexity? O(bm) → semua node disimpan di memory o Optimal? Tidak.
A* Search q Prinsip A* search : Hindari node yang berada di path yang “mahal”. q Evaluation function f(n) = g(n) + h(n) : o g(n) = Path cost ke n o h(n) = Estimasi path cost dari n ke goal o f(n) = Estimasi total cost melalui n q Contoh penelusuran A* search :
A* Search q Prinsip A* search : Hindari node yang berada di path yang “mahal”. q Evaluation function f(n) = g(n) + h(n) : o g(n) = Path cost ke n o h(n) = Estimasi path cost dari n ke goal o f(n) = Estimasi total cost melalui n q Contoh penelusuran A* search :
A* Search q Prinsip A* search : Hindari node yang berada di path yang “mahal”. q Evaluation function f(n) = g(n) + h(n) : o g(n) = Path cost ke n o h(n) = Estimasi path cost dari n ke goal o f(n) = Estimasi total cost melalui n q Contoh penelusuran A* search :
A* Search q Prinsip A* search : Hindari node yang berada di path yang “mahal”. q Evaluation function f(n) = g(n) + h(n) : o g(n) = Path cost ke n o h(n) = Estimasi path cost dari n ke goal o f(n) = Estimasi total cost melalui n q Contoh penelusuran A* search :
A* Search q Prinsip A* search : Hindari node yang berada di path yang “mahal”. q Evaluation function f(n) = g(n) + h(n) : o g(n) = Path cost ke n o h(n) = Estimasi path cost dari n ke goal o f(n) = Estimasi total cost melalui n q Contoh penelusuran A* search :
A* Search q Prinsip A* search : Hindari node yang berada di path yang “mahal”. q Evaluation function f(n) = g(n) + h(n) : o g(n) = Path cost ke n o h(n) = Estimasi path cost dari n ke goal o f(n) = Estimasi total cost melalui n q Contoh penelusuran A* search :
Admissible Heuristics q A* search menggunakan heuristic yang admissible 0 ≤ h(n) ≤ h*(n), di mana h*(n) adalah cost dari n yang sebenarnya. q Bahasa mudahnya : nilai sebuah heuristic function tidak pernah melebihi cost ke goal yang sebenarnya. Contoh : h. SLD(n). q A* search adalah optimal. Bukti optimalitas A* (1) : o Andaikan G 2 adalah goal suboptimal di dalam fringe. Ambil n sebuah fringe node pada path menuju G, goal optimal, sbb : • • • f(G 2) = g(G 2), karena h(G 2) = 0 g(G 2) > g(G), karena G 2 tidak optimal g(G) ≥ f(n), karena h admissible o Karena f(G 2) > f(n), algoritma A* search tidak pernah akan memilih G 2 untuk di-expand. Teorema terbukti!
Admissible Heuristics q Consistency sebuah heuristic : o Sebuah heuristic dikatakan consistent jika : h(n) ≤ c(n, a, n’) + h(n’) o Jika h konsisten, maka : f(n’) = g(n’) + h(n’) = g(n) + c(n, a, n’) + h(n’) ≥ g(n) + h(n) ≥ f(n) o Pada sembarang path, nilai f(n) tidak pernah turun (nondecreasing), atau monotonic. o Theorem : If h(n) is consistent, A* using GRAPHSEARCH is optimal
Admissible Heuristics q Bukti optimalitas A*(2) o Node expansion A* berdasarkan urutan nilai f. o Bayangkan penelusuran state space yang dilakukan A* menambahkan f-contour. o Bandingkan dengan “lapisan” yang ditelusuri breadthfirst dan uniform-cost.
A* Search q Properties of A* : o Complete? Ya, kecuali jumlah node di mana f ≤ f(G) tak terbatas. o Time complexity? Eksponensial dalam (error h x jumlah step solusi). o Space complexity? O(bm) → semua node disimpan di memory. o Optimal? Ya. § A* meng-expand semua node di mana f(n) < C* § A* (mungkin) meng-expand beberapa node di mana f(n) = C* § A* tidak pernah meng-expand node di mana f(n) > C*
Merancang Heuristic q Contoh Admissible Heuristic o h(n) untuk 8 -puzzle • h 1(n) : jumlah angka yang salah posisi. • h 2(n) : jumlah jarak semua angka dari posisi yang benar (base Manhattan Distance) (0, 0) (0, 1) (0, 2) (1, 0) (1, 1) (1, 2) (2, 0) (2, 1) (2, 2) Posisi • Diketahui posisi tile 1 di Start State (2, 2) dan di Goal State (0, 0) • Hitung Dman(1) = |2 -0|+|2 -0| = 2 + 2 = 4 o h 1(s) = 6 o h 2(s) = Dman(1) + Dman(2)+ Dman(3) + Dman(4)+ Dman(5) + Dman(6)+ Dman(7) + Dman(8)= 4+0+3+3+1+0+2+1=14
Merancang Heuristic q Latihan Admissible Heuristic o Perhatikan 8 -puzzle berikut : Tentukan h 1(s) dan h 2(s) !
Merancang Heuristic q Membandingkan dua heuristic o h 1 dan h 2 sama-sama admissible. Mana yang lebih baik? Bandingkan jumlah node yang di-expand: D IDS A*(h 1) A*(h 2) 12 3, 473, 941 539 113 24 54, 000, 000 39, 135 1, 641 o Jika h 2(n) ≥ h 1(n) untuk semua n (dan keduanya admissible), dikatakan bahwa h 2 men-dominate h 1 dan lebih baik untuk search. o Semakin besar nilai h(n), semakin dekat ke h*(n), semakin banyak node yang tidak di-expand (diprune), semakin efisien search-nya!
A* Search q f(N) = h(N) = jumlah angka yang salah posisi 3 5 3 4 2 4 2 3 3 0 4 5 4 1
A* Search q f(N) = g(N) + h(N) dengan h(N) = jumlah angka yang salah posisi 3+3 1+5 2+3 3+4 5+2 0+4 3+2 1+3 2+3 5+0 3+4 1+5 2+4 4+1
A* Search q f(N) = h(N) = jarak semua angka dari posisi yang benar (base Manhattan Distance) 6 5 2 4 3 0 4 6 5 1
Admissible Heuristics q Consistency sebuah heuristic : o Sebuah heuristic dikatakan consistent jika : h(n) ≤ c(n, a, n’) + h(n’) o Jika h konsisten, maka : f(n’) = g(n’) + h(n’) = g(n) + c(n, a, n’) + h(n’) ≥ g(n) + h(n) ≥ f(n) o Pada sembarang path, nilai f(n) tidak pernah turun (nondecreasing), atau monotonic. o Theorem : If h(n) is consistent, A* using GRAPHSEARCH is optimal
Admissible Heuristics q Bukti optimalitas A*(2) o Node expansion A* berdasarkan urutan nilai f. o Bayangkan penelusuran state space yang dilakukan A* menambahkan f-contour. o Bandingkan dengan “lapisan” yang ditelusuri breadthfirst dan uniform-cost.
Hill-Climbing Search q NILAI sebuah node → h(n) (heuristic function) q Bayangkan seorang penderita amnesia mendaki gunung dengan kabut tebal (thick fog). o State: posisi koordinat (X, Y) o h(n): ketinggian pendaki q Konsep penting: state space sebagai landscape. q Disebut juga greedy local search q Tergantung pilihan initial state, hill-climbing bisa terperangkap dalam local maximum.
Hill-Climbing Search q Local maximum: tidak ada tetangga yang lebih baik, tetapi bukan solusi optimal. q Plateau (dataran): semua tetangga sama baiknya. q Contoh Hill-Climbing Search :
Algoritma Minimax q Definisi algoritma ini rekursif, dengan base case pada terminal state q Untuk menghitung MINIMAX VALUE pada initial state, harus depth-first search seluruh game tree! q Complete? Ya, kalau game tree-nya finite q Optimal? Ya, asumsi lawan musuh optimal juga. (Kalau tidak? “Lebih optimal”!) q Time complexity? O(bm) q Space complexity? O(bm) (atau O(m) dgn. backtracking) q Contoh dalam catur: b ≈ 35, m ≈ 100 → pencarian strategi optimal berdasarkan Minimax tidak feasible!
Algoritma Minimax q Biasanya dalam suatu permainan ada batasan waktu q Andaikan ada agent bermain catur yang diberi 100 detik untuk “berpikir” tiap langkah. q Mis. sistem bisa memproses 104 node/detik → 106 node/langkah. q Kita bisa melakukan aproksimasi sbb. : o Cutoff: batasi depth yang diproses (≈ IDS). o Evaluation function: prediksi dari nilai utility function (tidak perlu sampai ke terminal state).
Algoritma Minimax q Biasanya, evaluation function berupa kombinasi linier dari fitur-fitur sebuah state: q Eval (s) = w 1 f 1(s) + w 2 f 2(s) +. . . + wnfn (s) = q Mis. untuk catur: q w 1 = 1, f 1 = jumlah pion putih - jumlah pion hitam q w 2 = 3, f 2 = jumlah gajah putih - jumlah gajah hitam
Algoritma Minimax q Contoh penerapan algoritma Min Max. Diberikan sebuah situasi permainan seperti di bawah ini : • X (max player) sedang dalam giliran untuk melanjutkan permainan. Berikan semua situasi berikutnya yang mungkin untuk X • Pilihlah jalur yang tepat sesuai dengan algoritma minmax, jika diketahui fungsi utilitas untuk situasi menang untuk X = +10, kalah = -10, dan draw = 0.
Algoritma Minimax q Penyelesaian pada Tic-Tac-Toe (Algoritma Min Max) :
Game Playing - Minimax q Misal, Terdiri dari : o 2 players: MAX (computer) and MIN (opponent) o Sifat : deterministic, perfect information. Select a depth-bound (say: 2) and evaluation function MAX MIN MAX Select this move 3 2 3 1 - Construct the tree up till the depth-bound - Compute the evaluation function for the leaves - Propagate the evaluation function upwards: - Taking minima in MIN - Taking maxima in MAX 2 5 3 1 4 4 3
Minimax Example MAX 1 A Select this move MIN MAX 4 1 4 B D -5 -3 1 E -5 = terminal position 2 1 -7 = agent C F -3 2 G -3 -8 = opponent
Algoritma Alpha-beta Pruning q Secara umum digunakan untuk optimasi Algoritma Minimax. q Instead of : o First creating the entire tree (up to depth-level) o Then doing all propagation o Interleave the generation of the tree and the propagation of values. q Point : o Some of the obtained values in the tree will provide information that other (non-generated) parts are redundant and do not need to be generated.
Algoritma Alpha-beta Pruning q Principles: o Generate the tree depth-first, left-to-right (propagate final values of nodes as initial estimates for their parent node). MAX 2 MIN 2 MAX =2 - The MIN-value (1) is already smaller than the MAX-value of the parent (2) - The MIN-value can only decrease further, 1 - The MAX-value is only allowed to increase, - No point in computing further below this node 2 5 1
Algoritma Alpha-beta Pruning q If an ALPHA-value is larger or equal than the Beta-value of a descendant node : stop generation of the children of the descendant 2 MIN 2 =2 Alpha-value MAX 2 5 1 1 Beta-value
Algoritma Alpha-beta Pruning q If an Beta-value is smaller or equal than the Alpha-value of a descendant node: stop generation of the children of the descendant 2 MIN 2 =2 1 Beta-value MAX 2 5 3 Alpha-value
Algoritma Alpha-beta Pruning MAX A MIN ≤ 6 MAX 6 D B ≥ 8 H I J 6 5 8 = agent C E K = opponent
Algoritma Alpha-beta Pruning MAX ≥ 6 MIN 6 MAX 6 D A B ≥ 8 H I J 6 5 8 = agent ≤ 2 E 2 K C F G L M 2 1 = opponent
Algoritma Alpha-beta Pruning MAX ≥ 6 MIN 6 MAX 6 D A B ≥ 8 H I J 6 5 8 = agent 2 E 2 K C F G L M 2 1 = opponent
Algoritma Alpha-beta Pruning MAX 6 MIN 6 MAX 6 D A B ≥ 8 H I J 6 5 8 = agent 2 E alpha cutoff K 2 C F beta cutoff G L M 2 1 = opponent
Mini-Max with at work: 4 16 8 6 5 23 = 4 15 8 2 =8 5 9 8 2 10 1 18 4 12 3 20 = 4 14 = 5 22 9 11 13 MAX 3 38 = 5 30 8 7 3 9 1 6 2 4 1 1 3 4 7 5 31 = 5 39 1 33 2 35 3 25 9 27 6 29 = 3 37 1 3 5 3 9 2 6 5 2 17 19 21 24 26 MIN 28 MAX 1 2 3 9 7 2 8 6 4 32 34 36 11 static evaluations saved !!
Example of a perfectly ordered tree MAX 21 21 21 24 12 27 21 20 19 24 23 22 27 26 25 12 15 3 18 12 11 10 15 14 13 18 17 16 3 6 MIN 9 MAX 3 2 1 6 5 4 9 8 7
Algoritma Alpha-beta Pruning q Kesimpulan : o alpha-beta algorithm does the same calculation as minimax, and is more efficient since it prunes irrelevant branches. o usually, the complete game tree is not expanded, search is cut off at some point and an evaluation function calculated to estimate the utility of a state. o So far, for a possibly good and efficient search: • select good search method/technique • provide info/heuristic if possible • apply prune irrelevant branches
Ringkasan q Best-first search : o Uniform-cost search : f(n) = g(n) o Greedy best-first search : f(n) = h(n) o A* search : f(n) = g(n) + h(n) q Dengan heuristic yang admissible dan consistent , A* pasti complete dan optimal. q Heuristic dapat diperoleh dari variasi masalah yang dipermudah, atau submasalah. q Search di mana environment-nya tidak observable atau non-deterministic masih bisa diatasi. q Permasalahan utama : menghindari local maximum secara stochastic.
Selesai
- Slides: 51