חיפוש
This presentation is the property of its rightful owner.
Sponsored Links
1 / 66

חיפוש PowerPoint PPT Presentation


  • 111 Views
  • Uploaded on
  • Presentation posted in: General

חיפוש. בינה מלאכותית אבי רוזנפלד. סוכנים פותרי בעיות. Reflex agents לא יכולים לתכנן קדימה כדי לחפש, יש צורך לייצר מודל לחפש בו!. להגדרת אלגוריתם חיפוש. סוכן צריך לדחות פעולות שלא מקדמות למטרה Goal formulation - נוסחת מטרה המבוססת על מדד הביצועים הנוכחיים של הסוכן ועל המצב הנוכחי

Download Presentation

חיפוש

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


חיפוש

בינה מלאכותית

אבי רוזנפלד


סוכנים פותרי בעיות

  • Reflex agents לא יכולים לתכנן קדימה

  • כדי לחפש, יש צורך לייצר מודל לחפש בו!


להגדרת אלגוריתם חיפוש

  • סוכן צריך לדחות פעולות שלא מקדמות למטרה

  • Goal formulation - נוסחת מטרה המבוססת על מדד הביצועים הנוכחיים של הסוכן ועל המצב הנוכחי

  • מטרה – אוסף של מצבים בעולם שצריכים להתקיים אם המטרה הושגה.

  • מטרת הסוכן היא למצוא את רצף הפעולות שיביא אותו לאוסף הזה של מצבים

  • קודם לכן, עליו להחליט אילו פעולות ואילו מצבים הם רלוונטיים.


State Space

1. initial state

2. successor function


Goal Test

3. goal test


מפת רומניה


Example: 8-Puzzle


(Partial) Search Space for 8-Puzzle Problem

1. initial state

2. successor function

3. goal test


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.


על מה לומדים היום?

  • BFS

  • DFS

  • Best-first search

  • A* search

    • Heuristics

  • Local search algorithms

    • Hill-climbing search

    • Backtracking

    • Simulated annealing


איך מבצעים את החיפוש?


Breadth-First Search

  • Breadth-first search tree after 0,1,2 and 3 node expansions

  • CLASSIC FIFO! (Queue!)

  • אופטימאלי


Depth-First Search

Alternatively can use a recursive implementation.

  • לא אופטימאלי!


O

S

F

Z

A

R

B

P

D

M

T

L

C

Breadth-First Search


O

S

F

Z

A

R

B

P

D

M

T

L

C

Breadth-First Search

A


O

S

F

Z

A

R

B

P

D

M

T

L

C

Breadth-First Search

A

ZA SA TA


O

S

F

Z

A

R

B

P

D

M

T

L

C

Breadth-First Search

A

ZA SA TA

SA TA OAZ


O

S

F

Z

A

R

B

P

D

M

T

L

C

Breadth-First Search

A

ZA SA TA

SA TA OAZ

TA OAZ OAS FAS RAS


O

S

F

Z

A

R

B

P

D

M

T

L

C

Breadth-First Search

A

ZA SA TA

SA TA OAZ

TA OAZ OAS FAS RAS

OAZ OAS FAS RAS LAT


O

S

F

Z

A

R

B

P

D

M

T

L

C

Breadth-First Search

A

ZA SA TA

SA TA OAZ

TA OAZ OAS FAS RAS

OAZ OAS FAS RAS LAT

OAS FAS RAS LAT


O

S

F

Z

A

R

B

P

D

M

T

L

C

Breadth-First Search

A

ZA SA TA

SA TA OAZ

TA OAZ OAS FAS RAS

OAZ OAS FAS RAS LAT

OAS FAS RAS LAT


O

S

F

Z

A

R

B

P

D

M

T

L

C

Breadth-First Search

A

ZA SA TA

SA TA OAZ

TA OAZ OAS FAS RAS

OAZ OAS FAS RAS LAT

OAS FAS RAS LAT

RAS LAT BASF

Result = BASF


O

S

F

Z

A

R

P

D

M

T

L

C

Breadth-First Search

B


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


Evaluation of BFS

  • Complete

  • Complexity:

    • O(bd) time

    • O(bd) space

  • Optimal (counting by number of arcs).


O

S

F

Z

A

R

B

P

D

M

T

L

C

Depth-First Search


O

S

F

Z

A

R

B

P

D

M

T

L

C

Depth-First Search

A


O

S

F

Z

A

R

B

P

D

M

T

L

C

Depth-First Search

A

ZA SA TA


O

S

F

Z

A

R

B

P

D

M

T

L

C

Depth-First Search

A

ZA SA TA


O

S

F

Z

A

R

B

P

D

M

T

L

C

Depth-First Search

A

ZA SA TA

OAZ SA TA


O

S

F

Z

A

R

B

P

D

M

T

L

C

Depth-First Search

A

ZA SA TA

OAZ SA TA

SAZO SA TA


O

S

F

Z

A

R

B

P

D

M

T

L

C

Depth-First Search

A

ZA SA TA

OAZ SA TA

SAZO SA TA

FAZOS RAZOS SA TA


O

S

F

Z

A

R

B

P

D

M

T

L

C

Depth-First Search

A

ZA SA TA

OAZ SA TA

SAZO SA TA

FAZOS RAZOS SA TA

BAZOSF RAZOS SA TA


O

S

F

Z

A

R

B

P

D

M

T

L

C

Depth-First Search

A

ZA SA TA

OAZ SA TA

SAZO SA TA

FAZOS RAZOS SA TA

BAZOSF RAZOS SA TA

Result = BAZOSF


S

F

Z

A

R

B

P

D

M

T

L

C

Depth-first Search

O


Evaluation of DFS

  • Not complete

  • Complexity:

    • O(bm) time

    • O(mb) space

  • Non-optimal


Bi-Directional Search


Romania with step costs in km


Greedy best-first search example


Greedy best-first search example


Greedy best-first search example


Greedy best-first search example


Romania with step costs in km

המחיר הכולל: 450. האם זה אופטימאלי? לא!


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(bm), but a good heuristic can give dramatic improvement

  • Space?O(bm) – keeps all nodes in memory

  • Optimal?No

b is branching factor, m is maximum depth of the search space


A*חיפוש

  • הרעיון המרכזי: קח בחשבון את המחיר הכללי (עד עכשיו)

  • 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 goalA* search uses an admissableheuristic:

    • 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


A* search example


A* search example


A* search example


A* search example


A* search example


A* search example


Romania with step costs in km


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 1010 states

    • A good heuristic function can reduce the search


Heuristic functions

  • For the 8-puzzle, two commonly used heuristics

  • h1 = the number of misplaced tiles

    • h1(s)=8

  • h2 = the sum of the distances of the tiles from their goal positions (manhattan distance)

    • h2(s)=3+1+2+2+2+3+3+2=18


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


בעיית המלכות השחמט

a)

b)

  • יש ל 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


חיפוש לוקאלי

  • אל תחפש כל מצב– רק תנסה "תיקון" מקומי

  • יתרונות

    • אין צורך בהרבה זיכרון

    • אפשר למצוא פתרונות במרחבי חיפוש גדולים


Hill-climbing search


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)


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


Hill-climbing example

a)

b)

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)


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


פתרון אחד:Backtracking

  • תחזור חזרה למלכה האחרונה – ותזיז אותה!

  • קוד שלי באתר

  • http://www.hbmeyer.de/backtrack/achtdamen/eight.htm


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


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.


Simulated annealing search

  • Idea (again): escape local maxima by allowing some “bad” moves but gradually decrease their size and frequency


  • Login