Lecture 3: reflex-based, model-based, goal-based, utility-based, - - PowerPoint PPT Presentation

lecture 3
SMART_READER_LITE
LIVE PREVIEW

Lecture 3: reflex-based, model-based, goal-based, utility-based, - - PowerPoint PPT Presentation

CS440/ECE448: Intro to Artificial Intelligence Review Different kinds of agents: Lecture 3: reflex-based, model-based, goal-based, utility-based, learning-based Systematic search How do we evaluate agents? External


slide-1
SLIDE 1

Lecture 3:
 Systematic search

  • Prof. Julia Hockenmaier

juliahmr@illinois.edu

  • http://cs.illinois.edu/fa11/cs440
  • CS440/ECE448: Intro to Artificial Intelligence

Review

Different kinds of agents: reflex-based, model-based, goal-based, utility-based, learning-based

  • How do we evaluate agents?

External performance measure


  • What is the task environment like:
  • bservable?, known?, deterministic?

sequential?, static?

When is an agent rational?

Answer 1: When an agent chooses actions that bring it closer to the goal.

  • Answer 2: When an agent chooses actions

that it expects to bring it closer to the goal

  • Answer 2 is correct.
  • 3

CS440/ECE448: Intro AI

Problem solving
 as search

slide-2
SLIDE 2

Problem solving as search

Problem solving

– Finding any solution (goal-driven) – Finding the cheapest solution (utility-driven)

  • Uninformed (blind) search (goal-driven):

– Algorithms: breadth-first; depth-first


  • Informed (heuristic) search (utility-driven):

– Search costs; admissible heuristics – Algorithms: greedy best first; A* search

5

CS440/ECE448: Intro AI

Problem solving

The 8 queens problem

Can you place 8 queens on a chess board so that they donʼt attack each other?

!! !! !! !" !! !! !! !! ! !! !! !! !! !! !! !! !! !! !! !!

♕ ♕ ♕ ♕ ♕ ♕ ♕ ♕

!! !! !! !" !! !! !! !! ! !! !! !! !! !! !! !! !! !! !! !!

♕ ♕ ♕ ♕ ♕ ♕

This doesn’t work! Phew!

Initial State Goal

Four possible actions: MoveTileUp
 MoveTileDown
 MoveTileLeft
 MoveTileRight

The 8-puzzle

8

4 8 2 1 6 5 3 7 1 2 3 4 5 6 7 8

slide-3
SLIDE 3
  • Find a letter/digit substitution that forms a

natural & correct arithmetic expression

  • send


+ more
 = money forty
 ten
 + ten
 = sixty

Cryptarithmetic The route-finding problem

Giurgiu Urziceni Hirsova Eforie Neamt Oradea Zerind Arad Timisoara Lugoj Mehadia Drobeta Craiova Sibiu Fagaras Pitesti Vaslui Iasi Rimnicu Vilcea Bucharest 71 75 118 111 70 75 120 151 140 99 80 97 101 211 138 146 85 90 98 142 92 87 86

Starting point Destination

This lecture: assumptions

Todayʼs methods work when the environment is:

  • 1. observable 


(Agent perceives all it needs to know)

  • 2. known


(Agent knows the effects of each action)

  • 3. deterministic


(Each action always has the same outcome)


  • In such environments, the solution to any

problem is a fixed sequence of actions.

Solving a problem

  • 1. Formulate a goal 


goal = a (set of) state(s) to be in


  • 2. Define the corresponding problem


problem = what actions and states to consider


  • 3. Find the solution to the problem


solution = a sequence of actions to reach goal


  • 4. Execute the solution
slide-4
SLIDE 4

Implementing problem solving

We need:

  • a data structure to represent states
  • a designated initial state
  • a function that maps states to states


to represent actions (operators)

  • a boolean predicate (goal test) on states 


that checks whether a state is a goal state

13

CS440/ECE448: Intro AI

Representing states

8-queens: a set of chessboard positions

{}, {a4}, {a4, b6}, …

  • 8-puzzle: a list of nine numbers

<1,2,8,5,4,0,6,7,3>

  • Cryptarithmetic: a tuple of three sets

(unassigned letters, unassigned digits, assignments)

({e, m, n, o, r, s, y,}
 {0, 1, 2, 3, 4, 5, 6, 7, 9}
 {d:8})

  • 14

CS440/ECE448: Intro AI

The initial state

8-queens: the empty board {} 
 Cryptarithmetic: 
 (all letters, all digits, no assignments)

