Presentasi sedang didownload. Silahkan tunggu

Presentasi sedang didownload. Silahkan tunggu

Informed Searching Part 1

Presentasi serupa


Presentasi berjudul: "Informed Searching Part 1"— Transcript presentasi:

1 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

2 Pokok Bahasan 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

3 Best-First Search Prinsip best-first search : Lakukan node expansion terhadap node di fringe yang nilai f(n)-nya paling kecil. Ide dasar : f(n) adalah sebuah evaluation function → fungsi yang menyatakan perkiraan seberapa “bagus” sebuah node. Kenapa perkiraan? Kalau tidak, bukan search namanya! Implementasi: fringe adalah sebuah priority queue di mana node disortir berdasarkan f(n). Contoh : Uniform-cost search Greedy (best-first) search A* search

4 Heuristic Function Kunci keberhasilan best-first search terletak di heuristic function. Heuristic adalah : rule of thumb “kiat-kiat sukses”, “tips-tips keberhasilan” informasi tambahan bagi si agent (agar lebih sukses) → informed search Heuristic function h(n) adalah fungsi yang menyatakan estimasi cost dari n ke goal state. Ada banyak kemungkinan heuristic function untuk sebuah masalah.

5 Heuristic Function Contoh : (Romania with step costs in km)
Sebuah heuristic function untuk agent turis Rumania : hSLD(n) = jarak straight-line distance dari n ke Bucharest.

6 Greedy Best-First Search
Prinsip greedy best-first search : Lakukan node expansion terhadap node di fringe yang nilai h(n)-nya paling kecil. Greedy best-first search selalu memilih node yang kelihatannya paling dekat ke goal.

7 Greedy Best-First Search
Prinsip greedy best-first search : Lakukan node expansion terhadap node di fringe yang nilai h(n)-nya paling kecil. Greedy best-first search selalu memilih node yang kelihatannya paling dekat ke goal.

8 Greedy Best-First Search
Prinsip greedy best-first search : Lakukan node expansion terhadap node di fringe yang nilai h(n)-nya paling kecil. Greedy best-first search selalu memilih node yang kelihatannya paling dekat ke goal.

9 Greedy Best-First Search
Prinsip greedy best-first search : Lakukan node expansion terhadap node di fringe yang nilai h(n)-nya paling kecil. Greedy best-first search selalu memilih node yang kelihatannya paling dekat ke goal.

10 Greedy Best-First Search
Properties of greedy best-first search : Complete? Ya, jika state space terbatas dan pengulangan state-nya ditangani. (Lihat Neamt → Oradea) Time complexity? Secara teoritis, O(bm), tetapi heuristic function yang baik akan lebih mempercepat. Space complexity? O(bm) → semua node disimpan di memory Optimal? Tidak.

11 A* Search Prinsip A* search : Hindari node yang berada di path yang “mahal”. Evaluation function f(n) = g(n) + h(n) : g(n) = Path cost ke n h(n) = Estimasi path cost dari n ke goal f(n) = Estimasi total cost melalui n Contoh penelusuran A* search :

12 A* Search Prinsip A* search : Hindari node yang berada di path yang “mahal”. Evaluation function f(n) = g(n) + h(n) : g(n) = Path cost ke n h(n) = Estimasi path cost dari n ke goal f(n) = Estimasi total cost melalui n Contoh penelusuran A* search :

13 A* Search Prinsip A* search : Hindari node yang berada di path yang “mahal”. Evaluation function f(n) = g(n) + h(n) : g(n) = Path cost ke n h(n) = Estimasi path cost dari n ke goal f(n) = Estimasi total cost melalui n Contoh penelusuran A* search :

14 A* Search Prinsip A* search : Hindari node yang berada di path yang “mahal”. Evaluation function f(n) = g(n) + h(n) : g(n) = Path cost ke n h(n) = Estimasi path cost dari n ke goal f(n) = Estimasi total cost melalui n Contoh penelusuran A* search :

