Romania Review
Sometimes, we can choose to be smart (if our environment allows!).
If we have hints from the environment about how close we are to our goals, we can include them.
We do this in the form of heuristic functions \(h(n)\)
Where:
\(h(n)\) is the estimated cost of of the cheapest path from node \(n\) to the goal state
Let’s take our Bucharest function for example: what’s a decent hint as to how to find our goal?
One of the simplest in this case is the straight-line distance heuristic \(h_{SLD}\)
Example: \(h_{SLD}(Arad)=366\)
We CANNOT derive the value of \(h_{SLD}\) from the problem description (ACTIONS and RESULT functions). Why?
Is \(h_{SLD}\) correlated with road distances?
Greedy Best with hSLD
Careful… how can this heuristic go wrong?
Does this always find the most optimal path?
Worst case, this gives us \(O(|V|)\) and best case can reach \(O(bm)\)
Where, \(V\) is vertices, \(b\) is branching factor, and \(m\) is maximum depth of the search tree.
Is this complete in a finite search space? An infinite one?
The most common search algorithm:
\[ f(n) = g(n) + h(n) \]
Where \(g(n)\) is the path-cost from the initial state to node \(n\) and \(h(n)\) is the estimated cost of the shortest path from \(n\) to the goal state.
So… \(f(n)\) is the estimated cost of the best path that continues from from \(n\) to a goal state.
A* Romania
An extremely important feature of the problem is admissibility, an admissible heuristic will never overestimate the cost to the goal (optimistic).
A* will always return cost-optimal paths (proof is in the book)
Another important feature is consistency, which is a stronger description of behavior, such that:
\[ h(n)\leq c(n,a,n')+h(n') \]
Triangle inequality anyone?
Is every consistent heuristic admissible? Vice versa?
Plus, with a consistent heuristic, A* will always expand on the right path, no state will have to be re-added to the frontier, no entry in reached will ever have to be updated.
Can A* return a cost-optimal path with an inadmissible heuristic?
A good way of visualizing our search is with contours:
Contour Romania
As we search, our \(g\) cost increases monotonically. Right?
It’s not as clear if \(f=g+h\) also increases monotonically
\[ g(n)+h(n) \longrightarrow g(n)+c(n,a,n')+h(n') \]
That is… we’re only monotonically increasing iff
\[ h(n) \leq c(n,a,n')+h(n') \]
…if our heuristic is consistent
If C* is our optimal path to the solution
A* expands all nodes that can be reached from the initial state, where every node has \(f(n)\lt C^*\). “surely expanded”
A* might expand some nodes on the “goal contour” where \(f(n)=C^*\), before selecting the goal node
A* never expands a node with \(f(n)\gt C^*\)
And so is considered optimally efficient (with a consistent heuristic)
A* prunes nodes not required for the solution
A* is complete, cost-optimal, and optimally efficient.
So… is A* just the best?
Consider, a 2D vacuum world, where the agent is equipped with a super-strong vacuum which can clean any square, at the cost of 1.
With \(N\) dirty squares, there are \(2^N\) partially dirty states, and all of those are on the optimal path, so \(f(n)<C^*\) so all of them get visited by A*
A* is quite good but expands lots of nodes, we can explore less if we are less worried about finding the optimal solution.
This is a task we do often as humans! “Good Enough” (satisficing)
An inadmissible heuristic might be more accurate, but overestimate.
Civil Engineers anyone? Detour index?
We can replicate this:
We can weight the heuristic:
\[ f(n)=g(n)+W \times h(n) \]
Where \(W \gt 1\)
A* vs Weighted A*
The weighted A* explored 7x fewer states, with a path 5% more costly. Worth it?
In general, weighted A* can find a solution between \(C^*\) and \(W \times C^*\) , though usually closer to \(C^*\)
We can even reason about weighted A* as a generalization of other searches:
\(g(n) + h(n)\) where \(W = 1\)
\(g(n)\) where \(W = 0\)
\(h(n)\) where \(W = \infty\)
\(g(n) + W \times h(n)\) where \(1 < W < \infty\)
Bounded-suboptimal search (within some value of W) (A* satisfies this)
Bounded-cost search (cost within some constant C)
Unbounded-cost search (solution of any cost, if it can be found fast)
Speedy search is an unbounded-cost algorithm where the heuristic is fewest number of actions required, regardless of cost.
Looking back at 8-puzzles:
How many states can a 8-puzzle be in?
8-puzzle:
15-puzzle
We need a good heuristic!
Two common candidates:
\(h_1\) which is # of misplaced tiles
\(h_2\) which is sum of distances of the tiles from their goal positions (Manhattan distance)
8-Puzzle example
\(h_2 = 3+1+2+2+2+3+3+2=18\)
One way to compare heuristics is effective branching factor \(b^*\)
That is… if the total number of nodes generated by A* for some problem is \(N\) and the solution depth is \(d\) then \(b^*\) is the branching factor a uniform tree of depth \(d\), would have to have, to contain \(N+1\) nodes:
\[ N+1=1+b^*+(b^*)^2+...+(b^*)^d \]
Cost comparisons