Lecture 9 Informed Search

Informed Search Algorithms

  • Informed search algorithms are like GPS navigation for problem-solving. They use extra information (a "heuristic") to make smarter decisions about where to look next.

  • Analogy: Imagine searching for a lost item in your house. An informed search is like someone giving you hints about where the item is likely to be, rather than randomly searching every room.

  • A good estimate (heuristic) helps speed up the search process, saving time and resources to find the goal much faster.

Generic Search Algorithm

  • The search algorithm explores a search tree, which is a way of representing all the possible paths from the starting point to the goal.

  • Nodes are expanded and put into the frontier, which is stored in a queue data structure. The frontier is like a list of promising paths that the algorithm hasn't fully explored yet.

  • Different queue types (LIFO, FIFO) lead to different search behaviors (depth-first, breadth-first).

    • LIFO (Last-In, First-Out): Acts like a stack. The most recently added node is explored first (Depth-First Search).

    • FIFO (First-In, First-Out): Acts like a regular queue. The earliest added node is explored first (Breadth-First Search).

  • A priority queue is used in the generic search algorithm, where the next node to expand is determined by an evaluation function ff. This function assigns a score to each node, and the node with the best score is explored next.

Evaluation Functions
  • Different evaluation functions create different search algorithms, each suited to different types of problems.

  • For Breadth-First Search:

    • Evaluation function: depth of the node in the search tree. This means it explores all nodes at the same level before moving to the next level.

    • The node with the minimum depth is expanded first guaranteeing that it finds the shortest path.

  • For Depth-First Search:

    • Evaluation function: depth-depth of the node. This negative sign makes the algorithm prioritize deeper nodes.

    • The deepest node in the search tree is expanded first, which can quickly lead to a solution if the search goes in the right direction but may get stuck in very long paths.