15 A* Search Prinsip A* search : Hindari node yang berada di path yang “mahal”. Evaluation function f(n) = g(n) + h(n) : g(n) = Path cost ke n h(n) = Estimasi path cost dari n ke goal f(n) = Estimasi total cost melalui n Contoh penelusuran A* search :

16 A* Search Prinsip A* search : Hindari node yang berada di path yang “mahal”. Evaluation function f(n) = g(n) + h(n) : g(n) = Path cost ke n h(n) = Estimasi path cost dari n ke goal f(n) = Estimasi total cost melalui n Contoh penelusuran A* search :

17 Admissible Heuristics
A* search menggunakan heuristic yang admissible ≤ h(n) ≤ h*(n), di mana h*(n) adalah cost dari n yang sebenarnya. Bahasa mudahnya : nilai sebuah heuristic function tidak pernah melebihi cost ke goal yang sebenarnya. Contoh : hSLD(n). A* search adalah optimal. Bukti optimalitas A* (1) : Andaikan G2 adalah goal suboptimal di dalam fringe. Ambil n sebuah fringe node pada path menuju G, goal optimal, sbb : Karena f(G2) > f(n), algoritma A* search tidak pernah akan memilih G2 untuk di-expand. Teorema terbukti! f(G2) = g(G2), karena h(G2) = 0 g(G2) > g(G), karena G2 tidak optimal g(G) ≥ f(n), karena h admissible

18 Admissible Heuristics
Consistency sebuah heuristic : Sebuah heuristic dikatakan consistent jika : h(n) ≤ c(n, a, n’) + h(n’) Jika h konsisten, maka : f(n’) = g(n’) + h(n’) = g(n) + c(n, a, n’) + h(n’) ≥ g(n) + h(n) ≥ f(n) Pada sembarang path, nilai f(n) tidak pernah turun (nondecreasing), atau monotonic. Theorem : If h(n) is consistent, A* using GRAPH-SEARCH is optimal

19 Admissible Heuristics
Bukti optimalitas A*(2) Node expansion A* berdasarkan urutan nilai f . Bayangkan penelusuran state space yang dilakukan A* menambahkan f-contour. Bandingkan dengan “lapisan” yang ditelusuri breadth-first dan uniform-cost.

20 A* Search Properties of A* :
Complete? Ya, kecuali jumlah node di mana f ≤ f(G) tak terbatas. Time complexity? Eksponensial dalam (error h x jumlah step solusi). Space complexity? O(bm) → semua node disimpan di memory. 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*

21 Merancang Heuristic Contoh Admissible Heuristic h(n) untuk 8-puzzle
h1(n) : jumlah angka yang salah posisi. h2(n) : jumlah jarak semua angka dari posisi yang benar (base Manhattan Distance) Diketahui posisi tile 1 di Start State (2,2) dan di Goal State (0,0) Hitung Dman(1) = |2-0|+|2-0| = = 4 h1(s) = 6 h2(s) = Dman(1) + Dman(2)+ Dman(3) + Dman(4)+ Dman(5) + Dman(6)+ Dman(7) + Dman(8)= =14 (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) Posisi

22 Merancang Heuristic Latihan Admissible Heuristic
Perhatikan 8-puzzle berikut : Tentukan h1(s) dan h2(s) !

23 Merancang Heuristic Membandingkan dua heuristic
h1 dan h2 sama-sama admissible. Mana yang lebih baik? Bandingkan jumlah node yang di-expand: Jika h2(n) ≥ h1(n) untuk semua n (dan keduanya admissible), dikatakan bahwa h2 men-dominate h1 dan lebih baik untuk search. Semakin besar nilai h(n), semakin dekat ke h*(n), semakin banyak node yang tidak di-expand (di-prune), semakin efisien search-nya! D IDS A*(h1) A*(h2) 12 3,473,941 539 113 24 54,000,000,000 39,135 1,641