({d e, m, n, o, r, s, y,}
 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
 {})

  • 8-puzzle: a random board

<1,2,8,5,4,0,6,7,3> 15

CS440/ECE448: Intro AI

Actions

8-queens:

placeQueen(e4, s):
 if e4 s: (precondition) return s ∪ {e4} (effect) 


Cryptarithmetic:

replaceLetterWithDigit(l,d, s): if l ∈ s.unassignedLetters 
 and d ∈ s.unassignedDigits: 
 return (s.unassignedLetters\{l},
 s.unassignedDigits\{d},
 s.assignments ∪ {l:d})

  • 16

CS440/ECE448: Intro AI

slide-5
SLIDE 5

The cost of actions

Actions may have different costs:

The cost of driving from A to B depends 


  • n the distance (and traffic conditions)
  • We may need a cost function which calculates

the (exact) cost of each action.

  • We may want to find the lowest-cost solution

(otherwise, weʼre happy with the first one we find)

  • 17

CS440/ECE448: Intro AI

Goal test

8-queens:
 Are eight queens placed, and no queen attacks another queen? Cryptarithmetic: Have all letters been replaced by different digits, are there no leading zeros, and are all calculations correct?

State-space graph

! "! ! "! ! "! ! "! ! "! ! "! ! "! ! "! ! "! ! "! ! "!

Initial state a2 a1 a3

Nodes: states Edges: actions Edge weights: cost of actions

! "!

!. Goal state

! "!

Goal state !.

! "!

Goal state !. b3 c5 b4 b1 b2

Solution

! "! ! "! ! "! ! "! ! "! ! "! ! "! ! "! ! "! ! "! ! "!

Initial state a2 a1 a3

A single path from the initial state to a goal state.

! "!

!. Goal state

! "!

Goal state !.

! "!

Goal state !. b3 c5 b4 b1 b2

slide-6
SLIDE 6

Weighted state space graphs

Giurgiu Urziceni Hirsova Eforie Neamt Oradea Zerind Arad Timisoara Lugoj Mehadia Drobeta Craiova Sibiu Fagaras Pitesti Vaslui Iasi Rimnicu Vilcea Bucharest 71 75 118 111 70 75 120 151 140 99 80 97 101 211 138 146 85 90 98 142 92 87 86

Initial state 
 (starting point) Goal state
 (destination) Step costs
 (distances)

Search

[(demnorsy), (0123456789), ( )] (initial state)

Search Tree

[(emnorsy)
 (012345678)
 (d=9)] [(emnorsy)
 (123456789)
 (d=0)] [(emnorsy)
 (023456789)
 (d=1)]

NB: If the state space graph has loops, the search tree may be infinite!

choose an action

Problem solving with search

Initial state and operators define search tree

  • We need a search algorithm to build 


(the relevant parts of) the search tree.

NB: In code, build/represent only what is needed

– Do NOT generate the entire search tree – Do NOT save everything generated – Generate states incrementally – Forget anything not needed for future

slide-7
SLIDE 7

If there are b possible actions at each node: (b = branching factor)

At depth 1, there are b nodes. At depth 2, there are b*b = b2 nodes. … At depth d, there are bd nodes.

  • The size of a search tree with depth d and

branching factor b is O(bd)

The size of the search tree

Reducing the size 


  • f the search tree

What is the branching factor of 8-queens?

  • If queens can be placed anywhere: b=64

Size of tree: 64x63x…x57 = 178,462,987,637,760

  • If n-th queen is placed in n-th row: b= 8

Size of tree: 88 = 16,777,216

  • When possible, it can help to impose a

specific order on the actions in advance.

26

CS440/ECE448: Intro AI

Exploring the search tree

Start with the root (= the initial state).

It may not be possible to store/build the entire tree.

  • Leaf nodes (frontier) = unvisited nodes
  • Visiting a node: test whether itʼs a goal.

If not, expand it (find all its children).

  • 27

CS440/ECE448: Intro AI

Representing nodes 


  • f the search tree

n.STATE:
 the corresponding state in the state space n.PARENT: 
 pointer to the parent node in the search tree n.ACTION: 
 the action which gets from parent to here n.PATH-COST: 
 the total cost from the initial state to here

28

CS440/ECE448: Intro AI

slide-8
SLIDE 8

Expanding leaf nodes

Generating all children of a node in the search tree Expand(Node N): Children = new List(); For every Action a: child = apply(a, N) if child != null: Children.add(child) Return Children;

Traversing the tree

We need an ordered list of the leaf nodes we have not expanded yet (= the queue)

