Cs b551 elements of artificial intelligence
This presentation is the property of its rightful owner.
Sponsored Links
1 / 63

CS B551 : Elements of Artificial Intelligence PowerPoint PPT Presentation


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

CS B551 : Elements of Artificial Intelligence. Instructor: Kris Hauser http://cs.indiana.edu/~hauserk. Agenda. Searching, data structures, and algorithms Breadth-first search Depth-first search Uniform-cost search. Defining a Search Problem. S. State space S

Download Presentation

CS B551 : Elements of Artificial Intelligence

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


Cs b551 elements of artificial intelligence

CS B551: Elements of Artificial Intelligence

Instructor: Kris Hauser

http://cs.indiana.edu/~hauserk


Agenda

Agenda

  • Searching, data structures, and algorithms

  • Breadth-first search

  • Depth-first search

  • Uniform-cost search


Defining a search problem

Defining a Search Problem

S

  • State space S

  • Successor function: x  S  SUCC(x)  2S

  • Initial state s0

  • Goal test:

    xS GOAL?(x) =T or F

  • Arc cost


State graph

State Graph

  • Each state is represented by a distinct node

  • An arc (or edge) connects a node s to a node s’ if s’ SUCC(s)

  • The state graph may contain more than one connected component


Solution to the search problem

I

Solution to the Search Problem

  • A solution is a path connecting the initial node to a goal node (any one)

  • The cost of a path is the sum of the arc costs along this path

  • An optimal solution is a solution path of minimum cost

  • There might be no solution !

G


Search graph state graph

8

8

2

2

8

2

7

3

3

4

4

7

7

3

4

5

5

1

1

6

6

5

1

6

8

2

3

4

7

8

2

8

4

2

3

4

7

3

7

5

1

6

5

1

6

5

1

6

Search Graph!= State Graph

If states are allowed to be revisited,the search tree may be infinite even

when the state space is finite


Search graph node state

8

2

PARENT-NODE

3

4

7

BOOKKEEPING

5

1

6

STATE

CHILDREN

Action

Right

Depth

5

...

Path-Cost

5

yes

Expanded

Search Graph Node != State

Depth of a node N = length of path from root to N

(depth of the root = 0)


Fringe of search tree

8

2

8

2

7

3

4

7

3

4

5

1

6

5

1

6

Fringe of Search Tree

  • The fringe is the set of all search nodes that haven’t been expanded yet

8

2

3

4

7

5

1

6

8

2

7

3

4

5

1

6

8

2

8

2

3

4

7

3

4

7

5

1

6

5

1

6


Search strategy

Search Strategy

  • The fringe is the set of all search nodes that haven’t been expanded yet

  • The fringe is implemented as a priority queue FRINGE

    • INSERT(node,FRINGE)

    • REMOVE(FRINGE)

  • The ordering of the nodes in FRINGE defines the search strategy


Search algorithm 1

Search Algorithm #1

SEARCH#1

1. If GOAL?(initial-state) then return initial-state

2. INSERT(initial-node,FRINGE)

3.Repeat:

4.If empty(FRINGE) then return failure

5.N REMOVE(FRINGE)

6.s  STATE(N)

7.For every state s’ in SUCCESSORS(s)

8.Create a new node N’ as a child of N

9.If GOAL?(s’) then return path or goal state

10.INSERT(N’,FRINGE)

Expansion of N


Blind search strategies

Blind Search Strategies


Blind strategies

Arc cost = 1

Arc cost

= c(action) 0

Blind Strategies

  • Breadth-first

    • Bidirectional

  • Depth-first

    • Depth-limited

    • Iterative deepening

  • Uniform-Cost(variant of breadth-first)


Breadth first strategy

1

2

3

4

5

6

7

Breadth-First Strategy

  • New nodes are inserted at the end of FRINGE

FRINGE = (1)


Breadth first strategy1

1

2

3

4

5

6

7

Breadth-First Strategy

  • New nodes are inserted at the end of FRINGE

FRINGE = (2, 3)


Breadth first strategy2

1

2

3

4

5

6

7

Breadth-First Strategy

  • New nodes are inserted at the end of FRINGE

FRINGE = (3, 4, 5)


Breadth first strategy3

1

2

3

4

5

6

7

Breadth-First Strategy

  • New nodes are inserted at the end of FRINGE

FRINGE = (4, 5, 6, 7)


Performance measures

Performance Measures

  • CompletenessA search algorithm is complete if it finds a solution whenever one exists[What about the case when no solution exists?]

  • OptimalityA search algorithm is optimal if it returns a minimum-cost path whenever a solution exists

  • ComplexityIt measures the time and amount of memory required by the algorithm


Important parameters

Important Parameters

  • Maximum number of successors of any state branching factor b of the search tree

  • Minimal length (≠ cost) of a path between the initial and a goal state depth d of the shallowest goal node in the search tree


Evaluation

