44
ששששש שששש שששששששש ששש ששששששש

חיפוש

Embed Size (px)

DESCRIPTION

חיפוש. בינה מלאכותית אבי רוזנפלד. סוגי חיפוש כלליים. UNINFORMED SEARCH -- חיפושים לא מיודעים במרחי מצבים BFS DFS INFORMED SEARCH – חיפושים מיודעים Dijkstra GREEDY A * http :// en.wikipedia.org/wiki/Dijkstra's_algorithm HILLCLIMBING. חיפוש נגד יריב (משחקים). - PowerPoint PPT Presentation

Citation preview

Page 1: חיפוש

חיפוש

מלאכותית בינהרוזנפלד אבי

Page 2: חיפוש

סוגי חיפוש כלליים

•UNINFORMED SEARCH חיפושים לא מיודעים -- במרחי מצבים

–BFS–DFS

•INFORMED SEARCHחיפושים מיודעים – –Dijkstra–GREEDY–A*–http://en.wikipedia.org/wiki/Dijkstra's_algorithm–HILLCLIMBING

Page 3: חיפוש

חיפוש נגד יריב )משחקים(

איזה מידע יש בתוך המודל )עץ(•איך היריב משחק?•

אופטימאלי / לא אופטימאלי–איך אפשר להוריד את מרחב החיפוש•

–Alpha / Beta Pruning)גיזום של העץ( (Evaluation functionיצירת החישוב )––The Horizon Effect

Page 4: חיפוש

4

סוגי משחקים

Page 5: חיפוש

5

Game tree (2-player, deterministic, turns)

Page 6: חיפוש

Minimax

• Create a utility function– Evaluation of board/game state to determine how

strong the position of player 1 is.– Player 1 wants to maximize the utility function– Player 2 wants to minimize the utility function

• Minimax tree– Generate a new level for each move– Levels alternate between “max” (player 1 moves)

and “min” (player 2 moves)

Page 7: חיפוש

Minimax עץ הMax

Min

Max

Min

Page 8: חיפוש

Minimax Tree Evaluation

)לא הנחה פשוטה(UTILITYהנחה: יש פונקציה •כל צד רוצה למקסם את הצד שלו•יש מספיק מידע בתוך העץ לעשות את •

החישובים

Page 9: חיפוש

(Minimaxעץ של המשחק )Max

Min

Max

Min

100

-24-8-14-73-100-5-70-12-470412-3212823

Page 10: חיפוש

(Minimaxעץ של המשחק )Max

Min

Max

Min

100

-24-8-14-73-100-5-70-12-470412-3212823

28 -3 12 70 -4 -73 -14 -8

Page 11: חיפוש

(Minimaxעץ של המשחק )Max

Min

Max

Min

100

-24-8-14-73-100-5-70-12-470412-3212823

21 -3 12 70 -4 -73 -14 -8

-3 -4 -73

Page 12: חיפוש

(Minimaxעץ של המשחק )Max

Min

Max

Min

100

-24-8-14-73-100-5-70-12-470412-3212823

21 -3 12 70 -4 -73 -14 -8

-3 -4 -73

-3

Page 13: חיפוש

Minimax Evaluation

• Given average branching factor b, and depth m:– A complete evaluation takes time bm

– A complete evaluation takes space bm• Usually, we cannot evaluate the complete

state, since it’s too big• Instead, we limit the depth based on various

factors, including time available.

Page 14: חיפוש

14

Minimaxעוד דוגמא של

Page 15: חיפוש

α-βגיזום של

אני יודע שאתה יודע שאני יודע...•שווה להוריד אופציות כדי שאפשר לחפש יותר•הפתרון: גיזום•

כל צד מוריד דבר שהוא בטוח שהצד השני –

Page 16: חיפוש

וαהצד של

קטן, אם הערך הנוכחי MAX : )שמחפשים (α ל•(PRUNEמערך בענף אחר, תוריד את הענף )

גדול , אם הערך הנוכחי MIN, )שמחפשים (βל •(PRUNEמערך בענף אחר, תוריד את הענף )

Page 17: חיפוש

17

α-β pruning example

Page 18: חיפוש

18

α-β pruning example

Page 19: חיפוש

19

α-β pruning example

Page 20: חיפוש

20

α-β pruning example

Page 21: חיפוש

21

α-β pruning example

Page 22: חיפוש

a Cut example

10021 -3 12 70 -4 -73 -14

-3 -4

-3

-73

Max

Max

Min

Page 23: חיפוש

a Cut example

• Depth first search along path 1

10021 -3 12 -70 -4 -73 -14

Max

Max

Min

Page 24: חיפוש

a Cut example

• 21 is minimum so far (second level)• Can’t evaluate yet at top level

10021 -3 12 -70 -4 -73 -14

Max

Max

Min 21

Page 25: חיפוש

a Cut example

• -3 is minimum so far (second level)• -3 is maximum so far (top level)

10021 -3 12 -70 -4 -73 -14

Max

Max

Min -3

-3

Page 26: חיפוש

a Cut example

• 12 is minimum so far (second level)• -3 is still maximum (can’t use second node yet)

10021 -3 12 -70 -4 -73 -14

Max

Max

Min -3

-3

12

Page 27: חיפוש

a Cut example

• -70 is now minimum so far (second level)• -3 is still maximum (can’t use second node yet)

10021 -3 12 -70 -4 -73 -14

Max

Max

Min -3

-3

-70

Page 28: חיפוש

a Cut example

• Since second level node will never be > -70, it will never be chosen by the previous level

• We can stop exploring that node

10021 -3 12 -70 -4 -73 -14

Max

Max

Min -3

-3

-70

Page 29: חיפוש

a Cut example

• Evaluation at second level is -73

10021 -3 12 -70 -4 -73 -14

Max

Max

Min -3

-3

-70 -73

Page 30: חיפוש

a Cut example

• Again, can apply a cut since the second level node will never be > -73, and thus will never be chosen by the previous level

10021 -3 12 -70 -4 -73 -14

Max

Max

Min -3

-3

-70 -73

Page 31: חיפוש

a Cut example

• As a result, we evaluated the Max node without evaluating several of the possible paths

10021 -3 12 -70 -4 -73 -14

Max

Max

Min -3

-3

-70 -73

Page 32: חיפוש

b cuts

• Similar idea to a cuts, but the other way around

• If the current minimum is less than the successor’s max value, don’t look down that max tree any more

Page 33: חיפוש

b Cut example

• Some subtrees at second level already have values > min from previous, so we can stop evaluating them.

10021 -3 12 70 -4 73 -14

Min

Min

Max 21

21

70 73

Page 34: חיפוש

למהa-b Pruningעובד

יותר טובMAX, 70לצד של • ייקח אותו MIN, אין מצב שאבל•

.21במקום 100

21 -3

12 70 -4

21

21

70

Page 35: חיפוש

a-b Pruningהיתרון ל

MINIMAXאין השפעה על תוצאת •כן עוזר לרדת יותר עמוק בתוך העץ–

מאוד תלוי ב"מזל" בסידור של העץ•במצב הכי טוב, הוא מכפיל הגודל שאפשר לחפש –

בו

Page 36: חיפוש

!?איך בונים את העצים

מאוד תלוי במשחק•יש צורך לראות את ה-כ-ל עד סוף המשחק )!(•- אם אתה 1 אם אני מנצח, 1ברמה הפשוטה: •

במצב תיקו.0מנצח, ברוב המשחקים יש ה-ר-ב-ה מצבים באמצע•

שמחט–דמקה–רצף ארבע )!(–

Page 37: חיפוש

למשחקUTILITYבניית פונקציות

לכל מצב יש ציון• וכו'3, אביר שווה 10בשחמט מלכה שווה •בהרבה מקרים, הערכים הסתברותיים.•

–utility = aa + bb + cc

Page 38: חיפוש

• For chess, typically linear weighted sum of featuresEval(s) = w1 f1(s) + w2 f2(s) + … + wn fn(s)

• e.g., w1 = 9 with

• f1(s) = (number of white queens) – (number of black queens), etc.

38

Utility Function

Page 39: חיפוש

לא ניתן לראות קדימה עד סוף המשחק )אין סוף(•(Cut Offבונים עוץ בגודל מסויים )• בשחמט למחשב Cut Off, הALPHA BETAבלי גיזום •

4נורמאלי הוא "רק" גובה של שזה שווה לבנאדם רגיל–

!8, זה מגיע לALPHA BETAאם •.12 עבדו עד לגובה של Deep Blue וKasparovאבל •

39

הגבלות בפועל

Page 40: חיפוש

הערכים לא משפעים על איזה פעולה לעשות!•

40

בהרבה מקרים גם הערכה היא "מספיק "טובה

Page 41: חיפוש

• Checkers: Chinook ended 40-year-reign of human world champion Marion Tinsley in 1994. Used a precomputed endgame database defining perfect play for all positions involving 8 or fewer pieces on the board, a total of 443,748,401,247 positions.

• A precomputed endgame database? Would it be possible to extend the “endgame” all the way back to the beginning of the game, essentially “solving” checkers?

41

Deterministic games in practice

Page 42: חיפוש

Originally published in Science Express on 19 July 2007Science 14 September 2007:Vol. 317, no. 5844, pp. 1518 – 1522Jonathan Schaeffer (University of Alberta), Neil Burch, Yngvi Björnsson, Akihiro

Kishimoto, Martin Müller, Robert Lake, Paul Lu, Steve SutphenThe game of checkers has roughly 500 billion billion possible positions (5 x 1020). The

task of solving the game, determining the final result in a game with no mistakes made by either player, is daunting. Since 1989, almost continuously, dozens of computers have been working on solving checkers, applying state-of-the-art artificial intelligence techniques to the proving process. This paper announces that checkers is now solved: Perfect play by both sides leads to a draw. This is the most challenging popular game to be solved to date, roughly one million times as complex as Connect Four. Artificial intelligence technology has been used to generate strong heuristic-based game-playing programs, such as Deep Blue for chess. Solving a game takes this to the next level by replacing the heuristics with perfection.

42

Checkers is Solved

Page 43: חיפוש

• Chess: Deep Blue defeated human world champion Garry Kasparov in a six-game match in 1997. Deep Blue searches 200 million positions per second, uses very sophisticated evaluation, and undisclosed methods for extending some lines of search up to 40 ply. Rybka was the 2008 and 2009 computer chess champion (uses an off-the-shelf 8-core 3.2GHz Intel Xeon processor), but was stripped of its titles for having plagiarized two other programs…

• Othello: Logistello beats human world champion in 1997; human champions refuse to compete against computers, who are too good

• Go: human champions refuse to compete against computers, who are too bad. In go, b > 300, so most programs use pattern knowledge bases to suggest plausible moves.

43

Deterministic games in practice

Page 44: חיפוש

משחקים הם לא משחק ילדים לאנשי מערכות •מידע...

איך הסוכן שלכם יעבוד!!!•

44

סיכום