Download presentation
Presentation is loading. Please wait.
Published byBeatrix Lucas Modified over 9 years ago
1
חיפוש בינה מלאכותית אבי רוזנפלד
2
סוכנים פותרי בעיות Reflex agents לא יכולים לתכנן קדימה כדי לחפש, יש צורך לייצר מודל לחפש בו !
3
להגדרת אלגוריתם חיפוש סוכן צריך לדחות פעולות שלא מקדמות למטרה Goal formulation - נוסחת מטרה המבוססת על מדד הביצועים הנוכחיים של הסוכן ועל המצב הנוכחי מטרה – אוסף של מצבים בעולם שצריכים להתקיים אם המטרה הושגה. מטרת הסוכן היא למצוא את רצף הפעולות שיביא אותו לאוסף הזה של מצבים קודם לכן, עליו להחליט אילו פעולות ואילו מצבים הם רלוונטיים.
4
State Space 1. initial state 2. successor function
5
Goal Test 3. goal test
6
מפת רומניה
7
Example: 8-Puzzle
8
(Partial) Search Space for 8-Puzzle Problem 1. initial state 2. successor function 3. goal test
9
Example: Route Planning in a Map Graph: nodes are cities and links are roads. Map gives world dynamics Current state is known World is fully predictable World (set of cities) is finite and enumerable. Cost: total distance or total time for path.
10
על מה לומדים היום ? BFS DFS Best-first search A * search – Heuristics Local search algorithms – Hill-climbing search – Backtracking – Simulated annealing 10
11
איך מבצעים את החיפוש?
12
Breadth-First Search Breadth-first search tree after 0,1,2 and 3 node expansions CLASSIC FIFO! (Queue!) אופטימאלי
13
Depth-First Search לא אופטימאלי ! Alternatively can use a recursive implementation.
14
Breadth-First Search A B Z O SF C P R T L M D
15
A B Z O SF C P R T L M D A
16
A B Z O SF C P R T L M D A Z A S A T A
17
Breadth-First Search A B Z O SF C P R T L M D A Z A S A T A S A T A O AZ
18
Breadth-First Search A B Z O SF C P R T L M D A Z A S A T A S A T A O AZ T A O AZ O AS F AS R AS
19
Breadth-First Search A B Z O SF C P R T L M D A Z A S A T A S A T A O AZ T A O AZ O AS F AS R AS O AZ O AS F AS R AS L AT
20
Breadth-First Search A B Z O SF C P R T L M D A Z A S A T A S A T A O AZ T A O AZ O AS F AS R AS O AZ O AS F AS R AS L AT O AS F AS R AS L AT
21
Breadth-First Search A B Z O SF C P R T L M D A Z A S A T A S A T A O AZ T A O AZ O AS F AS R AS O AZ O AS F AS R AS L AT O AS F AS R AS L AT
22
Breadth-First Search A B Z O SF C P R T L M D A Z A S A T A S A T A O AZ T A O AZ O AS F AS R AS O AZ O AS F AS R AS L AT O AS F AS R AS L AT R AS L AT B ASF Result = B ASF
23
Breadth-First Search B A Z O SF C P R T L M D
24
Evaluation of Search Strategies Completeness Time Complexity Space Complexity Optimality To evaluate, we use the following terms b = branching factor m = maximum depth d = goal depth
25
Evaluation of BFS Complete Complexity: – O(b d ) time – O(b d ) space Optimal (counting by number of arcs).
26
Depth-First Search A B Z O SF C P R T L M D
27
A B Z O SF C P R T L M D A
28
A B Z O SF C P R T L M D A Z A S A T A
29
Depth-First Search A B Z O SF C P R T L M D A Z A S A T A
30
Depth-First Search A B Z O SF C P R T L M D A Z A S A T A O AZ S A T A
31
Depth-First Search A B Z O SF C P R T L M D A Z A S A T A O AZ S A T A S AZO S A T A
32
Depth-First Search A B Z O SF C P R T L M D A Z A S A T A O AZ S A T A S AZO S A T A F AZOS R AZOS S A T A
33
Depth-First Search A B Z O SF C P R T L M D A Z A S A T A O AZ S A T A S AZO S A T A F AZOS R AZOS S A T A B AZOSF R AZOS S A T A
34
Depth-First Search A B Z O SF C P R T L M D A Z A S A T A O AZ S A T A S AZO S A T A F AZOS R AZOS S A T A B AZOSF R AZOS S A T A Result = B AZOSF
35
Depth-first Search O A B Z SF C P R T L M D
36
Evaluation of DFS Not complete Complexity: – O(b m ) time – O(mb) space Non-optimal
37
Bi-Directional Search
38
Romania with step costs in km 38
39
Greedy best-first search example 39
40
Greedy best-first search example 40
41
Greedy best-first search example 41
42
Greedy best-first search example 42
43
Romania with step costs in km 43 המחיר הכולל: 450. האם זה אופטימאלי? לא!
44
Properties of greedy best-first search Complete? No – can get stuck in loops, e.g., Iasi Neamt Iasi Neamt Complete in finite space with checking for repeated states Time? O(b m ), but a good heuristic can give dramatic improvement Space? O(b m ) – keeps all nodes in memory Optimal? No 44 b is branching factor, m is maximum depth of the search space
45
הרעיון המרכזי : קח בחשבון את המחיר הכללי ( עד עכשיו ) Evaluation function f(n) = g(n) + h(n) g(n) = cost so far to reach n h(n) = estimated cost from n to goal f(n) = estimated total cost of path through n to goal A* search uses an admissable heuristic: h(n) <= h*(n), where h*(n) is the true cost from n Also require h(n) >= 0, so h(G) = 0 for any goal G 45 A * חיפוש
46
A * search example 46
47
A * search example 47
48
A * search example 48
49
A * search example 49
50
A * search example 50
51
A * search example 51
52
Romania with step costs in km 52
53
Heuristic functions E.g., for the 8-puzzle Avg. solution cost is about 22 steps (branching factor +/- 3) Exhaustive search to depth 22: 3.1 x 10 10 states A good heuristic function can reduce the search 53
54
Heuristic functions For the 8-puzzle, two commonly used heuristics h 1 = the number of misplaced tiles h 1 (s)=8 h 2 = the sum of the distances of the tiles from their goal positions (manhattan distance) h 2 (s)=3+1+2+2+2+3+3+2=18 54
55
Inventing admissible heuristics Another way to find an admissible heuristic is through learning from experience: Experience = solving lots of 8-puzzles An inductive learning algorithm can be used to predict costs for other states that arise during search 55
56
בעיית המלכות השחמט יש ל 8 מלכות בשחמט איך אפשר לשים את כולם על הלוח כך שאחת לא יכולה לתקוף את השני יש 92 פתרונות http://he.wikipedia.org/wiki/%D7%97%D7%99%D7%93%D7%AA_%D7%A9%D7%9E% D7%95%D7%A0%D7%94_%D7%94%D7%9E%D7%9C%D7%9B%D7%95%D7%AA http://he.wikipedia.org/wiki/%D7%97%D7%99%D7%93%D7%AA_%D7%A9%D7%9E% D7%95%D7%A0%D7%94_%D7%94%D7%9E%D7%9C%D7%9B%D7%95%D7%AA 56 a)b)
57
חיפוש לוקאלי אל תחפש כל מצב – רק תנסה " תיקון " מקומי יתרונות אין צורך בהרבה זיכרון אפשר למצוא פתרונות במרחבי חיפוש גדולים 57
58
Hill-climbing search 58
59
Hill-climbing example 8-queens problem (complete-state formulation) Successor function: move a single queen to another square in the same column Heuristic function h(n): the number of pairs of queens that are attacking each other (directly or indirectly, i.e., “through” another queen) 59
60
Example: n-queens Put n queens on an n × n board with no two queens on the same row, column, or diagonal Move a queen to reduce the number of conflicts 60
61
Hill-climbing example a) shows a state of h=17 and the h-value for each possible successor b) A local minimum in the 8-queens state space (h=1) 61 a)b)
62
Drawbacks Ridge = sequence of local maxima difficult for greedy algorithms to navigate Plateau = an area of the state space where the evaluation function is flat Gets stuck 86% of the time in the 8-queens problem 62
63
פתרון אחד : Backtracking תחזור חזרה למלכה האחרונה – ותזיז אותה ! קוד שלי באתר http://www.hbmeyer.de/backtrack/achtdamen/eight.h tm http://www.hbmeyer.de/backtrack/achtdamen/eight.h tm 63
64
Hill Climbing Variations Random-restart hill-climbing Tries to avoid getting stuck in local maxima Conducts a series of hill-climbing searches from randomly generated initial states Stops each search at a local maxima – or better yet, stops after a fixed amount of time For the 3,000,000-queens problem, solutions found in under a minute The success (or failure) of hill-climbing can very much depend on the shape of the state- space landscape 64
65
Simulated annealing Escape local maxima by allowing “bad” moves Idea: but gradually decrease their size and frequency Origin; metallurgical annealing Bouncing ball analogy: Shaking hard (= high temperature) Shaking less (= lower the temperature) If T decreases slowly enough, best state is reached Applied for VLSI layout, airline scheduling, etc. 65
66
Simulated annealing search Idea (again): escape local maxima by allowing some “bad” moves but gradually decrease their size and frequency 66
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.