Evaluation

  • b: branching factor

  • d: depth of shallowest goal node

  • Breadth-first search is:

    • Complete? Not complete?

    • Optimal? Not optimal?


Evaluation1

Evaluation

  • b: branching factor

  • d: depth of shallowest goal node

  • Breadth-first search is:

    • Complete

    • Optimal if step cost is 1

  • Number of nodes generated:???


Evaluation2

Evaluation

  • b: branching factor

  • d: depth of shallowest goal node

  • Breadth-first search is:

    • Complete

    • Optimal if step cost is 1

  • Number of nodes generated: 1 + b + b2 + … + bd= ???


Evaluation3

Evaluation

  • b: branching factor

  • d: depth of shallowest goal node

  • Breadth-first search is:

    • Complete

    • Optimal if step cost is 1

  • Number of nodes generated: 1 + b + b2+ … + bd = (bd+1-1)/(b-1) = O(bd)

  •  Time and space complexity is O(bd)


Time and memory requirements

Time and Memory Requirements

Assumptions: b = 10; 1,000,000 nodes/sec; 100bytes/node


Time and memory requirements1

Time and Memory Requirements

Assumptions: b = 10; 1,000,000 nodes/sec; 100bytes/node


Remark

1

1

2

2

3

3

4

4

5

5

6

6

7

7

8

8

9

9

10

10

11

11

12

12

?

13

13

14

15

15

14

Remark

  • If a problem has no solution, breadth-first may run forever (if the state space is infinite or states can be revisited arbitrary many times)


Bidirectional strategy

s

Bidirectional Strategy

2 fringe queues: FRINGE1 and FRINGE2

Time and space complexity isO(bd/2)  O(bd) if both trees have the same branching factor b

Question: What happens if the branching factor is different in each direction?


Depth first strategy

2

3

FRINGE = (1)

4

5

Depth-First Strategy

  • New nodes are inserted at the front of FRINGE

1


Depth first strategy1

2

3

FRINGE = (2, 3)

4

5

Depth-First Strategy

  • New nodes are inserted at the front of FRINGE

1


Depth first strategy2

2

3

FRINGE = (4, 5, 3)

4

5

Depth-First Strategy

  • New nodes are inserted at the front of FRINGE

1


Depth first strategy3

2

3

4

5

Depth-First Strategy

  • New nodes are inserted at the front of FRINGE

1


Depth first strategy4

2

3

4

5

Depth-First Strategy

  • New nodes are inserted at the front of FRINGE

1


Depth first strategy5

2

3

4

5

Depth-First Strategy

  • New nodes are inserted at the front of FRINGE

1


Depth first strategy6

2

3

4

5

Depth-First Strategy

  • New nodes are inserted at the front of FRINGE

1


Depth first strategy7

2

3

4

5

Depth-First Strategy

  • New nodes are inserted at the front of FRINGE

1


Depth first strategy8

2

3

4

5

Depth-First Strategy

  • New nodes are inserted at the front of FRINGE

1


Depth first strategy9

2

3

4

5

Depth-First Strategy

  • New nodes are inserted at the front of FRINGE

1


Depth first strategy10

2

3

4

5

Depth-First Strategy

  • New nodes are inserted at the front of FRINGE

1


Evaluation4

Evaluation

  • b: branching factor

  • d: depth of shallowest goal node

  • m: maximal depth of a leaf node

  • Depth-first search is:

    • Complete?

    • Optimal?


Evaluation5

Evaluation

  • b: branching factor

  • d: depth of shallowest goal node

  • m: maximal depth of a leaf node

  • Depth-first search is:

    • Complete only for finite search tree

    • Not optimal

  • Number of nodes generated (worst case): 1 + b + b2+ … + bm = O(bm)

  • Time complexity is O(bm)

  • Space complexity is O(bm) [or O(m)]

  • [Reminder: Breadth-first requires O(bd) time and space]


Depth limited search

Depth-Limited Search

  • Depth-first with depth cutoff k (depth at which nodes are not expanded)

  • Three possible outcomes:

    • Solution

    • Failure (no solution)

    • Cutoff (no solution within cutoff)


Iterative deepening search

Iterative Deepening Search

  • Provides the best of both breadth-first and depth-first search

  • Main idea:

Totally horrifying !

IDS

For k = 0, 1, 2, … do:

Perform depth-first search with depth cutoff k

(i.e., only generate nodes with depth  k)


Iterative deepening

Iterative Deepening


Iterative deepening1

Iterative Deepening


Iterative deepening2

Iterative Deepening


Performance

Performance

  • Iterative deepening search is:

    • Complete

    • Optimal if step cost =1

  • Time complexity is: (d+1)(1) + db + (d-1)b2 + … + (1) bd= O(bd)

  • Space complexity is: O(bd) or O(d)


Calculation

Calculation

db + (d-1)b2 + … + (1) bd

=bd+2bd-1 +3bd-2 +… +db