NB: The difference between search algorithms 
 lies in how they sort the queue

  • We may also want a list of the states we

have explored already (= the explored set)

This allows us to search on the state graph

30

CS440/ECE448: Intro AI

SEARCH(Problem P, QueuingFunction QF): local:n /*current node*/


  • q

/*queue of nodes to explore*/ q ! new List(InitialState(P)); Loop: if q == () return failure; n ! pop(q); if n solves P return n; /*Goal test*/ q ! QF(q, expand(n)); /*Expansion*/ end

Generic Search Function

Generic (tree) search function

Uninformed 
 (blind) search

slide-9
SLIDE 9

Depth-first search (LIFO)

  • Expand deepest node first

QF(old, new): 
 Append(new, old)


  • Breadth-first (FIFO)

Expand nodes level by level QF(old, new): 
 Append(old, new);

  • Generic Search Function

The queuing function defines 
 the search order

A B C D G H J I F E A B C D G H J I F E

Sample Search Tree

A B C D G H J I F E Goals

Depth-first search

A B C D G H J I F E

node queue 


current afterwards

  • 0. -

(A)

  • 1. A

(B C D)

  • 2. B

(E F C D)

  • 3. E

(F C D)

  • 4. F

(C D)

  • 5. C

(G D)

  • 6. G

(D) 1 2 3 4 5 6

Breadth-first search

node queue 


current afterwards

  • (A)

1.A (B C D) 2.B (C D E F) 3.C(D E F G) 4.D(E F G H I J) 5.E (F G H I J) …

A B C D G H J I F E

1 2 3 4 5 6

slide-10
SLIDE 10

Graph search

37

Each node in the search tree corresponds to a single sequence of actions from the root.

  • If a state in the state space can be reached

through n different sequences of actions, it corresponds to n nodes in the search tree.

  • If the state space graph has loops, the

search tree may be infinite!

  • The size of the search tree

Graph search

! "! ! "! ! "! ! "! ! "! ! "! ! "! ! "! ! "! ! "! ! "!

Initial state a2 a1 a3

Explored set Frontier (Queue) Unexplored set

! "!

!. Goal state

! "!

Goal state !.

! "!

Goal state !. b3 c5 b4 b1 b2

SEARCH(Problem P, Queuing Function QF): local:n, q, e; /* e= explored nodes */ e ! new List(); q ! new List(Initial_State(P)); Loop: if q == () return failure; n ! pop(q); if n solves P return n; add n.STATE to e; for m in Expand(n): if m not in e or q: q ! QF(q, m); end

Generic Search Function

Graph search

slide-11
SLIDE 11

Comparing 
 search algorithms

Time complexity: How long does it take to find a solution? Space complexity: How much memory does it take to find a solution?

  • Complexity of search algorithms

42

A search algorithm is complete 
 if it will find any goal whenever one exists. A search algorithm is optimal 
 if it will find the cheapest goal. Time complexity: how long does it take to find a solution? Space complexity: how much memory does it take to find a solution?

  • Properties of search algorithms

43

Breadth-first search

Breadth-first search is complete, but only

  • ptimal if each action has the same cost

(it will return the shortest [shallowest] solution)

  • Time complexity: O(bd)

If the shallowest goal is at depth d, breadth-first will visit all nodes up to depth d.


 Space complexity: O(bd)

The queue is of size O(bd)

  • 44

CS440/ECE448: Intro AI

slide-12
SLIDE 12

Tree-search DFS

m = maximal depth of search tree.

  • Only complete if m is finite.


(may try to wander down infinite branches)

DFS is not optimal.

  • Time complexity: O(bm)

(may need to visit all nodes in search tree)


  • Space complexity: O(bm)

(only stores one branch of the search tree)

45

CS440/ECE448: Intro AI

Graph-search DFS

Complete if the search space is finite. DFS is not optimal.

  • Time complexity: bounded by size of

search space. 
 
 Space complexity: bounded by size of search space.

46

CS440/ECE448: Intro AI

To conclude…

Todayʼs key concepts

Problem solving as search:

Solution = a finite sequence of actions


  • State graphs and search trees

Which one is bigger/better to search?


  • Systematic (blind) search algorithms

Breadth-first vs. depth-first; properties?
 


  • 48

CS440/ECE448: Intro AI

slide-13
SLIDE 13

Your tasks

  • Reading: Ch. 3.1-3.4 (only relevant parts)

  • Compass quiz: Up at 2pm

CS440/ECE448: Intro AI

49