ai chapter 4

Upload: antonio-peji-jr

Post on 05-Jul-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/16/2019 AI Chapter 4

    1/13

      ARTIFICIAL INTELLIGENCE (A. I.)  1

    LECTURE 4: Uninformed Search, Informed Search and Exploration

    Uninformed Search

    Blind search  or uninformed search  does not use any extra information about the problem domain. The twocommon methods of blind search are:

    1. BFS or Breadth First Search2. DFS or Depth First Search

    1. Breadth First Search

    Breadth first search the newly generated nodes are put at the back of fringe or the OPEN list. What this impliesis that the nodes will be expanded in a First In First Out (FIFO) order. The node that enters OPEN earlier will beexpanded earlier. This amounts to expanding the shallowest nodes first.

    Example:

    We will now consider the search space, and show how breadth first search works on this graph.

    Step 1: Initially fringe contains only one node corresponding to the source state A.

    Fringe: A

    Step 2: A is removed from fringe. The node is expanded, and its children B and C are generated. They are placedat the back of fringe.

    FIFO

    LIFO

  • 8/16/2019 AI Chapter 4

    2/13

      ARTIFICIAL INTELLIGENCE (A. I.)  2

    Fringe: B C

    Step 3: Node B is removed from fringe and is expanded. Its children D, E are generated and put at the back offringe.

    Fringe: C D E

    Step 4: Node C is removed from fringe and is expanded. Its children D and G are added to the back of fringe.

    Fringe: D E D G

    Step 5: Node D is removed from fringe. Its children C and F are generated and added to the back of fringe.

    Fringe: E D G C F

    Step 6: Node E is removed from fringe. It has no children. 

    Fringe: D G C F

    Step 7: D is expanded; B and F are put in OPEN.

  • 8/16/2019 AI Chapter 4

    3/13

      ARTIFICIAL INTELLIGENCE (A. I.)  3

    Fringe: G C F B F

    Step 8: G is selected for expansion. It is found to be a goal node. So the algorithm returns the path A C G byfollowing the parent pointers of the node corresponding to G. The algorithm terminates.

    Properties of Breadth-First Search

    Breadth first search is:

      Complete.  The algorithm is optimal (i.e., admissible) if all operators have the same

    cost. Otherwise, breadth first search finds a solution with the shortest

    path length.

      The algorithm has exponential time and space complexity. Suppose thesearch tree can be modeled as a b-ary tree as shown in Step 1 (graph).Then the time and space complexity of the algorithm is O(bd) where d isthe depth of the solution and b  is the branching factor (i.e., number ofchildren) at each node.

     A complete search tree of depth d where each non-leaf node has b children, has a total of

    1 + b + b2

    + ... + bd

    = (b(d+1)

    - 1)/(b-1) nodes

     Advantages of Breadth First Search:

      Finds the path of minimal length to the goal.

    Disadvantages of Breadth First Search:

      Requires the generation and storage of a tree whose size is exponential the depth of the shallowest goalnode.

    2. Depth First Search

    Depth first search algorithm puts newly generated nodes in the front of OPEN. This results in expanding thedeepest node first. Thus the nodes in OPEN follow a Last In First Out (LIFO) order. OPEN is thus implementedusing a stack data structure.

  • 8/16/2019 AI Chapter 4

    4/13

      ARTIFICIAL INTELLIGENCE (A. I.)  4

    Example:

    Let us now run Depth First Search on the search space given above, and trace its progress.

    Step 1: Initially fringe contains only the node for A.

    Fringe: A

    Step 2: A is removed from fringe. A is expanded and its children B and C are put in front of fringe.

    Fringe: B C

    Step 3: Node B is removed from fringe, and its children D and E are pushed in front of fringe.

    Fringe: D E C

    Step 4: Node D is removed from fringe. C and F are pushed in front of fringe.

    Fringe: C F E C

    Step 5: Node C is removed from fringe. Its child G is pushed in front of fringe.

  • 8/16/2019 AI Chapter 4

    5/13

      ARTIFICIAL INTELLIGENCE (A. I.)  5

    Fringe: G F E C

    Step 6: Node G is expanded and found to be a goal node. The solution path A-B-D-C-G is returned and thealgorithm terminates.

    Fringe: G F E C

    Properties of Depth First Search

    The algorithm takes exponential time. If N is the maximum depth of a node in the search space, in the worst case

    the algorithm will take time O(bd

    ). However the space taken is linear in the depth of the search tree, O(bN).

    Note that the time taken by the algorithm is related to the maximum depth of the search tree. If the search treehas infinite depth, the algorithm may not terminate. This can happen if the search space is infinite. It can alsohappen if the search space contains cycles. The latter case can be handled by checking for cycles in thealgorithm. Thus Depth First Search is not complete. 

    Depth Limited Search

     A variation of Depth First Search circumvents the above problem by keeping a depth bound. Nodes are onlyexpanded if they have depth less than the bound. This algorithm is known as depth-limited search.

     Advantages:• Linear memory requirements of depth-first search• Guarantee for goal node of minimal depth

    Procedure:

    Successive depth-first searches are conducted – each with depth bounds increasing by 1

    Depth First Iterative Deepening

  • 8/16/2019 AI Chapter 4

    6/13

      ARTIFICIAL INTELLIGENCE (A. I.)  6

    Depth First Iterative Deepening combines the advantage of BFS (i.e., completeness) with the advantages ofDFS (i.e., limited space and finds longer paths more quickly). This algorithm is generally preferred for large statespaces where the solution depth is unknown. 

    Informed Search Strategies

      Informed search strategy--one that uses problem-specific knowledge beyond the definition of the problemitself-can find solutions more efficiently than an uninformed strategy.

      Informed search strategies exploit problem-specific knowledge as much as possible to drive the search. They are almost always more efficient than uninformed searches and often also optimal .

    Heuristics

      a replicable method or approach for directing one's attention in learning, discovery, or problem-solving. Itis originally derived from the Greek "heurisko", which means "I find". (A form of the same verb is found in

     Archimedes'   famous exclamation "eureka!"   –  "I have found [it]!").  The term was introduced in the 4thcentury AD by Pappus of Alexandria. 

      means “rule of thumb”. To quote Judea Pearl, “Heuristics are criteria, methods or principles for decidingwhich among several alternative courses of action promises to be the most effective in order to achievesome goal”.

      used to identify the most promising search path.  stand for strategies using readily accessible, though loosely applicable, information to control problem

    solving in human beings and machines.  used to come to a solution rapidly that is hoped to be close to the best possible answer, or 'optimal

    solution'.

    In other words, the heuristic tells us approximately how far the state is from the goal state*.

    Heuristic algorithm consists of two parts:

      Heuristic measure  Search algorithm

    Search algorithm maintains a list of nodes called the fringe. The fringe keeps track of the nodes that have beengenerated but are yet to be explored. The fringe represents the frontier of the search tree generated.

    Here are a few other commonly used heuristics:

      If you are having difficulty understanding a problem, try drawing a picture.  If you can't find a solution, try assuming that you have a solution and seeing what you can derive from

    that ("working backward").

      If the problem is abstract, try examining a concrete example.

      Try solving a more general problem first (the "inventor's paradox": the more ambitious plan may havemore chances of success).

    Informed search  methods use problem specific knowledge, and may be more efficient. At the heart of suchalgorithms there is the concept of a heuristic function.

    Heuristic Function - heuristics are often obtained from relaxed problem. 

    http://www.heuristic.eu/greek_language_en.htmlhttp://www.heuristic.eu/archimedes_en.htmlhttp://www.heuristic.eu/eureka_word_en.htmlhttp://www.heuristic.eu/4th_century_en.htmlhttp://www.heuristic.eu/4th_century_en.htmlhttp://www.heuristic.eu/pappus_of_alexandria_en.htmlhttp://en.wikipedia.org/wiki/Problem_solvinghttp://en.wikipedia.org/wiki/Problem_solvinghttp://en.wikipedia.org/w/index.php?title=Inventor%27s_paradox&action=edit&redlink=1http://en.wikipedia.org/w/index.php?title=Inventor%27s_paradox&action=edit&redlink=1http://en.wikipedia.org/wiki/Problem_solvinghttp://en.wikipedia.org/wiki/Problem_solvinghttp://en.wikipedia.org/wiki/Problem_solvinghttp://www.heuristic.eu/pappus_of_alexandria_en.htmlhttp://www.heuristic.eu/4th_century_en.htmlhttp://www.heuristic.eu/4th_century_en.htmlhttp://www.heuristic.eu/4th_century_en.htmlhttp://www.heuristic.eu/eureka_word_en.htmlhttp://www.heuristic.eu/archimedes_en.htmlhttp://www.heuristic.eu/greek_language_en.html

  • 8/16/2019 AI Chapter 4

    7/13

      ARTIFICIAL INTELLIGENCE (A. I.)  7

      Simplify the original problem by removing constraints  The cost of an optimal solution to a relaxed problem is an admissible heuristic.

     A heuristic function at a node n is an estimate of the optimum cost from the current node to a goal. It is denotedby h(n).

    h(n) = estimated cost of the cheapest path from node n to a goal node

    Example 1: We want a path from Arad to Bucharest

    Solution: Straight-Line Distance 

    Greedy Search

    Greedy algorithms often perform very well. They tend to find good solutions quickly, although not always optimalones.

    The resulting algorithm is not optimal. The algorithm is also incomplete, and it may fail to find a solution even if

    one exists. This can be seen by running greedy search on the following example. A good heuristic for the route-finding problem would be straight-line distance to the goal.

    Greedy best-first search3 tries to expand the node that is closest to the goal, on the: grounds that this is likely to

    lead to a solution quickly. Thus, it evaluates nodes by using just the heuristic function: f (n) = h(n)

    h(n) estimates the distance remaining to a goal.

    Figure 1 is an example of a route finding problem. S is the starting state, G is the goal state.

    Figure 1 Figure 2

    Let us run the greedy search algorithm for the graph given in Figure 1. The straight line distance heuristicestimates for the nodes are shown in Figure 2.

    Step 1: S is expanded. Its children are A and D.

    Step 2: D has smaller cost and is expanded next.

  • 8/16/2019 AI Chapter 4

    8/13

      ARTIFICIAL INTELLIGENCE (A. I.)  8

    Straight-Line Distance

    Let us see how this works for route-finding problems in Romania, using the straight-line distance heuristic, whichwe will call hsLD. If the goal is Bucharest, we will need to know the straight-line distances to Bucharest. Forexample, hsLD(In(Arad)= ) 366. Notice that the values of hsLD cannot be computed from the problem descriptionitself. Moreover, it takes a certain amount of experience to know that hsLD is correlated with actual road distancesand is, therefore, a useful heuristic.

    Values of hSLD-straight-line distances to Bucharest .

    Stages in a greedy best-first search for Bucharest using the straight-line distanceheuristic hsto. Nodes are labeled with their h-values.

  • 8/16/2019 AI Chapter 4

    9/13

      ARTIFICIAL INTELLIGENCE (A. I.)  9

    Our first edition called this greedy search; other authors have called it best-first search. Our mare generalusage of the latter tern follows Pearl (1984).

    Manhattan Distance Heuristic. Another heuristic for 8-puzzle is the Manhattan distance heuristic. This heuristicsums the distance that the tiles are out of place. The distance of a tile is measured by the sum of the differencesin the x-positions and the y-positions. Manhattan distance is always >= exact heuristic, we can find path thatclose to best path but the application runs fast.

    Example: 8-puzzle: Misplaced Tiles Heuristics is the number of tiles out of place.

    The first picture shows the current state n, and the second picture the goal state.

      h1(n) = number of misplaced tiles  h2(n) = total Manhattan distance (i.e., number of squares from desired location of each tile)

    h(n) = 5 because the tiles 2, 8, 1, 6 and 7 are out of place.

    For the above example, using the Manhattan distance heuristic, h(n) = 1 + 1 + 0 + 0 + 0 + 1 + 1 + 2 = 6

    Symmetry Reductions. The state explosion problem is the main limitation of model checking. Symmetries in thesystem being verified can be exploited in order to avoid this problem by defining an equivalence (symmetry)relation on the states of the system, which induces a semantically equivalent quotient system of smaller size. Onthe other hand, heuristic search algorithms can be applied to improve the bug finding capabilities of modelchecking.

    Example: Tic-Tac-Toe

    This is a game that involves two players who play alternately. Player one puts a X in an empty position. Player 2places an O in an unoccupied position. The player who can first get three of his symbols in the same row, columnor diagonal wins. A portion of the state space of tic-tac-toe is depicted below. 

    Best First Search

     Uniform Cost Search is a special case of the best first search algorithm. The algorithm maintains apriority queue of nodes to be explored. A cost function f(n) is applied to each node. Nodes with smallerf(n) values are expanded earlier.

  • 8/16/2019 AI Chapter 4

    10/13

      ARTIFICIAL INTELLIGENCE (A. I.)  10

     Best-first search is an instance of the general TREE-SEARCH or GRAPH-SEARCH algorithm in which anode is EVALUATION FUNCTION selected for expansion based on an evaluation function, f (n).

     The name "best-first search" is a venerable but inaccurate one. Nevertheless, we will stick with the name"best-first search," because "seemingly-best-first search" is a little awkward.

    There is a whole family of BEST-FIRST-SEARCH algorithms with different evaluation functions.' A key

    component of these algorithms is a heuristic function, noted h(n):

    h(n) = estimated cost of the cheapest path from node n to a goal node.

    We will now consider different ways of defining the function f . This leads to different search algorithms.

    Uniform Cost Search

    In Uniform Cost Search (UCS), we enqueue nodes by path cost. Let g(n) = cost of the path from the start node tothe current node n. The algorithm sorts nodes by increasing value of g , and expands the lowest cost node of thefringe.

    Properties of Uniform Cost Search:  Complete  Optimal/Admissible  Exponential time and space complexity, O(bd)

    The UCS algorithm uses the value of g(n) to select the order of node expansion. We will now introduce informedsearch or heuristic search that uses problem specific heuristic information. The heuristic will be used to select theorder of node expansion.

    Example: Hill Climbing

    Uniform Cost

    • Measures the cost to each node. • Is optimal and complete! • Can be very slow. 

    Hill Climbing

    • Estimates how far away the goal is.• Is neither optimal nor complete. • Can be very fast. 

    A* Search

    In computer science,  A*  (pronounced "A star") is a computer algorithm that is widely used in path-finding andgraph traversal, the process of plotting an efficiently traversable path between points, called nodes. Noted for itsperformance and accuracy, it enjoys widespread use. Peter Hart,  Nils Nilsson,  and Bertram Raphael firstdescribed the algorithm in 1968. It is an extension of Edsger Dijkstra's 1959 algorithm.  A* achieves betterperformance (with respect to time) by using heuristics. 

    A* algorithm

    f(n) = g(n) + h(n) 

    where:

    g (n) is the cost to get to a node.sum of edge costs from start to ncost of going from the starting state to state n

    h (n) is the estimated distance to the goalestimate of lowest cost path from n to goal

    http://en.wikipedia.org/wiki/Computer_sciencehttp://en.wikipedia.org/wiki/Computer_algorithmhttp://en.wikipedia.org/wiki/Pathfindinghttp://en.wikipedia.org/wiki/Graph_traversalhttp://en.wikipedia.org/wiki/Computer_performancehttp://en.wikipedia.org/wiki/Peter_E._Harthttp://en.wikipedia.org/wiki/Nils_Nilssonhttp://en.wikipedia.org/wiki/Bertram_Raphaelhttp://en.wikipedia.org/wiki/Dijkstra%27s_algorithmhttp://en.wikipedia.org/wiki/Heuristicshttp://en.wikipedia.org/wiki/Heuristicshttp://en.wikipedia.org/wiki/Dijkstra%27s_algorithmhttp://en.wikipedia.org/wiki/Bertram_Raphaelhttp://en.wikipedia.org/wiki/Nils_Nilssonhttp://en.wikipedia.org/wiki/Peter_E._Harthttp://en.wikipedia.org/wiki/Computer_performancehttp://en.wikipedia.org/wiki/Graph_traversalhttp://en.wikipedia.org/wiki/Pathfindinghttp://en.wikipedia.org/wiki/Computer_algorithmhttp://en.wikipedia.org/wiki/Computer_science

  • 8/16/2019 AI Chapter 4

    11/13

      ARTIFICIAL INTELLIGENCE (A. I.)  11

    heuristic estimate of the cost of going from state n to the goal statef (n) actual distance so far + estimated distance remaining 

    We can think of f(n) as the estimated cost of the cheapest solution that goes through node n. We can prove that ifh(n) is admissible, then the search will find an optimal solution.

    The path returned is A-B-C-F-H.The path cost is 39. This is an optimal path.

    Informal proof outline of A* completeness: 

       Assume that every operator has some minimum positive cost, epsilon.    Assume that a goal state exists, therefore some finite set of operators lead to it.  Expanding nodes produces paths whose actual costs increase by at least epsilon each time. Since the

    algorithm will not terminate until it finds a goal state, it must expand a goal state in finite time.

    Informal proof  outline of A* optimality: 

      When A* terminates, it has found a goal state   All remaining nodes have an estimate cost to goal (f(n))  greater than or equal to that of goal we have

    found.

      Since the heuristic function was optimistic, the actual cost to goal for these other paths can be no betterthan the cost of the one we have already found.

    Local Search Algorithms

      If the path does not matter we can deal with local search.  They use a single current state  Move only to neighbors of that state

     Advantages:  Use very little memory

      Often find reasonable solutions

      It helps to see a state space landscape

      Find global maximum or minimum

    Complete search: Always finds a goalOptimal search: Finds global maximum or minimum.

    Example: Hill Climbing, local beam search, genetic algorithms, … Hill Climbing:

  • 8/16/2019 AI Chapter 4

    12/13

      ARTIFICIAL INTELLIGENCE (A. I.)  12

      Moves in the direction of increasing value.

      Terminates when it reaches a “peak”. 

      Does not look beyond immediate neighbors.

    Can get stuck for some reasons:

    a. Local maxima - a local maximum is a peak that is higher thaneach of its neighboring states, but lowers than the globalmaximum. H[ill-climbing algorithms that reach the vicinity of a localmaximum will be drawn upwards towards the peak, but will then be stuck with nowhere else to go. 

    Example: 8-queens a local maximum (i.e., a local minimum for thecost h); every move of a single queen makes the situation worse.

    b. Ridges - result in a sequence of local maxima that is very difficultfor greedy algorithms to navigate.

    c. Plateaux -  is an area of the state space landscape where the

    evaluation function is flat. It can be a flat local maximum, fromwhich no uphill exit exists, or a shoulder, from which it is possibleto make progress. A hill-climbing search might be unable to findits way off the plateau.

    Online Search Problems

      Agent knowledge: –   ACTION(s): list of allowed actions in state s –   C(s,a,s’): step-cost function (! After s’ is determined)  –   GOAL-TEST(s)

      An agent can recognize previous states

      Actions are deterministic

      Access to admissible heuristic h(s), e.g. Manhattan distance 

      Objective: reach goal with minimal cost –   Cost = total cost of traveled path –   Competitive ratio = comparison of cost with cost of the solution

    path if search space is known. –   Can be infinite in case of the agent accidentally reaches dead

    ends

    Online Search Agents

      The agent maintains a map of the environment. –   Updated based on percept input. –   This map is used to decide next action.

    * An online version can only expand the node it is physically in (local order).

    Online Local Search

    Illustration of why ridges cause difficultiesfor hill-climbing. The grid of states (darkcircles) is superimposed on a ridge risingfrom left to right, creating a sequence of

    local maxima that are not directlyconnected to each other. From eachlocal maximum, all the available actions

     point downhill.

  • 8/16/2019 AI Chapter 4

    13/13

      ARTIFICIAL INTELLIGENCE (A. I.)  13

      Hill-climbing is already online –   One state is stored.

      Bad performance due to local maxima –   Random restarts impossible.

    Real Problems

      Route finding

      Touring problems: traveling salesman, delivery tour

    Traveling Salesman Problem (TSP): Given a route of cities, visit each city exactly once while minimizing distancetraveled.

      Vehicle Routine Problem (VRP): Similar. Given one or more vehicles, visit each city at most once startingand returning to a depot(s).

      Scheduling and planning

      Theorem proving  Configuration Problems:  Given a set of components and constraints on their (spatial) relationships,

    arrange the components to variously minimize interconnections, maximize number of components, etc.(example: VLSI layout).

      VLSI layout

    VLSI layout: positioning millions of components and connections on a chip (minimizing area, circuit delays, straycapacitance, . . . )

      Speech recognition

      Model based vision

      Robot Planning:  Given a real robot and a goal of getting from point A to point B, find a plan whichminimizes distance/time traveled and succeeds.

      Robot navigation: no discrete sets of routes, continuous space   Automatic assembly sequence: find an order in which to assemble parts of an object

      Protein design:  find a sequence of amino acids that will fold into three-dimensional protein with rightproperties

      Internet searching: looking for relevant information on the Web

    Note:  All above are Constraint Optimization Problems which are known to be NP-complete.