artificialintelligence_4_informedsearch

30
Grundlagen der k¨ unstlichen Intelligenz – Informed Search Matthias Althoff TU M¨ unchen 17. October 2014 Matthias Althoff Informed Search 17. October 2014 1 / 22

Upload: marawan-okasha

Post on 19-Nov-2015

11 views

Category:

Documents


0 download

DESCRIPTION

Artificial Intelligence Presentation

TRANSCRIPT

  • Grundlagen der kunstlichen Intelligenz Informed Search

    Matthias Althoff

    TU Munchen

    17. October 2014

    Matthias Althoff Informed Search 17. October 2014 1 / 22

  • Organization

    Informed search strategies

    Heuristic functions

    The content is covered in the AI book by the section Solving Problems bySearching, Sec. 5-6.

    Matthias Althoff Informed Search 17. October 2014 2 / 22

  • Informed Search Strategies

    Informed Search

    Requires problem-specific knowledge beyond the problem definition.

    Can find solutions more efficiently than uninformed search.

    Informed search uses indications whether a state is more promisingthan another to reach a goal.

    The choice of the next node is based on an evaluation functionf (n), which itself is often based on a heuristic function h(n).

    h(n) is problem specific with the only constraints that it isnonnegative and h(n) = 0, where n is a goal node.

    All presented informed search strategies are implemented identically touniform-cost search, except that f instead of g is used in the priorityqueue.

    Heuristic

    Heuristic refers to the art to achieve good solutions with limitedknowledge and time based on experience.

    Matthias Althoff Informed Search 17. October 2014 3 / 22

  • Informed Search Strategies

    Greedy Best-First Search: Idea

    Expands the node that is closest to the goal by using just the heuristic functionso that f (n) = h(n).Example: Route-finding problem in Romania. We use the straight line distance tothe goal as h(n), which is listed below:

    Bucharest

    Giurgiu

    Urziceni

    Hirsova

    Eforie

    NeamtOradea

    Zerind

    Arad

    Timisoara

    LugojMehadia

    DobretaCraiova

    Sibiu

    Fagaras

    PitestiRimnicu Vilcea

    Vaslui

    Iasi

    Straightline distanceto Bucharest

    0160242161

    77151

    241

    366

    193

    178

    25332980

    199

    244

    380

    226

    234

    374

    98

    Giurgiu

    UrziceniHirsova

    Eforie

    Neamt

    Oradea

    Zerind

    Arad

    Timisoara

    Lugoj

    Mehadia

    Dobreta

    Craiova

    Sibiu Fagaras

    Pitesti

    Vaslui

    Iasi

    Rimnicu Vilcea

    Bucharest

    71

    75

    118

    111

    70

    75120

    151

    140

    99

    80

    97

    101

    211

    138

    146 85

    90

    98

    142

    92

    87

    86

    Matthias Althoff Informed Search 17. October 2014 4 / 22

  • Informed Search Strategies

    Greedy Best-First Search: Example

    Arad

    366

    Matthias Althoff Informed Search 17. October 2014 5 / 22

  • Informed Search Strategies

    Greedy Best-First Search: Example

    Zerind

    Arad

    Sibiu Timisoara

    253 329 374

    Matthias Althoff Informed Search 17. October 2014 5 / 22

  • Informed Search Strategies

    Greedy Best-First Search: Example

    Rimnicu Vilcea

    Zerind

    Arad

    Sibiu

    Arad Fagaras Oradea

    Timisoara

    329 374

    366 176 380 193

    Matthias Althoff Informed Search 17. October 2014 5 / 22

  • Informed Search Strategies

    Greedy Best-First Search: Example

    Rimnicu Vilcea

    Zerind

    Arad

    Sibiu

    Arad Fagaras Oradea

    Timisoara

    Sibiu Bucharest

    329 374

    366 380 193

    253 0

    Note that the solution is not optimal since the path is 32 km longer thanthrough Rimnicu Vilcea and Pitesti.

    Matthias Althoff Informed Search 17. October 2014 5 / 22

  • Informed Search Strategies

    Greedy Best-First Search: Another Example

    Greedy best-first search is incomplete when not using an explored set,even on finite state spaces.E.g. when going from Iasi to Faragas, Neamt is first expanded due tocloser straight line distance, but this is a dead end.

    Giurgiu

    UrziceniHirsova

    Eforie

    Neamt

    Oradea

    Zerind

    Arad

    Timisoara

    Lugoj

    Mehadia

    DobretaCraiova

    Sibiu Fagaras

    Pitesti

    Vaslui

    Iasi

    Rimnicu Vilcea

    Bucharest

    71

    75

    118

    111

    70

    75

    120

    151

    140

    99

    80

    97

    101

    211

    138

    146 85

    90

    98

    142

    92

    87

    86

    Matthias Althoff Informed Search 17. October 2014 6 / 22

  • Informed Search Strategies

    Greedy Best-First Search: Performance

    Reminder: Branching factor b, depth d, maximum length m of any path.

    Completeness: Yes, if an explored set is used, otherwise no (seeprevious example).

    Optimality: No (see previous example).

    Time complexity: The worst-case is that the heuristics is misleadingthe search such that the solution is found last: O(bm). But a goodheuristic can provide dramatic improvement.

    Space complexity: Equals time complexity since all nodes are stored:O(bm).

    Matthias Althoff Informed Search 17. October 2014 7 / 22

  • Informed Search Strategies

    A* search: Idea

    The most widely known informed search is A* search (pronouncedA-star search).

    It evaluates nodes by combining the path cost g(n) and the estimatedcost to the goal h(n):

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

    where h(n) has to be underestimated, i.e. it has to be less than theactual cost.

    f (n) never overestimates the cost to the goal and thus thealgorithm keeps searching for paths that might have lower cost to thegoal than the previously found ones.

    Matthias Althoff Informed Search 17. October 2014 8 / 22

  • Informed Search Strategies

    A* Search: Example

    Straight line distance is an underestimation of the cost to the goal, whichare used for h(n).

    Arad

    366=0+366

    Nodes are labeled with f = g + h

    Matthias Althoff Informed Search 17. October 2014 9 / 22

  • Informed Search Strategies

    A* Search: Example

    Straight line distance is an underestimation of the cost to the goal, whichare used for h(n).

    Zerind

    Arad

    Sibiu Timisoara

    447=118+329 449=75+374393=140+253

    Nodes are labeled with f = g + h

    Matthias Althoff Informed Search 17. October 2014 9 / 22

  • Informed Search Strategies

    A* Search: Example

    Straight line distance is an underestimation of the cost to the goal, whichare used for h(n).

    Zerind

    Arad

    Sibiu

    Arad

    Timisoara

    Rimnicu VilceaFagaras Oradea

    447=118+329 449=75+374

    646=280+366 413=220+193415=239+176 671=291+380

    Nodes are labeled with f = g + h

    Matthias Althoff Informed Search 17. October 2014 9 / 22

  • Informed Search Strategies

    A* Search: Example

    Straight line distance is an underestimation of the cost to the goal, whichare used for h(n).

    Zerind

    Arad

    Sibiu

    Arad

    Timisoara

    Fagaras Oradea

    447=118+329 449=75+374

    646=280+366 415=239+176

    Rimnicu Vilcea

    Craiova Pitesti Sibiu

    526=366+160 553=300+253417=317+100

    671=291+380

    Nodes are labeled with f = g + h

    Matthias Althoff Informed Search 17. October 2014 9 / 22

  • Informed Search Strategies

    A* Search: Example

    Straight line distance is an underestimation of the cost to the goal, whichare used for h(n).

    Zerind

    Arad

    Sibiu

    Arad

    Timisoara

    Sibiu Bucharest

    Rimnicu VilceaFagaras Oradea

    Craiova Pitesti Sibiu

    447=118+329 449=75+374

    646=280+366

    591=338+253 450=450+0 526=366+160 553=300+253417=317+100

    671=291+380

    Nodes are labeled with f = g + h

    Matthias Althoff Informed Search 17. October 2014 9 / 22

  • Informed Search Strategies

    A* Search: Example

    Straight line distance is an underestimation of the cost to the goal, whichare used for h(n).

    Zerind

    Arad

    Sibiu

    Arad

    Timisoara

    Sibiu Bucharest

    Rimnicu VilceaFagaras Oradea

    Craiova Pitesti Sibiu

    Bucharest Craiova Rimnicu Vilcea

    418=418+0

    447=118+329 449=75+374

    646=280+366

    591=338+253 450=450+0 526=366+160 553=300+253

    615=455+160 607=414+193

    671=291+380

    Nodes are labeled with f = g + h

    Matthias Althoff Informed Search 17. October 2014 9 / 22

  • Informed Search Strategies

    A* Search: Effects of the Heuristics

    The heuristics steers the search towards the goal.A* expands nodes in order of increasing f value, so that f -contoursof nodes are gradually added.Each contour i has all nodes with f = fi , where fi < fi+1.

    O

    Z

    A

    T

    L

    M

    DC

    R

    F

    P

    G

    BU

    H

    E

    V

    I

    N

    380

    400

    420

    S

    Matthias Althoff Informed Search 17. October 2014 10 / 22

  • Informed Search Strategies

    A* Search: Pruning

    Given the cost C of the optimal path, it is obvious that only pathsare expanded with f (n) < C . A* never expands nodes, where f (n) C .

    For instance, Timisoara is not expanded in the previous example. Wesay that the subtree below Timisoara is pruned.

    The concept of pruning eliminating possibilities from considerationwithout having to examine them brings enormous time savings andis similarly done in other areas of AI.

    Especially for large problems, pruning becomes important.

    Matthias Althoff Informed Search 17. October 2014 11 / 22

  • Informed Search Strategies

    A* Search: Performance

    Reminder: Branching factor b, depth d, maximum length m of any path.

    Time and space complexity of A* is quite involved and we will not derivethe results. They are presented in terms of the relative error = (h h)/h, where h is the estimated and h is the actual cost fromthe root to the goal.

    Completeness: Yes, if costs are greater than 0 (otherwise infiniteoptimal paths of zero cost exist).

    Optimality: Yes (if cost are positive).

    Time complexity: We only consider the easiest case: The statespace has a single goal and all actions are reversible: O(bd) (withoutproof)

    Space complexity: Equals time complexity since all nodes are stored.

    Matthias Althoff Informed Search 17. October 2014 12 / 22

  • Informed Search Strategies

    Alternatives of A* Search

    One of the big disadvantages of A* search is the possibly huge spaceconsumption. This can be alleviated by extensions, which we only mentionhere:

    Iterative-deepening A*: adapts the idea of iterative deepening toA*. The main difference is that the f -cost (g + h) is used for cutoff,rather than the depth.

    Recursive best-first search: a simple recursive algorithm with linearspace complexity. Its structure is similar to the one ofrecursive-depth-first search, but keeps track of the f -value of the bestalternative path.

    Memory-bounded A* and simplified memory-bounded A*: Thosealgorithms work just as A* until the memory is full. The algorithmsdrop less promising paths to free memory.

    Matthias Althoff Informed Search 17. October 2014 13 / 22

  • Heuristic Functions

    Heuristic Functions

    For the shortest route in Romania, the straight line distance is an obviousunderapproximating heuristics.

    2

    Start State Goal State

    1

    3 4

    6 7

    5

    1

    2

    3

    4

    6

    7

    8

    5

    8

    This is not always so easy, as we will show for the 8-puzzle. Problem size:

    On average 22 steps to a solution.Average branching factor is about 3 (4 moves when empty tile is inthe middle, 2 in a corner, and 3 on an edge).An exhaustive search visits about 322 3.1 1010 states.Remembering previously visited states reduces to 9!/2 = 181, 440distinct states, but there are already 15!/2 1013 for the 15-puzzle.Matthias Althoff Informed Search 17. October 2014 14 / 22

  • Heuristic Functions

    Heuristic Functions for the 8-Puzzle

    Two commonly used candidates that underestimate the costs to the goal:

    h1: the number of misplaced tiles (e.g. in the figure h1 = 8).Admissible since any misplaced tile has to be moved at least once.

    h2: the sum of the distances to the goal positions using horizontaland vertical movement. Admissible since all a move can do is bringthe tile one step closer. In the figure:

    tile 1 2 3 4 5 6 7 8 sumsteps 3 1 2 2 2 3 3 2 18

    2

    Start State Goal State

    1

    3 4

    6 7

    5

    1

    2

    3

    4

    6

    7

    8

    5

    8

    (the true cost is 26)

    Matthias Althoff Informed Search 17. October 2014 15 / 22

  • Heuristic Functions

    Effective Branching Factor

    One way of characterizing the quality of a heuristics is the effectivebranching factor b.Given:

    Number of nodes N generated by the A* search.

    A uniform tree with depth d (each node has the same fractionalnumber b of children)

    Thus,N + 1 = 1 + b + (b)2 + . . .+ (b)d .

    E.g. if A* generates a solution at depth 5 using 52 nodes, b = 1.92 since

    53 1 + 1.92 + (1.92)2 + . . .+ (1.92)5.

    The branching factor makes it possible to compare heuristics applied toproblems of different size. Why?

    Matthias Althoff Informed Search 17. October 2014 16 / 22

  • Heuristic Functions

    Comparison of the Heuristics for the 8-Puzzle

    1200 random problems with solution length from 2 24 (100 for each evennumber):

    Search Cost (nodes generated) Effective Branching Factord IDS A*(h1) A*(h2) IDS A*(h1) A*(h2)

    2 10 6 6 2.45 1.79 1.79

    4 112 13 12 2.87 1.48 1.45

    6 680 20 18 2.73 1.34 1.30

    8 6384 39 25 2.80 1.33 1.24

    10 47127 93 39 2.79 1.38 1.22

    12 3644035 227 73 2.78 1.42 1.24

    14 539 113 1.44 1.23

    16 1301 211 1.45 1.25

    18 3056 363 1.46 1.26

    20 7276 676 1.47 1.27

    22 18094 1219 1.48 1.28

    24 39135 1641 1.48 1.26

    Matthias Althoff Informed Search 17. October 2014 17 / 22

  • Heuristic Functions

    Domination of a Heuristics

    Question: Is h2 always better than h1?

    Answer: Yes.

    Reason:

    For every node we have that h2(n) > h1(n). We say that h2dominates h1.

    A* using h2 will never expand more nodes than with h1 (exceptspossibly for some nodes with f (n) = C ):

    A* expands all nodes with

    f (n) < C h(n) < C g(n),

    where g(n) is fixed. Since h2(n) > h1(n), less nodes are expanded.

    Matthias Althoff Informed Search 17. October 2014 18 / 22

  • Heuristic Functions

    Heuristics from Relaxed ProblemsIdea: The previous heuristics h1 and h2 are perfectly accurate for simplifiedversions of the 8-puzzle.

    Method: Formalize a problem definition and remove restrictions.

    Result:

    One obtains a relaxed problem, i.e. a problem with more freedom, whosestate-space graph is a supergraph of the original problem (see figure).

    An optimal solution in the original problem is automatically a solution in therelaxed problem, but the relaxed problem might have better solutions due toadded edges in the state-space graph.

    Hence, the cost of an optimal solution in the relaxed problem is anunderapproximative heuristic for the original problem.

    supergraph

    graph

    Matthias Althoff Informed Search 17. October 2014 19 / 22

  • Heuristic Functions

    Heuristics from Relaxed Problems: 8-Puzzle Example

    A tile can move from square A to B if 1 2, where

    1: B is blank

    2: A is adjacent to B

    We generate three relaxed problems by removing one or two conditions:

    1 remove 1: A tile can move from square A to B if A is adjacent to B.2 remove 2: A tile can move from square A to B if B is blank.3 remove 1 and 2: A tile can move from square A to B.

    From the first relaxed problem, we can generate h2 and from the thirdrelaxed problem, we can derive h1.

    If one is not sure which heuristics is better, one can apply in each step

    h(n) = max{h1(n), h2(n), . . . , hM(n)}.

    Why?

    Matthias Althoff Informed Search 17. October 2014 20 / 22

  • Heuristic Functions

    Heuristics from Pattern Databases

    Underapproximative heuristics can also be obtained from subproblems.

    Those solution costs are underapproximations and can be stored in adatabase.

    The number of subproblems has to be much less than the original problemsto not exceed storage capacities.

    The figure shows a subproblem of an 8-puzzle, where only the first 4 tiles have tobe brought into a goal position (the cost is obtained by optimal backwards searchfrom the goal):

    Start State Goal State

    1

    2

    3

    4

    6

    8

    5

    21

    3 6

    7 8

    54

    Matthias Althoff Informed Search 17. October 2014 21 / 22

  • Summary

    Summary

    Informed search methods require a heuristic function that estimatesthe cost h(n) from a node n to the goal:

    Greedy best-first search expands nodes with minimal h(n), which isnot always optimal.

    A* search expands nodes with minimal f (n) = g(n) + h(n). A* iscomplete and optimal for underapproximative h(n).

    The performance of informed search depends on the quality of theheuristics. Possibilities to obtain good heuristics are relaxedproblems and pattern databases.

    Matthias Althoff Informed Search 17. October 2014 22 / 22

    Informed Search StrategiesHeuristic FunctionsSummary