Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS Fall 2016 (Shavlik©), Lecture 8, Week 5

Similar presentations


Presentation on theme: "CS Fall 2016 (Shavlik©), Lecture 8, Week 5"— Presentation transcript:

1 CS 540 - Fall 2016 (Shavlik©), Lecture 8, Week 5
11/18/2018 Today’s Topics FREE Code that will Write Your PhD Thesis, a Best-Selling Novel, or Your Next 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 10/4/16 CS Fall 2016 (Shavlik©), Lecture 8, Week 5

2 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) 10/4/16 CS Fall 2016 (Shavlik©), Lecture 8, Week 5

3 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 Note: nodes usually a complex data structure (eg, a tree) 10/4/16 CS Fall 2016 (Shavlik©), Lecture 8, Week 5

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!’) 10/4/16 CS Fall 2016 (Shavlik©), Lecture 8, Week 5

5 The KEY Question of AI Search
Given a set of search-space nodes, which one should we ‘consider’ next? The youngest (most recently created)? This is DEPTH-FIRST SEARCH (DFS) The oldest (least recently created)? This is BREATH-FIRST SEARCH (BFS) A random choice? SIMULATED ANNEALING (SA) does this The best (need some scoring function)? This is BEST-FIRST SEARCH (BEST) 10/4/16 CS Fall 2016 (Shavlik©), Lecture 8, Week 5

6 Another Task Viewed as AI Search – the ‘8 Puzzle’
Possible heuristic (for scoring nodes)? 1 3 5 6 7 2 4 8 Start State i) Count of #’s in wrong cell ii) Sum of moves if ‘collisions’ allowed Legal moves: slide number into empty cell (‘state space’ drawn on blackboard) 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. 1 2 3 4 5 6 7 8 Goal State 10/4/16 CS Fall 2016 (Shavlik©), Lecture 8, Week 5

7 CS 540 - Fall 2016 (Shavlik©), Lecture 8, Week 5
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) 10/4/16 CS Fall 2016 (Shavlik©), Lecture 8, Week 5

8 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. Called ‘expanding’ a node 10/4/16 CS Fall 2016 (Shavlik©), Lecture 8, Week 5

9 Variations of “Return Solution”
CS 540 Fall 2015 (Shavlik) 11/18/2018 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 GOAL eg, if planning a route to travel in a GPS Proper choice is problem specific 10/4/16 CS Fall 2016 (Shavlik©), Lecture 8, Week 5

10 Data Structures for OPEN
Breadth-first Use a ‘queue’ (first in, first out; FIFO) OPEN  OPEN + RemainingChildren Depth-first Use a ‘stack’ (last in, first out; LIFO) OPEN  RemainingChildren + OPEN Best-first Use a ‘priority queue’ OPEN  sort(OPEN + RemainingChildren) 10/4/16 CS Fall 2016 (Shavlik©), Lecture 8, Week 5

11 Example (via blackboard) - assume LOWER scores are better
Start score = 9 B score = 11 C score = 8 D score = 4 Use these headers for HW2, Problem 2 Goal score = 0 E score = 3 Step# OPEN CLOSED X CHILDREN RemainingCHILDREN (this part done on blackboard for BFS, DFS, and BEST) 10/4/16 CS Fall 2016 (Shavlik©), Lecture 8, Week 5

12 CS 540 - Fall 2016 (Shavlik©), Lecture 8, Week 5
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 { C, 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 1 { S9 } { } S9 { S9, B11, C8} { B11, C8 } 2 { C8, B11 } { S9 } C8 { G0 } { G0 } 3 { G0, B11 } { S9, C8} G0 DONE 10/4/16 CS Fall 2016 (Shavlik©), Lecture 8, Week 5

13 CS 540 - Fall 2016 (Shavlik©), Lecture 8, Week 5
DFS - remember we fill out line n+1 while working on line n Step# OPEN CLOSED X CHILDREN RemainingCHILDREN 1 { S } { } S { SS, BS, CS} { BS, CS } 2 { BS, CS } { S } BS { DB } { DB } 3 { DB, CS } { S, BS } DB { CD, ED } { ED } 4 { ED, CS } { S, BS, DB} ED { GE } { GE } 5 { GE, CS } {S,BS,DB,ED} GE DONE Notice we did not get the shortest path here (BFS did, though) We might want to also record the PARENT of each node reached, so we can easily extract the path from START to GOAL. This was done in the above using SUPERSCRIPTs 10/4/16 CS Fall 2016 (Shavlik©), Lecture 8, Week 5

14 Think before you compute!
LOWER Better or Worse? Need to carefully check if lower scores 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! 10/4/16 CS Fall 2016 (Shavlik©), Lecture 8, Week 5

15 A ‘Blocks World’ Example
Initial State Goal State A B A B C C ‘Preconditions’ of a legal move(?x, ?y) action: clearTop(?x) ˄ clearTop(?y) ˄ ?x ≠ ?y Heuristic? One possibility: # blocks in correct final position 10/4/16 CS Fall 2016 (Shavlik©), Lecture 8, Week 5

16 CS 540 - Fall 2016 (Shavlik©), Lecture 8, Week 5
An INFINITE Space 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, … 10/4/16 CS Fall 2016 (Shavlik©), Lecture 8, Week 5

17 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 full From the movie ‘Die Hard’ 10/4/16 CS Fall 2016 (Shavlik©), Lecture 8, Week 5


Download ppt "CS Fall 2016 (Shavlik©), Lecture 8, Week 5"

Similar presentations


Ads by Google