24 A* Search f(N) = h(N) = jumlah angka yang salah posisi 3 4 3 4 5 3 3 4
2 4 4 2 1

25 A* Search f(N) = g(N) + h(N) dengan h(N) = jumlah angka yang salah posisi 3+3 3+4 1+5 1+3 2+3 2+4 5+2 5+0 0+4 3+4 3+2 4+1

26 A* Search f(N) = h(N) =  jarak semua angka dari posisi yang benar (base Manhattan Distance) 6 4 5 3 2 5 4 2 1

27 Admissible Heuristics
Consistency sebuah heuristic : Sebuah heuristic dikatakan consistent jika : h(n) ≤ c(n, a, n’) + h(n’) Jika h konsisten, maka : f(n’) = g(n’) + h(n’) = g(n) + c(n, a, n’) + h(n’) ≥ g(n) + h(n) ≥ f(n) Pada sembarang path, nilai f(n) tidak pernah turun (nondecreasing), atau monotonic. Theorem : If h(n) is consistent, A* using GRAPH-SEARCH is optimal

28 Admissible Heuristics
Bukti optimalitas A*(2) Node expansion A* berdasarkan urutan nilai f . Bayangkan penelusuran state space yang dilakukan A* menambahkan f-contour. Bandingkan dengan “lapisan” yang ditelusuri breadth-first dan uniform-cost.

29 Hill-Climbing Search NILAI sebuah node → h(n) (heuristic function)
Bayangkan seorang penderita amnesia mendaki gunung dengan kabut tebal (thick fog). State: posisi koordinat (X,Y) h(n): ketinggian pendaki Konsep penting: state space sebagai landscape. Disebut juga greedy local search Tergantung pilihan initial state, hill-climbing bisa terperangkap dalam local maximum.

30 Hill-Climbing Search Local maximum: tidak ada tetangga yang lebih baik, tetapi bukan solusi optimal. Plateau (dataran): semua tetangga sama baiknya. Contoh Hill-Climbing Search :

31

32 Algoritma Minimax Definisi algoritma ini rekursif, dengan base case pada terminal state Untuk menghitung MINIMAX VALUE pada initial state, harus depth-first search seluruh game tree! Complete? Ya, kalau game tree-nya finite Optimal? Ya, asumsi lawan musuh optimal juga. (Kalau tidak? “Lebih optimal”!) Time complexity? O(bm) Space complexity? O(bm) (atau O(m) dgn. backtracking) Contoh dalam catur: b ≈ 35, m ≈ 100 → pencarian strategi optimal berdasarkan Minimax tidak feasible!

33 Algoritma Minimax Biasanya dalam suatu permainan ada batasan waktu
Andaikan ada agent bermain catur yang diberi 100 detik untuk “berpikir” tiap langkah. Mis. sistem bisa memproses 104 node/detik → 106 node/langkah. Kita bisa melakukan aproksimasi sbb.: Cutoff: batasi depth yang diproses (≈ IDS). Evaluation function: prediksi dari nilai utility function (tidak perlu sampai ke terminal state).

34 Algoritma Minimax Biasanya, evaluation function berupa kombinasi linier dari fitur-fitur sebuah state: Eval (s) = w1f1(s) + w2f2(s) wnfn (s) = Mis. untuk catur: w1 = 1, f1 = jumlah pion putih - jumlah pion hitam w2 = 3, f2 = jumlah gajah putih - jumlah gajah hitam

35 Algoritma Minimax 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.

36 Algoritma Minimax Penyelesaian pada Tic-Tac-Toe (Algoritma Min Max) :

37 Game Playing - Minimax Misal, Terdiri dari : 3 2 1 3 2 5 3 1 4
2 players: MAX (computer) and MIN (opponent) Sifat : deterministic, perfect information. Select a depth-bound (say: 2) and evaluation function MAX MIN - Construct the tree up till the depth-bound Select this move 3 - Compute the evaluation function for the leaves 2 1 3 - Propagate the evaluation function upwards: - Taking minima in MIN - Taking maxima in MAX 2 5 3 1 4