= (1 + 2b-1 + 3b-2 + … + db-d)bd

 (Si=1,…,ib(1-i))bd = bd(b/(b-1))2


Number of generated nodes breadth first iterative deepening

Number of Generated Nodes (Breadth-First & Iterative Deepening)

  • d = 5 and b = 2

120/63 ~ 2


Number of generated nodes breadth first iterative deepening1

Number of Generated Nodes (Breadth-First & Iterative Deepening)

  • d = 5 and b = 10

123,456/111,111 ~ 1.111


Recap

Recap

  • BFS: Complete, optimal

    • O(bd) time and space

  • DFS: Not complete nor optimal

    • O(bd) space, unbounded time

  • ID: Complete, optimal

    • O(bd) space, O(bd) time


Related topics

Related Topics

  • Non-unit costs

  • Revisited states

  • Heuristic search


Non unit costs

Why?

Non-unit Costs

  • Each arc has cost c  > 0

  • The cost of the path to each node N is g(N) =  costs of arcs

  • Breadth-first is no longer optimal


Uniform cost search

A

S

1

10

0

S

B

G

5

5

A

B

C

5

1

5

15

C

15

G

G

10

11

Suboptimal path!

Uniform-Cost Search

  • Expand node in FRINGE with the cheapest path


Search algorithm 2

Search Algorithm #2

The goal test is applied

to a node when this node is

expanded, not when it is

generated.

SEARCH#2

1. If GOAL?(initial-state) then return initial-state

2. INSERT(initial-node,FRINGE)

3.Repeat:

4.If empty(FRINGE) then return failure

5.N REMOVE(FRINGE)

6.s  STATE(N)

7.If GOAL?(s) then return path or goal state

8.For every state s’ in SUCCESSORS(s)

9.Create a new node N’ as a child of N

10.INSERT(N’,FRINGE)


Revisited states

No

Few

Many

search tree is infinite

search tree is finite

1

2

3

4

5

assembly planning

7

8

6

8-queens

8-puzzle and robot navigation

Revisited States


Avoiding revisited states

Avoiding Revisited States

  • Requires comparing state descriptions

  • Breadth-first search:

    • Store all states associated with generated nodes in VISITED

    • If the state of a new node is in VISITED, then discard the node


Avoiding revisited states1

Avoiding Revisited States

  • Requires comparing state descriptions

  • Breadth-first search:

    • Store all states associated with generated nodes in VISITED

    • If the state of a new node is in VISITED, then discard the node

Implemented as hash-table

or as explicit data structure with flags


Explicit data structures

Explicit Data Structures

  • Robot navigation

  • VISITED: array initialized to 0, matching grid

  • When grid position (x,y) is visited, mark corresponding position in VISITED as 1

  • Size of the entire state space!


Hash tables

8

2

3

4

7

5

1

6

1

2

3

4

5

7

8

6

Hash Tables

VISITED: Hash table of size N

0

1

2

N-1

Hash function: map from S to {0,…,N-1}

If hash function is chosen carefully to minimize chance of collision, then membership testing on M states averages O(M/N) time


Avoiding revisited states2

Avoiding Revisited States

  • Depth-first search:

    • Solution 1:

      • Store all states associated with nodes in current path in VISITED

      • If the state of a new node is in VISITED, then discard the node

    • ??


Avoiding revisited states3

Avoiding Revisited States

  • Depth-first search:

    • Solution 1:

      • Store all states associated with nodes in current path in VISITED

      • If the state of a new node is in VISITED, then discard the node

    • Only avoids loops

    • Solution 2:

      • Store all generated states in VISITED

      • If the state of a new node is in VISITED, then discard the node

    • Same space complexity as breadth-first !


Avoiding revisited states in uniform cost search

Avoiding Revisited States in Uniform-Cost Search

  • For any state S, when the first node N such that STATE(N) = S is expanded, the path to N is the best path from the initial state to S

  • So:

    • When a node is expanded, store its state into VISITED

    • When a new node N is generated:

      • If STATE(N) is in VISITED, discard N

      • If there exits a node N’ in the fringe such that STATE(N’) = STATE(N), discard the node -- N or N’ -- with the highest-cost path


Search algorithm 3

Search Algorithm #3

SEARCH#3

1. If GOAL?(initial-state) then return initial-state

2. INSERT(initial-node,FRINGE)

3.Repeat:

4.If empty(FRINGE) then return failure

5.N REMOVE(FRINGE)

6.s  STATE(N)

7.Add s to VISITED

7.If GOAL?(s) then return path or goal state

8.For every state s’ in SUCCESSORS(s)

9.Create a new node N’ as a child of N

10.If s’ is in VISITED then discard N’

11.If there is N’’ in FRINGE with STATE(N’)=STATE(N’’)

12. If g(N’’) is lower than g(N’) then discard N’

13.Otherwise discard N’’

14.INSERT(N’,FRINGE)


Homework

Homework

  • Readings: R&N Ch. 3.5


  • Login