Date post: | 02-Jan-2016 |
Category: |
Documents |
Upload: | sharlene-joseph |
View: | 216 times |
Download: | 0 times |
Lecture 1, Slide 1
Today’s Topics
• FREE Code that will Write Your PhD Thesis, a Best-Selling Novel, or Your Next Email
• Methods for Intelligently/Efficiently Searching a Space of Possible Solutions
– Depth, Breadth, Best first search
• Casting a Task as a Search Problem
• An Infinite Space
9/29/15 CS 540 - Fall 2015 (Shavlik©), Lecture 9, Week 4
CS 540 - Fall 2015 (Shavlik©), Lecture 9, Week 4
Generating Great Text is Easy, Discarding the Junk is Hard
WriteMyThesis(int expectedLengthInChars)
let text = “”
while (random() > 1.0 / expectedLengthInChars)
text += getRandomASCIIcharacter()
if (acceptable(text)) return text
else return WriteMyThesis(expectedLengthInChars)
9/29/15 2
CS 540 - Fall 2015 (Shavlik©), Lecture 9, Week 4
Visualizing AI Search as Discrete Graphs
• Nodes: an importance aspect of the problem• Directed Arcs: legal transitions between nodes• Weights (optional): cost of traversing an arc
9/29/15 3
Note: nodes usually a complex data structure (eg, a tree)
CS 540 - Fall 2015 (Shavlik©), Lecture 9, Week 4
Recall: Aspects of an AI Search Algorithm
Search Space Where we are looking; for now this will be a DISCRETE SPACE
Operators Legal ways to move from one node to another
Search Strategy
How we decide which move to make next
Heuristic Function
Some search methods score nodes to help guide search strategy (optional)
Start Node(s) Where we start (usually a single node, but could be a set)
Goal Node(s) How we know we are done (sometimes we’ll have an end test, ie code that says ‘DONE!’)9/29/15 4
Another Task Viewed as AI Search – the ‘8 Puzzle’
9/29/15 CS 540 - Fall 2015 (Shavlik©), Lecture 9, Week 4 5
1 3 5
6 7
2 4 8
Start State
1 2 3
4 5 6
7 8
Goal State
Legal moves: slide number into empty cell(‘state space’ drawn on paper using document camera)
In AI we build the state space as we go, and rarely generate the whole space. In HWs and textbooks, we often are given the WHOLE space, but that is misleading.
Possible heuristic (for scoring nodes)?i) Count of #’s in wrong cell
ii) Sum of moves if ‘collisions’ allowed
Designing Heuristics
• One good method is to think of a ‘relaxed’ (ie, simplified version) of the task– This guides the search algo, while the search algo
works out the details of the unrelaxed version
• Eg, in ROUTE PLANNING, assume one can ‘drive as the crow flies’ directly to the goal state (aka, ‘straight-line’ or Euclidean distance)
9/29/15 CS 540 - Fall 2015 (Shavlik©), Lecture 9, Week 4 6
The KEY Question of AI Search
Given a set of search-space nodes, which one should we ‘consider’ next?1. The youngest (most recently created)?
This is DEPTH-FIRST SEARCH (DFS)
2. The oldest (least recently created)?This is BREATH-FIRST SEARCH (BFS)
3. A random choice? SIMULATED ANNEALING (SA) does this
4. The best (need some scoring function)?This is BEST-FIRST SEARCH (BEST)
9/29/15 CS 540 - Fall 2015 (Shavlik©), Lecture 9, Week 4 7
General Pseudocode for Searching
The following is the basic outline for the various search algorithms (some steps need to be
modified depending on the specifics of the search being used).
OPEN = { startNode } // Nodes under consideration.
CLOSED = { } // Nodes that have been expanded.
While OPEN is not empty
Remove the first item from OPEN. Call this item X.
If goalState?(X) return the solution found.
// Expand node X if it isn’t a goal state.
Add X to CLOSED. // Prevents infinite loops.
Generate the immediate neighbors (i.e., children) of X.
Eliminate those children already in OPEN or CLOSED.
Based on the search strategy, insert the remaining
children into OPEN.
Return FAILURE // Failed if OPEN exhausted w/o a goal found.9/29/15 CS 540 - Fall 2015 (Shavlik©), Lecture 9, Week 4 8
Called ‘expanding’ a node
Lecture 1, Slide 9
Variations of “Return Solution”
• Might simply return SUCCESS
• Or return the GOAL node (this is what ID3 does)
• Or return PATH found from START to GOALeg, if planning a route to travel in a GPS
• Proper choice is problem specific
9/29/15 CS 540 - Fall 2015 (Shavlik©), Lecture 9, Week 4
CS 540 - Fall 2015 (Shavlik©), Lecture 9, Week 4
Data Structures for OPEN
Breadth-firstUse a ‘queue’ (first in, first out; FIFO)
OPEN OPEN + RemainingChildren
Depth-firstUse a ‘stack’ (last in, first out; LIFO)
OPEN RemainingChildren + OPEN
Best-firstUse a ‘priority queue’
OPEN sort(OPEN + RemainingChildren)9/29/15 10
Example (via Doc Camera)- assume LOWER scores are better
9/29/15 CS 540 - Fall 2015 (Shavlik©), Lecture 9, Week 4 11
Startscore = 9
Bscore = 11
Cscore = 8
Dscore = 4
Escore = 3
Goalscore = 0
Step# OPEN CLOSED X CHILDREN RemainingCHILDREN
(this part done on doc camera for BFS, DFS, and BEST)
Use these headers for HW2,
Problem 2
CS 540 - Fall 2015 (Shavlik©), Lecture 9, Week 4
BFS - remember we fill out line n+1 while working on line n
Step# OPEN CLOSED X CHILDREN RemainingCHILDREN
1 { S } { } S { S, B, C} { B, C }
2 { B, C } { S } B { D } { D }
3 { C, D } { S, B } C { G } { G }
4 { D, G } { S, B, C} D { E } { E }
5 { G, E} { S, B, C, D} G DONE
- note we check for GOALS upon removal from OPEN in order to get SHORTEST PATHS in later algo’s
BEST - we now need to record the heuristic score and sort OPEN
Step# OPEN CLOSED X CHILDREN RemainingCHILDREN
1 { S9 } { } S9 { S9, B11, C8} { B11, C8 }
2 { C8, B11 } { S9 } C8 { G0 } { G0 }
3 { G0, B11 } { S9, C8} G0 DONE
9/29/15 Lecture 1, Slide 12
CS 540 - Fall 2015 (Shavlik©), Lecture 9, Week 4
LOWER Better or Worse?
• Need to carefully check if lowerscores are better or worse
• Our default is lower is better, because often the score is ‘estimated distance to goal’
• For algo’s where HIGHER is better (hill climbing, simulated annealing), use
scoretoUse = - scoreoriginal
Think before you compute!9/29/15 13
CS 540 - Fall 2015 (Shavlik©), Lecture 9, Week 4 Lecture 1, Slide 14
A ‘Blocks World’ Example
‘Preconditions’ of a legal move(?x, ?y) action: clearTop(?x) ˄ clearTop(?y) ˄ ?x ≠ ?y
Heuristic? One possibility: # blocks in correct final position
9/29/15
CBA
Initial State
C
B
AGoal State
CS 540 - Fall 2015 (Shavlik©), Lecture 9, Week 4
An INFINITE Space
9/29/15 15
Legal actions:A) add TWO blocks (from an infinite bin) to an existing tower
B) add ONE block to an existing tower
Initial state: ONE block on the table (ie, a tower of height 1)
Goal state: a tower of height TWO
What might go wrong?
might produce tower of height 3, of height 5, …
CS 540 - Fall 2015 (Shavlik©), Lecture 9, Week 4
A (Hollywood) Famous AI Puzzle
• Task: put exactly 4 gallons of water in a 5 gallon jug, given
– a hose and an infinite supply of water– a 3 gallon jug (no ‘depth’ markings on the jug)– a 5 gallon jug
• Operators– Can fully empty or fill either jug– Can pour Jug ?A into Jug ?B
until ?A empty or ?B full9/29/15 16
From the movie
‘Die Hard’