lect topic3 search sem1 0910[1]

Upload: na2ry

Post on 30-May-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    1/33

    CSC 3301CSC 3301 -- Principles Of Artificial IntelligencePrinciples Of Artificial Intelligence

    STRUCTURE and STRATEGIES for STATE SEARCHSTRUCTURE and STRATEGIES for STATE SEARCHSPACESPACE

    Assoc. Prof. Dr. Normaziah Abdul Aziz

    Semester 1 2009/2010

    Note: Some parts of the lecture slides are referred to notes of Prof. Michael Pazzani, University of Irvine, California.

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    2/33

    The Relation of Problem SolvingThe Relation of Problem Solving

    And SearchAnd Search

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    3/33

    Search is a method that can be used by the computer toexamine a problem space in order to find a goal.

    Many problems in AI are represented as search spaces.

    A search space is a representation of the set of the possible

    choices in a given problem. One or more of the choices leads tothe solution to the problem.

    Problem Solving as Search (1)

    Example

    Find the word adab from an Arabic-English

    dictionary that has 500 pages.

    The page that is being searched for is called a goal,

    and it can be identified by seeing whether the word

    we are searching for is on the page or not.

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    4/33

    Problem Solving as Search (2)

    The aim of most search procedures is to identify one or more

    goals and identify one or more paths to those goals.

    Often the shortest path or path with least cost is selected as

    the best solution path.

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    5/33

    A search space is a representation of the set of the possiblechoices in a given problem. One or more of the choices leads

    to the solution to the problem.

    State spaces - A search space that consists of a set of states,

    connected by paths that represent actions.

    Many search problems can be represented by a state space,

    where the aim is to start with the world in one state and end

    with the world in another more desirable state.

    Problem Solving as Search (3)

    Initial state or start state the situation where we begin.

    Goal state the final situation that we want it to be.

    Illegal state the situation where we have to avoid. This is also

    referred to as constraint.

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    6/33

    Search Trees

    We can represent search space in the form of a tree. This tree

    is referred to as search tree. node represents a situation or a state. Several types of

    nodes: a root node, leaf node, goal node, parent node, child node

    path connects one node to another node

    branch the path between the parent node and child node(s). A

    tree can have deep orshallow branching and high number of

    branching in terms ofbreadth.

    Note: Goalnode(s) can be from anyof the

    leafnodes that has the value/contentof the

    problems goal

    A

    B

    D E

    C

    FG

    IH

    parent nodes

    leaf nodes

    root node

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    7/33

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    8/33

    Problem Solving Example 2

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    9/33

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    10/33

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    11/33

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    12/33

    Searching ApproachSearching Approach

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    13/33

    Data-driven search search process starts from aninitial state and uses actions that are allowed to move

    forward until a goal is reached. Also known as forward

    chaining.

    Goal-driven search search process begins from

    the goal and work back towards a start state, by

    seeing what moves could have led to the goal state.This is also known as backward chaining.

    Searching Approaches the broad perspective

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    14/33

    ExampleA system that analyses astronomical data and thus makes

    deduction about the nature of stars and planets. Here, there is a lot

    of data but it would not necessarily be given any direct goals. It is

    expected to analyse the data and determine conclusions of its own.

    In this case, data-driven search is appropriate.

    Other examples: weather forecast, _________________

    Data-driven is most useful when the initial data are provided,

    and it is unclear what the goal is.

    Searching Approaches (cont.)

    Goal-driven is most useful in situations where the goal can be

    clearly specified.

    ExampleA situation in medical diagnosis where the goal (i.e. the condition to

    be diagnosed) is known, but the data (i.e. the causes of the sickness

    condition) need to be discovered.

    Other examples: finding right path in a maze, ______________

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    15/33

    Generate and Test

    generates each nodes in the search space and test it to find out

    if it is a goal node. If it is, the search has succeed and need not

    carry on. Else, the process moves on to the next node.

    the simplest brute-force search (also known as exhaustive

    search).

    no additional knowledge besides knowing how to traverse he

    search tree, and how to identify leaf nodes and goal nodes.

    Techniques of Searching (1)

    3 properties for successful Generate & Test searching process:

    complete must generate all possible solution to avoid missing

    a suitable node

    non-redundant should not generate the same solution twice

    well informed should only propose suitable solutions & should

    not examine possible solution that do not match the search

    space.

    A

    B

    D E

    C

    FG

    IH

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    16/33

    Depth-First Search

    the search process follows each path to its greatest depthbefore moving on to the next path.

    if we start from the left side of a search tree and work

    towards the right, depth-first search goes all the way down

    the left-most path in the tree until the leaf node is reached. If

    this is a goal state, the search stops & success is reported.

    if the leaf node is not the goal state, search backtracks up

    to the next highest node that has unexplored path.

    A

    B

    D E

    C

    J

    H

    1

    8

    2

    5

    6

    3

    G

    I

    7

    4

    910 13

    12

    11

    14

    F

    KL

    15

    If node I is the goal node, hence node J, K

    & L need not be examined.

    ExamplesLocating files on a disk and web search

    engines.Other examples: ______________

    Techniques of Searching (2)

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    17/33

    Breadth-First Search

    the search process starts by examining all nodes one

    level (also known as ply) down from the root node.

    if the goal state is reached, success is reported. Else,

    search continues by expanding paths from all nodes in

    the current level down to the next level.

    search continues until a goal node is met and

    success is reported. Failure is reported when all nodes

    have been examined but no goal node has been found.A

    B

    DE

    C

    J

    H

    1

    11

    3

    10G

    I7

    4

    2

    65

    F

    KL

    89

    Techniques of Searching (3)

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    18/33

    Comparison between Depth-First and

    Breadth-First Search

    Situation Depth first performance Breadth first performance

    Some path are extremely

    long or even infinite

    All path are of similar

    length

    All path are of similar

    length & all path lead to a

    goal state

    High branching factor

    Bad Well

    WellWell

    WellTime & memory

    wasted

    PoorDepends on otherfactors

    A

    B

    D E

    C

    FG

    IH

    Depth-first search is usually simpler to implement than breadth-first search.

    Depth-first search requires less memory usage because it needs to store only theinformation the current path it is exploring.

    Breadth-first search needs more memory to store information of all paths that reach

    the current depth.

    Techniques of Searching (4)

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    19/33

    Depth-First Search with Iterative Deepening

    Depth-First Search Iterative Deepening (DFID) is also calledIterative Deepening Search (IDS) is an exhaustive search

    technique that combines both dept-first with breadth-first search.

    DFID technique involves repeatedly carrying out depth-first

    search on the tree until a depth bound that is set.

    The depth bound forces a failure on a search space once it gets

    below a certain level. This causes a breadth-like sweep of the

    search space at that particular depth level.

    This technique is suitable when it is known that a solution lies

    within a certain depth or when time constraints. such as thoseoccur in an extremely large search space.

    ExamplesIn playing chess, we can limit the number of states that

    are to be considered; then a depth-first search with a

    depth bound can be applied.

    Techniques of Searching (5)

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    20/33

    Properties of Search Approaches

    Several important properties that search methods should have in

    order to be most useful. How efficient the method is, are based on time

    and space required.

    Complexity. The time complexity is a related to the length of time that

    the method takes to to find a goal state. The space complexity is related

    to the amount of memory that the method needs to use.

    Big-O notation is used to describe the complexity of a method. As

    example, breadth-first search has a time complexity ofO(b ), where

    b is the branching factorof the tree and d is the depth of the goal

    node in the tree.

    Depth-first is efficient in space but not efficient in terms of time.

    Complexity must be balanced against the adequacy of the solution

    generated by the method. Ex. A very fast search methodmaynot

    find the best solution, and a search method that examines all

    possible solution will guarantee to find the best solution though it is

    verytime-consuming.

    d

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    21/33

    Completeness. A search method is considered complete if it is

    guaranteed to find a goal state if one exists.

    Breadth-first search is complete but depth-first search is not

    complete because it may explore a path of infinite length and

    never find a goal node that exist on another path.

    this is a desirable property because the objective of running asearch is to find the solution (goal state)).

    Properties of Search Approaches

    Optimality. A search method is optimal if it is guaranteed to find

    the best solution that exists. It will find the path to a goal state that

    involves taking the least number of steps.

    The method may not be efficient it may take longer time for

    an optimal search to identify the optimal solution but once it

    has found, it is guaranteed to be the best one.

    Breadth-first search is an optimal method.

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    22/33

    Properties of Search Approaches

    Irrevocablility. A search method that do not use backtracking &

    therefore examine just a path not more than once.

    A

    B

    D E

    C

    J

    H

    1

    8

    2

    5

    6

    3

    G

    I

    7

    4

    9

    1013

    12

    11

    14

    F

    KL

    15

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    23/33

    Some Calculations

    For a tree of depth d and with a branching factor of b, the total

    number of nodes is:1 root node

    b nodes in the first layer

    b nodes in the second layer

    b nodes in the n layer

    Therefore, the total number of nodes is

    1 + b + b + b+ + b

    which is a geometric progression equal to

    2

    2

    n th

    d3

    1 - bd+1

    1 - b

    ExampleA tree with depth of2 with a branching factor of2, has

    1 8

    1 2= 7 nodes

    Using depth-first or breadth-first search, the total number

    of nodes to be examined is7

    .

    Calculating the number of nodes that need to be examined:

    A

    B

    D E

    C

    F G

    IH

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    24/33

    Some Calculations

    Using DFID, nodes need to be examined more than once, resultingto the following progression: number of nodes is:

    (d + 1) + b (d) + b (d 1) + b (d 2)+ + b

    Hence, DFID has a time complexityofO(b ). It has the memory

    efficiencyof depth-first search because itonlyeverneeds to storeinformation about the currentpath.

    Hence, its space complexityis O(bd).

    2

    n

    d3

    Example

    A tree with depth of4 with a branching factor of10. Using

    DFID, it has the following number of nodes to be examined

    (4+1) +10(4) +100(3) +1000(2) +10,000

    = 12,345 nodes

    Calculating the number of nodes that need to be examined:

    d

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    25/33

    Using Heuristics for SearchUsing Heuristics for Search

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    26/33

    Heuristic a commonsense rule (or set of rules) intended to

    increase the success probability of solving some problems

    In the context of state space search, heuristic are rules for

    choosing those branches in a state space that are most likely to lead

    to an acceptable problem solution.

    The heuristic used in search is one that provides an estimate of

    the distance from any given node to a goal node. This estimate

    assist us to get better results than our pure/random guesswork.

    Heuristic Search

    Example

    A problem may not have an exact solution because of inherentambiguities in the problem statement or available data. Medical

    diagnosis is an example. A given set of symptoms may have

    several possible causes; doctors use heuristics to choose the most

    likely diagnosis and formulate a plan of treatment.

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    27/33

    Informed and Uninformed Search Methods

    Search method is informed if it uses additional informationabout nodes that have not yet been explored to decide which nodes

    to examine next.

    If the search method is not informed, it is referred to as

    uninformed orblind search method.

    Search method that uses heuristics are informed.

    Best-first search is an example ofinformed search, whereas

    breadth-first and depth-first are uninformed or blind.

    A heuristic, h is said to be more informed than another heuristicj,if h(node) < = j(node) for all nodes in the search space.

    The more informed a search method is , the more efficiently it will

    search.

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    28/33

    Hill Climbing

    Hill climbing is an informed search method. It uses informationabout the search space to search in a reasonably efficient manner.

    Hill climbing strategies expand the current state of search and

    evaluate its children nodes. The best child is selected for further

    expansion; neither its sibling or parent are retained.

    In examining a search tree, hill climbing will move to the first

    successor node that is better than the current node.

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    29/33

    Best-First Search

    Best-first search - employs a heuristic in a similar manner to hillclimbing. The difference is that with best-first search the queue is

    sorted after the new paths have been added to it, rather than adding

    a set of sorted paths.

    Best-first search follows the best path available from the current

    (partially developed) tree, rather than always follow a depth-firstapproach.

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    30/33

    Identifying Optimal Paths

    Optimal path path that involves the lowest cost or travels theshortest distance from the start to goal node.

    Sophisticated techniques to identify optimal paths:

    A*

    Uniform cost search (Branch & Bound)

    Greedy search

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    31/33

    The Missionaries and Cannibals problem

    3 missionaries and 3 cannibals are on the one side of a river,

    with a canoe. They all want to get to the other side of the river.

    The canoe can only hold 1 or2 people at a time. At no time

    should there be more cannibals than missionaries on either

    side of the river, as this would probably result in the

    missionaries being eaten.

    What is the start state? What is the goal state?

    What is the state space? What is the state that we have

    to avoid or the illegal state?

    Start state: 0, 0, 0 Goal state: 3, 3, 1

    State space: All possible states in between.

    Illegal state orconstraint: 2, 1, 1 or 2, 1, 0

    Problem Solving Example

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    32/33

    ExerciseExercise

  • 8/9/2019 Lect Topic3 Search Sem1 0910[1]

    33/33

    The Missionaries and Cannibals problem

    3, 3, 1 0, 0, 0

    3, 3, 10, 0, 0

    River

    bank A

    C, M, Canoe C, M, Canoe

    Initial

    state

    Goal

    state

    River

    bank B

    Apply any of the operators given to

    move from the Initial state to the

    Goal state:

    1) Move 1 C totheothersideoftheriver

    2) Move2 C totheothersideoftheriver

    3) Move 1 M totheothersideoftheriver

    4) Move2 M totheothersideoftheriver

    5) Move 1 C & 1M totheothersideofthe

    river.