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

חיפוש PowerPoint PPT Presentation


  • 102 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


2845180

חיפוש

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

אבי רוזנפלד


2845180

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

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

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


2845180

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

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

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

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

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

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


State space

State Space

1. initial state

2. successor function


Goal test

Goal Test

3. goal test


2845180

מפת רומניה


Example 8 puzzle

Example: 8-Puzzle


Partial search space for 8 puzzle problem

(Partial) Search Space for 8-Puzzle Problem

1. initial state

2. successor function

3. goal test


Example route planning in a map

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.


2845180

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

  • BFS

  • DFS

  • Best-first search

  • A* search

    • Heuristics

  • Local search algorithms

    • Hill-climbing search

    • Backtracking

    • Simulated annealing


2845180

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


Breadth first search

Breadth-First Search

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

  • CLASSIC FIFO! (Queue!)

  • אופטימאלי


Depth first search

Depth-First Search

Alternatively can use a recursive implementation.

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


Breadth first search1

O

S

F

Z

A

R

B

P

D

M

T

L

C

Breadth-First Search


Breadth first search2

O

S

F

Z

A

R

B

P

D

M

T

L

C

Breadth-First Search

A


Breadth first search3

O

S

F

Z

A

R

B

P

D

M

T

L

C

Breadth-First Search

A

ZA SA TA


Breadth first search4

O

S

F

Z

A

R

B

P

D

M

T

L

C

Breadth-First Search

A

ZA SA TA

SA TA OAZ


Breadth first search5

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


Breadth first search6

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


Breadth first search7

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


Breadth first search8

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


Breadth first search9

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


Breadth first search10

O

S

F

Z

A

R

P

D

M

T

L

C

Breadth-First Search

B


Evaluation of search strategies

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

Evaluation of BFS

  • Complete

  • Complexity:

    • O(bd) time

    • O(bd) space

  • Optimal (counting by number of arcs).


Depth first search1

O

S

F

Z

A

R

B

P

D

M

T

L

C

Depth-First Search


Depth first search2

O

S

F

Z

A

R

B

P

D

M

T

L

C

Depth-First Search

A


Depth first search3

O

S

F

Z

A

R

B

P

D

M

T

L

C

Depth-First Search

A

ZA SA TA


Depth first search4

O

S

F

Z

A

R

B

P

D

M

T

L

C

Depth-First Search

A

ZA SA TA


Depth first search5

O

S

F

Z

A

R

B

P

D

M

T

L

C

Depth-First Search

A

ZA SA TA

OAZ SA TA


Depth first search6

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


Depth first search7

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


Depth first search8

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


Depth first search9

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


Depth first search10

S

F

Z

A

R

B

P

D

M

T

L

C

Depth-first Search

O


Evaluation of dfs

Evaluation of DFS

  • Not complete

  • Complexity:

    • O(bm) time

    • O(mb) space

  • Non-optimal


Bi directional search

Bi-Directional Search


Romania with step costs in km

Romania with step costs in km


Greedy best first search example

Greedy best-first search example


Greedy best first search example1

Greedy best-first search example


Greedy best first search example2

Greedy best-first search example


Greedy best first search example3

Greedy best-first search example


Romania with step costs in km1

Romania with step costs in km

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


Properties of greedy best first search

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


2845180

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 example1

A* search example


A search example2

A* search example


A search example3

A* search example


A search example4

A* search example


A search example5

A* search example


Romania with step costs in km2

Romania with step costs in km


Heuristic functions

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 functions1

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

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


2845180

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

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


2845180

חיפוש לוקאלי

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

  • יתרונות

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

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


Hill climbing search

Hill-climbing search


Hill climbing example

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

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 example1

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

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

פתרון אחד:Backtracking

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

  • קוד שלי באתר

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


Hill climbing variations

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

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

Simulated annealing search

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


  • Login