cs414-artificial intelligence - lecture 6: informed search...

29
CS414-Artificial Intelligence Lecture 6: Informed Search Algorithms Waheed Noor Computer Science and Information Technology, University of Balochistan, Quetta, Pakistan Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 1 / 30

Upload: others

Post on 05-Feb-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

  • CS414-Artificial IntelligenceLecture 6: Informed Search Algorithms

    Waheed Noor

    Computer Science and Information Technology,University of Balochistan,

    Quetta, Pakistan

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 1 / 30

  • Outline

    1 Informed Search

    2 Best First SearchA* Search ExampleMore on HeuristicReading

    3 Hill-Climbing SearchReadings

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 2 / 30

  • Outline

    1 Informed Search

    2 Best First SearchA* Search ExampleMore on HeuristicReading

    3 Hill-Climbing SearchReadings

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 3 / 30

  • Informed Search

    What we have seen so far are all those search algorithms thatoperate with out any domain knowledge, and try to solve theproblem in brute-force fashion.Such methods are insufficient for most problems specially whenthe problem is large and complex.Now we will look into another type of search techniques calledinformed search.

    DefinitionInformed Search Incorporates a heuristic in the search that determinesthe quality of any state in the search space. In a graph search, thisresults in a strategy for node expansion. The heuristic may considerthe problem knowledge to guide the search strategy.

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 4 / 30

  • Outline

    1 Informed Search

    2 Best First SearchA* Search ExampleMore on HeuristicReading

    3 Hill-Climbing SearchReadings

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 5 / 30

  • Best First Search I

    Best-FS tries to minimize some estimated measure (evaluationfunction) of the cost of the solution.

    Generally, in Best-FS, state space is evaluated on the basis of anevaluation function f (n) that incorporates an estimate of themeasure of the cost of the path from the current state to theclosest goal.

    Then the Best-FS may follow two strategies:

    1 Greedy Search: Expands the node closest to the goal, i.e.,f (n) = h(n).

    2 A∗ Search: Expands the node on the least cost solution path, i.e.,f (n) = g(n) + h(n).

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 6 / 30

  • Best First Search II

    where h(n) is heuristic function and g(n) is estimated path-costfrom start node to current node n.

    The h(n) can be an educated guess or estimate of the cheapestpath from the state at node n to the goal.

    In Romania example, this may be a straight line between state atnode n to goal.

    The g(n) is the cost from the start node to node n.

    The algorithm is often implemented by maintaining two list, anopen one and a closed one.

    Open list is a priority queue consist nodes yet to be visited sortedby their evaluation function.

    Closed list contains nodes that have already been evaluated.

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 7 / 30

  • Best First Search III

    Best-FS specializes to BFS when f (n) = h(n) and to UCS whenf (n) = g(n).

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 8 / 30

  • An Example

    Consider again the Romania example

    Bucharest

    Giurgiu

    Urziceni

    Hirsova

    Eforie

    NeamtOradea

    Zerind

    Arad

    Timisoara

    LugojMehadia

    DobretaCraiova

    Sibiu

    Fagaras

    PitestiRimnicu Vilcea

    Vaslui

    Iasi

    Straight−line distanceto Bucharest

    0160242161

    77151

    241

    366

    193

    178

    253329

    80199

    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

    Figure : Romania map with SLD

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 9 / 30

  • Greedy Fashion

    Rimnicu Vilcea

    Zerind

    Arad

    Sibiu

    Arad Fagaras Oradea

    Timisoara

    Sibiu Bucharest

    329 374

    366 380 193

    253 0

    Rimnicu Vilcea

    Zerind

    Arad

    Sibiu

    Arad Fagaras Oradea

    Timisoara

    329 374

    366 176 380 193

    Zerind

    Arad

    Sibiu Timisoara

    253 329 374

    Arad

    366

    (a) The initial state

    (b) After expanding Arad

    (c) After expanding Sibiu

    (d) After expanding Fagaras

    Figure : In the greedy fashion

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 10 / 30

  • Outline

    1 Informed Search

    2 Best First SearchA* Search ExampleMore on HeuristicReading

    3 Hill-Climbing SearchReadings

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 11 / 30

  • A* Search Example(a) The initial state

    (b) After expanding Arad

    (c) After expanding Sibiu

    Zerind

    Arad

    Sibiu Timisoara

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

    Arad

    366=0+366

    (d) After expanding Rimnicu Vilcea

    (e) After expanding Fagaras

    (f) After expanding Pitesti

    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

    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

    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

    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

    Figure : The A* implementationWaheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 12 / 30

  • Class Activity

    Apply A∗ & Greedy Best-FS on following problem

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 13 / 30

  • A* Search

    A* Search Rating

    Complete: YesTime Complexity: O(bd)Space Complexity: O(bd)Optimal: Yes.

    A* search algorithm have two flavors, the graph based and tree based.

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 14 / 30

  • Conditions for Optimality

    Admissibility and Consistency

    Admissibility: That the heuristic is admissible i.e., that h(n) will neveroverestimate the cost to reach the goal. For A*, h(n) is admissible,since straight line is the shortest path between any two points.Consistent: Consistency (also called monotonicity) describes that thecost along the path is increasing or decreasing. For A* graph version,the h(n) needs to be the increasing function of n along the path togoal, i.e., h(n) < c(n,a,n‘) + h(n‘).

    The A* tree search is optimal when h(n) is admissible.The A* graph search is optimal when h(n) is consistent.

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 15 / 30

  • Outline

    1 Informed Search

    2 Best First SearchA* Search ExampleMore on HeuristicReading

    3 Hill-Climbing SearchReadings

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 16 / 30

  • Heuristic for 8-Puzzle

    2

    Start State Goal State

    51 3

    4 6

    7 8

    5

    1

    2

    3

    4

    6

    7

    8

    5

    What possible heuristic h(n) you can propose?

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 17 / 30

  • Two Possible Heuristic for 8-Puzzleh1One possibility can be to count the number of misplaced tiles in thecurrent state n than the goal state. For initial state given aboveh1(n) = 6. Maximum possible h1(n) = 8, since there are eight tiles. Ish1 admissible?

    h2Second possibility can be the sum of the distance of tiles in the currentstate n from their goal. As the tiles in this problem can not movediagonal, they can either move horizontal or vertical therefore, thisdistance will be the count of horizontal and vertical distance/steps.This is also called Manhattan distance. The Manhattan distance from 1to 8 for above problem start state is:

    h2(n) = 4 + 0 + 3 + 3 + 1 + 0 + 2 + 1

    Is h2 admissible?Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 18 / 30

  • Outline

    1 Informed Search

    2 Best First SearchA* Search ExampleMore on HeuristicReading

    3 Hill-Climbing SearchReadings

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 19 / 30

  • Reading

    Read about Recursive best-first search (RBFS) and try on theRomania map example to develop your understanding.

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 20 / 30

  • Outline

    1 Informed Search

    2 Best First SearchA* Search ExampleMore on HeuristicReading

    3 Hill-Climbing SearchReadings

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 21 / 30

  • Hill-Climbing Search

    An iterative algorithm that tries to find maximum (or minimum)value of an objective/evaluation function.In each iteration it moves towards the direction of increasing value.Unlike Best-First, it does not maintain a search tree and usescurrent state node and its immediate neighbors.Each time it follows a single node and hence its OPEN list containonly one node.It is also sometime called a greedy local search.

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 22 / 30

  • Hill-Climbing Search

    currentstate

    objective function

    state space

    global maximum

    local maximum

    "flat" local maximum

    shoulder

    Problems:Since hill-climbing search considers immediate neighbor state that isits local, therefore it may end-up with a local optimal solution, i.e., localmaximum(or minimum) rather than global optimum solution.Solution: Random restart sometime solve the problem of localoptimum.

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 23 / 30

  • Ridges and Plateau

    Ridges: Result in the a series of local optima and it is very difficultfor greedy algorithm to overcome.Plateau: A plateau is the flat area of the state space with respectto the objective function. It can be a flat local optimum, for whichno uphill exist or a shoulder where progress is possible.The hill-climbing may get lost in plateau, one possible solution canbe to allow progress sideways, if plateau is shoulder.If plateau is flat local optima then it may result in an infinite loop,so we can then limit the number of sideway moves.

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 24 / 30

  • An Example

    h = 5 h = 2 h = 0

    Figure : 4-Queen starting from state with heuristic cost estimate of h(n) = 4

    In this problem our heuristic can be the number of conflicts we canobserve in the current state.Obviously then our goal is h(n) = 0.The hill-climbing algorithm will often (say 80% of the time for thisproblem) fails to find the solution.But when the algorithm solve the problem, it is very efficient evenin very large state space.

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 25 / 30

  • Discussion

    The hill-climbing algorithm explained today is incomplete, since itwill often lost in local optima.Multiple restarts (with random initial state in each restart) maysolve the problem.If p is the probability of success of hill-climbing algorithm then weneed at-least 1/p restarts.It is also not guaranteed to give optimal solution globally.However, local optimal is guaranteed.The time and space complexity both are linear, i.e., O(d) andO(b) respectively. Since the algorithm consider only one statenode at a time.

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 26 / 30

  • Outline

    1 Informed Search

    2 Best First SearchA* Search ExampleMore on HeuristicReading

    3 Hill-Climbing SearchReadings

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 27 / 30

  • Readings

    You are supposed to read an alternative approach called SimulatedAnnealing, and discuss in a report the characteristics and comparisonof hill climbing and simulated annealing algorithm. Your answer shouldcontain at least 100 words.

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 28 / 30

  • References I

    Stuart Russell and Peter Norvig.Artificial Intelligence: A Modern Approach.Pearson Education, Inc, USA, second edition, 2003.

    George F. Luger.Artificial Intelligence: Structures and Strategies for ComplexProblem Solving.Addison-Wesley Publishing Company, USA, 6th edition, 2008.

    Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 29 / 30

    Informed SearchBest First SearchHill-Climbing Search