38 Minimax Example MAX 1 A B C MIN 1 -3 D E F G MAX 4 1 2 -3 4 -5 1 -7 2
Select this move B C MIN 1 -3 D E F G MAX 4 1 2 -3 4 -5 1 -7 2 -3 -8 = terminal position = agent = opponent

39 Algoritma Alpha-beta Pruning
Secara umum digunakan untuk optimasi Algoritma Mini-max. Instead of : First creating the entire tree (up to depth-level) Then doing all propagation Interleave the generation of the tree and the propagation of values. Point : 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.

40 Algoritma Alpha-beta Pruning
Principles: Generate the tree depth-first, left-to-right (propagate final values of nodes as initial estimates for their parent node). MIN MAX 2 2 - The MIN-value (1) is already smaller than the MAX-value of the parent (2) 1 - The MIN-value can only decrease further, 2 =2 1 5 - The MAX-value is only allowed to increase, - No point in computing further below this node

41 Algoritma Alpha-beta Pruning
If an ALPHA-value is larger or equal than the Beta-value of a descendant node : stop generation of the children of the descendant Alpha-value MIN MAX 2 2 1 2 =2 1 Beta-value 5

42 Algoritma Alpha-beta Pruning
If an Beta-value is smaller or equal than the Alpha-value of a descendant node: stop generation of the children of the descendant MIN MAX 2 2 3 2 =2 1 Beta-value 5 Alpha-value

43 Algoritma Alpha-beta Pruning
MAX A B C MIN ≤ 6 D E MAX 6 ≥ 8 H I J K 6 5 8 = agent = opponent

44 Algoritma Alpha-beta Pruning
MAX ≥ 6 A B C MIN 6 ≤ 2 D E F G MAX 6 ≥ 8 2 H I J K L M 6 5 8 2 1 = agent = opponent

45 Algoritma Alpha-beta Pruning
MAX ≥ 6 A B C MIN 6 2 D E F G MAX 6 ≥ 8 2 H I J K L M 6 5 8 2 1 = agent = opponent

46 Algoritma Alpha-beta Pruning
MAX 6 A B C MIN 6 2 beta cutoff D E F G MAX 6 ≥ 8 alpha cutoff 2 H I J K L M 6 5 8 2 1 = agent = opponent

47 Mini-Max with  at work:
8 7 3 9 1 6 2 4 5  4 16  5 31 39 = 5 MAX 6  8  5 23 15 = 4 30 = 5  3 38 MIN 10  2 18  1 33  1 2  8 12  4 20  3 25  3 35  2 5 = 8 8  9 14 = 4 22 = 5 27  9 29  6 37 = 3 MAX 1 3 4 7 9 11 13 17 19 21 24 26 28 32 34 36 11 static evaluations saved !!

48 Example of a perfectly ordered tree
MAX MIN 21

49 Algoritma Alpha-beta Pruning
Kesimpulan : alpha-beta algorithm does the same calculation as minimax, and is more efficient since it prunes irrelevant branches. 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. So far, for a possibly good and efficient search: select good search method/technique provide info/heuristic if possible apply prune irrelevant branches

50 Ringkasan Best-first search : Uniform-cost search : f(n) = g(n)
Greedy best-first search : f(n) = h(n) A* search : f(n) = g(n) + h(n) Dengan heuristic yang admissible dan consistent , A* pasti complete dan optimal. Heuristic dapat diperoleh dari variasi masalah yang dipermudah, atau submasalah. Search di mana environment-nya tidak observable atau non-deterministic masih bisa diatasi. Permasalahan utama : menghindari local maximum secara stochastic.

51 Selesai


Download ppt "Informed Searching Part 1"

Presentasi serupa


Iklan oleh Google