Uniform Cost Search (Dijkstra's Algorithm)

  • Finds the shortest path or the solution with the smallest cost, useful when actions have different costs associated with them.

  • Evaluation function: path cost of a node (cost of getting to a particular node from the start). This is the sum of the costs of all the actions taken to reach that node.

  • The node with the lowest path cost is expanded first, ensuring that the algorithm always explores the cheapest path first.

Example: Comparing Breadth-First Search and Uniform Cost Search
  • Search problem: finding a path on a map with towns labeled a, b, c, d, etc., and action costs (kilometers) associated with transitions between states. Each road between towns has a specific length.

  • Breadth-First Search:

    • Doesn't consider transition costs; it only cares about the number of steps.

    • Minimizes the number of actions to reach a solution (shallowest goal node). If the goal is 2 nodes away it will pick it even if it costs more.

    • May return a sub-optimal solution because it doesn't take into account the cost of each step.

  • Uniform Cost Search:

    • Takes the cost into account when expanding nodes, always finding the cheapest path.

    • Uses a priority queue ordered by path cost and will expand the nodes based on what is the total cost so far from the inital node.

Example Walkthrough

  • Goal: Get from state a to state d.

  • Breadth-First Search expands a, then b and d. If b is expanded before d, it may find a longer path (a -> b -> c -> … -> d) before reaching the goal d directly (a -> d).

  • Uniform Cost Search expands a, then considers paths a -> b (cost 3) and a -> d (cost 6). It expands b first because it has a lower path cost. It then expands c. Finally, it reaches d via the lowest cost path a -> b -> c -> d.

Informed Search (Heuristic Search)

  • Uses a heuristic function to speed up the search process. A heuristic is a rule of thumb or an educated guess.

  • The heuristic function estimates the cost of getting from the current state to the goal state. It doesn't have to be perfect, just reasonably accurate.

  • Evaluation function: f(n)=g(n)+h(n)f(n) = g(n) + h(n)

    • g(n)g(n) is the path cost (cost of getting from the start state to the current node nn). This is how much it has actually cost to get where we are.

    • h(n)h(n) is the heuristic estimate of the cost of getting from nn to the goal state. This is our guess about how much further we have to go.

A* Search

  • A generic best-first search algorithm with a specific evaluation function.

    • It puts together the cost from the initial state to nn (path cost) and also the estimated cost from nn to the final state. By ading these costs we can try to find the best option

  • Dijkstra's algorithm is a special case of A* search where the heuristic function always returns zero.

    • h(n)=0h(n) = 0 for all nodes nn. This means it doesn't use any extra information to guide the search, only the actual cost from the start.

Example: Route Finding Problem
  • Goal: Find the route from Arad to Bucharest.

  • Heuristic: Straight-line distance from the current city to Bucharest. This is a reasonable heuristic because the shortest distance between two points is a straight line.

Greedy Best-First Search

  • Uses only the heuristic function to guide the search (ignores path cost). It is "greedy" because it always goes for what looks best right now.

  • Evaluation function: f(n)=h(n)f(n) = h(n)

  • Not guaranteed to find the optimal solution because it might get lured down a path that seems good initially but ends up being longer overall.

  • Example: Starting from Arad, the algorithm expands Sibiu because it has the smallest straight-line distance to Bucharest. This may lead to a sub-optimal path.

A* Search with Path Cost and Heuristic

  • Combines path cost and heuristic function in the evaluation function, balancing the desire to reach the goal quickly with the need to find the cheapest path.

  • Evaluation function: f(n)=g(n)+h(n)f(n) = g(n) + h(n)

  • Example: Starting from Arad:

    • f(Arad)=0+366=366f(\text{Arad}) = 0 + 366 = 366

    • The algorithm expands Arad and considers Sibiu, Timisoara, and Zerind.

    • The value of f(n)f(n) is computed for each successor node based on the path cost and the heuristic value.

    • The node with the smallest f(n)f(n) is expanded next.

Admissible Heuristics

  • An admissible heuristic never overestimates the true cost of getting to the goal state. It's optimistic, never pessimistic.

  • If an admissible heuristic is used, A* search is guaranteed to find the optimal solution. This is because it prevents the algorithm from overlooking potentially better paths.

  • Example: Straight-line distance is an admissible heuristic because it is always less than or equal to the actual path cost over roads.

  • Using zero as the heuristic value is also admissible, but it may result in a slower search. It is admissible because it never overestimates, but it provides no useful information.

  • A better heuristic is one that estimates the true cost as closely as possible from below, without overestimating. This guides the search more effectively without sacrificing optimality.

Heuristic Design

  • Careful design of a heuristic function can significantly speed up the search process. A well-chosen heuristic can make the difference between solving a problem quickly and not solving it at all.

  • Strategies for designing heuristics are available in the literature. These strategies often involve understanding the specific properties of the problem you're trying to solve.

Example: 8-Puzzle Problem
  • Goal: Rearrange tiles to reach the goal state.

  • Heuristic: Estimate the number of moves needed to reach the goal state. The better the estimate the faster the algorithm can find the optimized version to solve the puzzle

Relaxed Problems

  • Create relaxed versions of the search problem by removing some of the constraints. This makes the problem easier to solve, and the solution to the relaxed problem can be used as a heuristic for the original problem.

  • Example 1: Allow tiles to be moved anywhere in one move. The heuristic value is the number of misplaced tiles. This is a relaxed version because it removes the constraint that tiles can only move to adjacent squares.

  • Example 2: Allow tiles to move by one square even if the square is occupied. The heuristic value is the sum of the Manhattan distances (city block distances) between each tile's current location and its location in the goal state.

  • The Manhattan distance is calculated as the sum of the horizontal and vertical distances. It is called Manhattan distance because it is like calculating the distance a car has to drive between two points in Manhattan: It can't go straight, it has to follow the grid to get there.

Consistent Heuristics

  • A stronger criterion than admissibility. If it's consistent it's admissible but not all admissible heuristics are consistent

  • A heuristic is consistent if it satisfies the triangle inequality: h(n)c(n,a,n)+h(n)h(n) \leq c(n, a, n') + h(n')

    • c(n,a,n)c(n, a, n') is the action cost for performing action aa in state nn to get to state nn'.

    • h(n)h(n') is the estimated cost for getting from nn' to the goal state.

    • h(n)h(n) is the estimated cost for getting from nn to the goal state.

  • If a heuristic is consistent, the first time a goal state is reached, it corresponds to the optimal path to the goal state. This means you don't have to worry about finding a better path later.

  • With a consistent heuristic, we may not need to check if a node has been reached via a shorter path. This can save computation time.

  • Consistent heuristics allow us to draw search contours where the value of the evaluation function decreases monotonically. The closer it gets to the goal the search will decrease. Since it is consistent, you don't have to worry about finding a better path later due to the nature of how the heuristic works

  • A* search with a consistent heuristic is cost-optimal, complete, and optimally efficient. Very good performance and makes it optimal compared to other heuristics.

Limitations of A* Search

  • May run out of memory or take too long to find a solution. Especially for very large and complex problems, this may not be a solution. It make take hours, days, or even run out of memory before finding the optimal results

  • In such cases, we may need to sacrifice optimality. Sometimes a "good enough" solution is better than waiting forever for the best solution.

Beam Search
  • Limit the size of the frontier (number of nodes kept in memory).

  • Keep only the best NN nodes (beam) in the frontier. It reduces the amount of memory usage, so even if you don't find the perfect solution it solves it within the constraints

  • Sacrifice optimality for reduced memory usage.

  • Can be implemented efficiently using a min-max heap or by truncating the queue.

Next Steps

  • Adversarial search problems (e.g., game playing). In games, you need to consider what your opponent is going to do.

  • Min-max search and alpha-beta pruning. These are techniques for making optimal decisions in games.

  • Monte Carlo tree search. A more advanced technique used in games like Go.