Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory
Principles of Ar ficial Intelligence
Vasant Honavar Ar ficial Intelligence Research Laboratory College of Informa on Sciences and Technology Bioinforma cs and Genomics Graduate Program The Huck Ins tutes of the Life Sciences Pennsylvania State University
[email protected] h p://vhonavar.ist.psu.edu h p://faculty.ist.psu.edu/vhonavar
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Summary of uninformed (blind) search algorithms Criterion Breadth Depth- Iterative Bi- -First First deepening directional Complete? YES NO YES YES* Time bd+1 bm bd bd/2
Space bd+1 bm bd bd/2
Admissible? YES NO YES YES*
Optimal? NO NO YES NO
Assuming all arc costs are equal m – max depth of search d – depth of solu on, b – finite branching factor * Assuming forward and backward search are BFS
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Finding an op mal solu on
• All operator applica ons may not be equally expensive • Suppose we have a cost func on c: S x O à ℜ+ • c (q,o,r) = cost of applying operator o in state q to reach state r • Path cost is typically assumed to be the sum of costs of operator applica ons along the path • An op mal solu on is one with the lowest cost path from the specified start state s to a goal g ∈ G
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Finding op mal (minimum cost) solu ons
• Branch and bound search (BBS) with dynamic programming • Maintain a list of nodes sorted by cost g(n) of cheapest known par al paths to the respec ve nodes • Terminate when a node picked from the open list happens to be a goal node A 1 2 ((A,0)) B C ((AB, 1) (AC, 2) 3 8 1 3 D G E F ((AC, 2) (ABD, 4)(ABG,9)) 2 1 H I ((ACE, 3) (ABD, 4)(ACF, 5) (ABG,9))
((ACEI, 4) (ABD, 4)(ACEH, 5)(ACF, 5) (ABG,9))
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Finding op mal solu ons
• Branch and bound search (BBS) with dynamic programming • Maintain a list of nodes sorted by cost g(n) of cheapest known par al paths to the respec ve nodes • Terminate when a node picked from the open list happens to be a goal node • Ques ons: – Is BBS complete? • Yes – Is BBS admissible? • Yes – Under the assump on that each arc cost is bounded from below by some posi ve constant δ
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Informed search
• Informed search uses problem-specific knowledge • Which search strategies? – Best-first search and its variants • Heuris c func ons – How to design them • Local search and op miza on – Hill climbing, local beam search, gene c algorithms,… • Local search in con nuous spaces • Online search agents
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory A heuris c func on
• [dic onary]“A rule of thumb, simplifica on, or educated guess that reduces or limits the search for solu ons in domains that are difficult and poorly understood.”
Heuris cs, those rules of thumb, O en scorned as sloppy, dumb, Yet slowly commonsense become! – Judea Pearl, in Heuris cs
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Why we need heuris cs • Combinatorial explosion • Uninformed search runs out of me, space, or both quickly • Solu on – incorporate heuris cs to guide search • Perfect heuris c would guide search directly from start state to a goal state yielding the least expensive solu on – No need to search! • In prac ce, we have imperfect but useful heuris cs • A heuris c func on h(n), roughly speaking, es mates the cost of comple ng a par al path (s..n) to obtain a solu on, i.e., a path (s..n…g) where g is a goal state
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Why we need heuris cs • Combinatorial explosion • Uninformed search runs out of me, space, or both quickly • Perfect ra onality unaffordable • Can we come up with a compromise? – Use a heuris c func on to guide choice of ac ons • Suppose we could es mate the cost of the cheapest solu on obtainable by expanding each node that could be chosen
+ A h : S → ℜ ∀n∈ S, h(n)≥ 0 ∀g ∈G, h g = 0 s s ( ) 1 s2 3 h(s1 ) = 0.8 h(s2 ) = 2.0 h(s3 ) =1.6
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory A heuris c func on
In problems requiring the cheapest path from start state to a goal state – h(n) = es mated cost of the cheapest path from node n to a goal node – h(g1)=h(g2)=0 s
h(m) m n h(n)
g2 g1
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Hill-climbing search
• Choose “locally best” moves, guided by the heuris c func on, with random choice to break es • Terminates when a goal state is reached • Does not look beyond the immediate successors of the current state in deciding which move to make • Essen ally DFS, where at each step, successors are ordered by heuris c evalua on • a.k.a. greedy local search
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Heuris c func on - Example
• E.g for the 8-puzzle – Avg. solu on cost is about 22 steps – Exhaus ve search to depth 22 ≈ 3.1 x 1010 states – A good heuris c func on can reduce search
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Heuris c func ons
Two commonly used heuris cs
• h1 = the number of misplaced les (not coun ng blank) rela ve to the goal (why?)
h1(s)=8
• h2 = the sum of the distances of the les (not coun ng blank) from their desired posi ons (Manha an distance) (why?)
h2(s)=3+1+2+2+2+3+3+2=18 Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Drawbacks of hill-climbing search
• Ridge – sequence of local maxima difficult for greedy algorithms to navigate • Plateau – an area of the state space where the evalua on func on is flat
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Hill-climbing varia ons
• Stochas c hill-climbing – Random selec on among the uphill moves – The selec on probability can vary with the steepness of the uphill move • First-choice hill-climbing – stochas c hill climbing by genera ng successors randomly un l a be er one is found • Random-restart hill-climbing – Tries to avoid ge ng stuck in local maxima
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Best-first search
• General approach to informed search: – Best-first search: node is selected for expansion based on an evalua on func on f(n) • Idea: evalua on func on measures es mated cost of comple ng the par al solu on (s..n) – Choose node which appears best • Implementa on: – Open-list is a queue sorted in decreasing order of desirability – Special cases: greedy search, A* search
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Examples of Best-first search
• Best first search – List of par al paths is ordered by h values of the nodes • A* search – BBS-like search with dynamic programming – Open list nodes ordered by
f (n)= g(n)+ h(n)
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory A* search f (n)= g(n)+ h(n)
g(n) =2 g(m)=3 s 3 2 4 h(m)=6 3 h(n)=8 n 6 m 5 8
g2 g1
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Romania with step costs in km
• hSLD= straight-line distance heuris c.
• hSLD cannot be computed from the problem descrip on, requires addi onal informa on or knowledge on the part of the agent • In this example f(n)=h(n) – Expand node that is closest to goal = Greedy best-first search
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory A* search
• Best-known form of best-first search • Idea: avoid expanding paths that are already expensive • Evalua on func on f(n)=g(n) + h(n) – g(n) the cost (so far) to reach the node. – h(n) es mated cost to get from the node to the goal – f(n) es mated total cost of path through n to goal
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory A* search
• A* search using an admissible heuris c – A heuris c is admissible if it never overes mates the cost to reach the goal – Op mis c
Formally: 1. h(n) <= h*(n) where h*(n) is the true cost from n 2. h(n) >= 0 so h(G)=0 for any goal G.
e.g. hSLD(n) never overes mates the actual road distance
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Romania example
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Admissible heuris cs • A heuris c h(n) is admissible if for every node n, h(n) ≤ h*(n), where h*(n) is the true cost to reach the goal state from n. • An admissible heuris c never overes mates the cost to reach the goal, i.e., it is op mis c
• Example: hSLD(n) (never overes mates the actual road distance) • Theorem: If h(n) is admissible, A* using TREE-SEARCH is admissible • (provided each arc cost is bounded from below by a posi ve constant δ) • Proof Sketch: – Show that A* terminates with a solu on – Show that A* terminates with an op mal solu on
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Completeness of A*: A* Terminates with a solu on
• Assump on: Cost of each arc is bounded from below by a posi ve constant
∀ni,n j ,c(ni,n j ) ≥ δ > 0 • Any me a path gets extended, its cost increases by at least • There is a solu on, i.e., a bounded cost path to a goal (by assump on) • Termina on condi on: a path termina ng in a goal is picked off the front of € the list of par al paths L • There are two kinds of paths other than those that terminate in a goal: – Paths that lead to dead ends – discovered and discarded (if their cost is lower than that of a path to a goal) – Paths that are infinite (demoted behind a path leading to a goal because sooner or later their cost exceeds the cost of a path leading to a goal) – See notes for a formal proof.
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Admissibility of A*: A* cannot terminate with a subop mal goal
Suppose some subop mal goal G2 has been generated and is in the fringe. Let n be an unexpanded node in the fringe such that n is on a shortest path to an op mal goal G.
f(G2) = g(G2) since h(G2) = 0
g(G2) > g(G) since G2 is subop mal f(G) = g(G) since h(G) = 0
f(G2) > f(G) from above
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Admissibility of A*: A* cannot terminate with a subop mal goal
Suppose some subop mal goal G2 has been generated and is in the fringe. Let n be an unexpanded node in the fringe such that n is on a shortest path to an op mal goal G.
f(G2) > f(G) from above h(n) ≤ h*(n) since h is admissible g(n) + h(n) ≤ g(n) + h*(n) f(n) ≤ f(G)
* Hence f(G2) > f(n), and A will never select G2 for expansion That is, A* tree search is admissible provided the heuris c func on is admissible See notes for a more formal proof. Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory What if the search space is not a tree?
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Graph search • Previous proof breaks down • Possible solu ons: – Discard more expensive paths when there are mul ple paths to a node • Adds messy book-keeping • Admissible if h is admissible – Ensure that op mal path to any repeated state is always first followed • Extra requirement on h(n): consistency ∀n,∀n' where n' is a child of n, h(n) ≤ h(n')+ c(n, n')
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Consistency If h is consistent, we have n h ( n ) c( n ; m ) h(n) ≤ c(n,m) + h(m) c( n ; m ) f(n) is non-decreasing along any path
f (m) = g(m) + h(m) m = g(n) + c(n,m) + h(m) h ( m ) ≥ g(n) + h(n) +δ
G > f (n) à First goal selected for expansion must be an op mal goal à A* using graph search is admissible provided the heuris c used is consistent
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Proper es of A* search
• Complete?: YES – Since bands of increasing f are added – Unless there are infinitely many nodes with f < f(G) • Not possible when the branching factor is finite and arc costs are bounded from below by δ • Time complexity: – exponen al in the length of the solu on (in the worst case) • Space complexity: – Need to maintain all generated nodes in memory – Space is a more serious problem than me
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Memory-bounded heuris c search
• Some solu ons to A*’s space problems – Itera ve-deepening A* (IDA*) • Cutoff informa on is the f-cost (g+h) instead of depth • Can expand too many nodes when every node has a different f value – (simple) Memory-bounded A* ((S)MA*) • Drop the worst-leaf node when memory is full – Recursive best-first search (RBFS) • Recursive algorithm that a empts to mimic standard best- first search with linear space
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory (simple) memory-bounded A*
• Use all available memory. – i.e. expand best leafs un l available memory is full – When full, SMA* drops worst leaf node (highest f-value) – Backup the f-value of the forgo en node to its parent
• What if all leafs have the same f-value? – Same node could be selected for expansion and dele on – SMA* solves this by expanding newest best leaf and dele ng oldest worst leaf. • SMA* is complete if solu on is reachable, admissible if op mal solu on is reachable within the available memory bound
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Recursive best-first search (RBFS)
• Similar to IDA* but keeps track of the f value of the best- alterna ve path available from any ancestor of the current node – If current f values exceeds this alterna ve f value then backtrack to the best alterna ve path – During backtracking (unwinding of recursion) change f value of each node to best f-value of its children – Remembers the f value of the best leaf in the “forgo en” sub-tree and hence can revisit that sub-tree, if warranted, at some point in the future
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Recursive best-first search func on RECURSIVE-BEST-FIRST-SEARCH(problem) return a solu on or failure return RFBS(problem,MAKE-NODE(INITIAL-STATE[problem]),∞) func on RFBS( problem, node, f_limit) return a solu on or failure and a new f- cost limit if GOAL-TEST[problem](STATE[node]) then return node successors ← EXPAND(node, problem) if successors is empty then return failure, ∞ for each s in successors do f [s] ← max(g(s) + h(s), f [node]) repeat best ← the lowest f-value node in successors if f [best] > f_limit then return failure, f [best] alterna ve ← the second lowest f-value among successors result, f [best] ← RBFS(problem, best, min(f_limit, alterna ve)) if result ≠ failure then return result
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Recursive best-first search: Example
• Path un l Rumnicu Vilcea is already expanded • f-limit for every recursive call is shown above the node • f value is shown below the node • The path is followed un l Pites which has a f value worse than the f-limit.
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Recursive best-first search: Example
• Unwind recursion and store best f-value for current best leaf Pites result, f [best] ← RBFS(problem, best, min(f_limit, alterna ve)) • best is now Fagaras. Call RBFS for new best – best value is now 450
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Recursive best-first search: example.
• Unwind recursion and store best f-value for current best leaf Fagaras • best is now Rimnicu Viclea (again). Call RBFS for new best – Subtree is again expanded. – Best alterna ve subtree is now through Timisoara. • Solu on is found because 447 > 417. Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory RBFS
• RBFS is a bit more efficient than IDA* – S ll excessive node genera on – Like A*, admissible if h(n) is admissible • Space complexity is O(bd). • Time complexity difficult to characterize – Depends on accuracy if h(n) and how o en best path changes • IDA* and RBFS suffer from too li le memory • Other variants of A* aim to address these limita ons
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar Pennsylvania State University College of Information Sciences and Technology Artificial Intelligence Research Laboratory Learning to search be er
• All previous algorithms use fixed strategies. • Agents can learn to improve their search by exploi ng experience gained during the search (e.g., by analyzing missteps) • We will see examples of this when we consider learning agents
Principles of Artificial Intelligence, IST 597F, Fall 2014, (C) Vasant Honavar