Top Banner

of 68

AI Good Notes

Apr 14, 2018

Download

Documents

Syaza Ibrahim
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 7/27/2019 AI Good Notes

    1/68

    Savefrom:www.uotechnology.edu.iq

    2ndclass

    AIstrategiesandalgorithms..:

  • 7/27/2019 AI Good Notes

    2/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Artificial Intelligence (A.I)

    Artificial Intelligence (A.I) :- Is the branch of computer science that concerned with theautomation of intelligence behaviour.

    A.I :- Is simply a way of making a computer think.

    A.I:- Is the part of computer science concerned with designing intelligent computer system thaexhibit the character static associate with intelligent in human behavior. This require many

    process:-1- learning :- acquiring the knowledge and rules that used these knowledge.

    2- Reasoning:- Used the previous rules to access to nearly reasoning or fixed reasoning.

    A.I Principles:-1- The data structures used in knowledge representation.

    2- the algorithms needed to apply that knowledge.3- the language and programming techniques used their implementation.

    A.I Application:-1- Game application.

    2-Automated reasoning and theorm proving.3-Perception.4-Expert Systems

    5- Natural language understanding and semantic modeling.6- planning and robotics

    machine learning

    language & environment for A.IPattern recognition

    A.I & Philosophy.

    A.I Branches:-1- Logical A.I

    2-Search3- Representation

    4-Inference5-knowledge & Reasoning

    6- Planning

  • 7/27/2019 AI Good Notes

    3/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    7- Epistemology.

    8- Ontology.

    9- Heuristics.10-Genetig Programming.

    Search Algorithms:

    To successfully design and implement search algorithms, a programmer must be able to

    analyze and predict their behavior.Many questions needed to be answered by the algorithm these include:

    - is the problem solver guranteed to find a solution?- Will the problem solver always terminate , or can it become caught in an infinite loop?

    - When a solution is found , is it guaranteed to be optimal?- -What is the complexity of the search process in terms of time usage ? space search?

    - How can the interpreter be designed to most effectively utilize a representation language?

    -State Space Search

    The theory of state space search is our primary tool for answering these questions , by

    representing a problem as state space graph, we can use graph theory to analyze the structure

    and complexity of both the problem and procedures used to solve it.

    - Graph Theory:-

    A graph consist of a set of a nodes and a set of arcs or links connecting pairs of nodes. Thdomain of state space search , the nodes are interpreted to be stated in problem_solving

    process, and the arcs are taken to be transitions between states.

    Graph theory is our best tool for reasoning about the structure of objects and relations.

    Nodes={a,b,c,d,e}

    Arcs={(a,b), (a,d),(b,c),(c,b),(d,e),(e,c),(e,d)}

    e

    ab

    c

    d

  • 7/27/2019 AI Good Notes

    4/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Nodes=={a,b,c,d,e,f,g,h,i}

    Arcs={(a,b),(a,c),(a,d),(b,e),(b,f),(c,f),(c,g),(c,h),(c,i),(d,j)}

    State Space Representation of Problems:-A state space is represented by four_tuple [N,A,S,G,D], where:-

    N is a set of nodes or states of the graph. These correspond to the states in a problemsolving process.

    A is the set of arcs between the nodes. These correspond to the steps in a problem solving process.

    S a nonempty subset of N ,contains the start state of the problem.

    GD a nonempty subset of N ,contains the goal state of the problem.

    A solution path:- Is a path through this graph from a node S to a node in GD.

    Example :- Traveling Saleman ProblemStarting at A , find the shortest path through all the cities , visiting each city exactly

    once returning to A.

    b

    cd

    e f g h i

    a

  • 7/27/2019 AI Good Notes

    5/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    An instance of traveling Saleman Problem

    The complexity of exhaustive search in the traveling Saleman is (N-1)!, where N is the N

    of cities in the graph. There are several technique that reduce the search complexity.

    1- Branch and Bound Algorithm :-Generate one path at a time , keeping track of the best circu

    so far. Use the best circuit so far as a bound of future branches of the search .

    figure below illustrate branch and bound algoritm.

    a

    e

    d

    c

    b

    75

    100

    50

    100

    50

    125

    300

  • 7/27/2019 AI Good Notes

    6/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    a b c d e a=375 a b c e d a =425 a b d c e a=474

    2- Nearest Nieghbor Heuristic: At each stage of the circuit , go to the nearest unvisited city. T

    strategy reduces the complexity to N, so it is highly efficient , but it is not guranteed to find the

    shortest path , as the following example:

    c

    a

    d

    c

    e

    a

    e

    b

    c

    d

    e d

    a

    100

    150

    250

    300

    375

    125100

    75

  • 7/27/2019 AI Good Notes

    7/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Cost of Nearest neighbor path is a e d b c a=550Is not the shortest path , the comparatively high cost of arc (C,A) defeated the heuristic.

    a

    e

    d

    c

    b

    75

    100

    50

    100

    50

    125

    300

  • 7/27/2019 AI Good Notes

    8/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    State Space Searchs examples:-

    1) Monkey and Banana ProblemThere is a monkey at the door in to a room. In the middle of the room a banana is

    hunging from the ceiling. The monkey is hungry and wants to get the banana , but he cann

    stretch high enough from the floor. At the window of the room there is a box the monkey

    may use.

    The monkey can perform the following actions:-

    walk on the floor

    Climb the box

    Push the box a round (if it is already at the box).

    Grasp the banana if standing on the box directly under the banana.

    The question is (Can the monkey get the banana?), the initial state of the world is

    setermind by:-

    1- Monkey is at door.

    2- Monkey is on floor.

    3- Box is at Window.

    4- Monkey does not have banana

    Initial state :- State (at door, on floor, at window, has not).

    At door horizontal position of monkeyOn floor vertical position of monkey

    At window Position of box

    Has not monkey has not banana

    Goal state:-State (_,_,_,has).

    State1 state2

  • 7/27/2019 AI Good Notes

    9/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Move (state1, move, state2).

    State1: is the state before the move.

    Move: is the move executed.

    State2:is the state after the move.

    To answer the question :- Can the monkey in some initial state (state) get the banana?

    This can be formulated as a predicate canget(state).The program canget can be based on

    two observation:-

    1) The program:- for any state in which the monkey already has the banana. The predicat

    canget must certainly be true , no move is needed in this case:

    Canget(state( state(_,_,_,has)).

    2) In other cases one or more moves are necessary.

    Canget (state):-move (state1,move,state2),canget (state2).

    A program of monkey and banana problem:-

    Move (state (at door , on floor , at window , has not), walk, state (at box , on floor , at

    window , has not)).

    Move (state (at box , on floor , at window , has not), push , state (middle, on floor, middle

    has not)).

    Move (state (middle, on floor, middle, has not), climb, state (middle, on box, middle, has

    not)).Move (state (middle, on box, middle, has not),grasp, state (middle, on box, middle, has

    not)).

    Canget( state(_,_,_,has)).

    Canget (State1):- move (state1,move,state2), canget (state2).

  • 7/27/2019 AI Good Notes

    10/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Goal= canget (state(at door, on floor, at window ,has not)).

    The monkey and banana problem can be represented by the following state space:-

    No move possible

    state (at door , on floor , at

    window , has not)

    state (at box , on floor , at

    window , has not)

    , state (middle, on floor, middle,has not)

    state (middle, on box, middle,

    has not)

    state (middle, on box, middle,

    has not)

    State(at window, on box,

    at window, has not).

    Push ( at box , middle)climb

  • 7/27/2019 AI Good Notes

    11/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    2) A water Jug Problem

    You are give two jugs , a 4-gallon one and a 3-gallon one. Neither has any measuringmarkers on it. There is a pump that can be used to fillthe jugs with water. How can you get

    exactly 2 gallons of water in to the 4-gallon jug?

    The state space for this problem can be described as the set of ordered pairs of integers (x,y) ,

    such that x=0,1,2,3 or 4 and y=0,1,2, or 3; x represent the number of gallons of a water in the 4

    gallon jug , and y represents the quantity of water in 3-gallon jug. The start state is (0,0). The

    goal state is (2,n) for any value of n ( since the problem does not specify how many gallons ne

    to be in the 3-gallon jug).

    1) (X,Y: X0) (X,Y-D) Pour some water out of the 3- gallon jug

    5) (X,Y:X>0) (0,Y) Empty the 4-gallon jug on the ground

    6) (X,Y: Y>0) (X,0) Empty the 3-gallon jug on the ground

    7) (X,Y: X+Y>=4 ^ Y>0) (4,Y-(4-X)) pour water from the 3-gallon jug into the 4-gallo

    jug until the 4-gallon jug is full.

    8) (X,Y:X+Y0) (X-(3-Y),3) pour water from the 4-gallon jug into the 3-

    gallon jug until the 3-gallon jug is full.

    9) (X,Y:X+Y0) (X+Y,0) pour all the water from 3-gallon jug into the 4-gallon jug.

    10) (X,Y: X+Y0) (0,X+Y) pour all the water from 4-gallon jug into the 3-

    gallon jug.

  • 7/27/2019 AI Good Notes

    12/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    (0,0)

    0,3 4,0

    0,0 3,0 4,3 4,3 1,3 0,0

    0,3 4,00,0 0,3

    3,3 1,0

    0,3 3,0 1,3 0,04,2 0,1

    1,0

    4,0 3,3 0,0 4,10,2

    4,0 0,1

    4,2 0,0

    The goal

    The goal

    The solutions of water jug problem

    2,3

    2,0

  • 7/27/2019 AI Good Notes

    13/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Backtracking Search Algorithm

    Backtracking search begins at the start state and pursues a path until it reaches a goal or "dea

    end", if it reaches a goal , it returns the solution path and quits. If it reaches a dead end , it

    backtracks to the most recent node in the path having unexamined siblings and continues do

    on of those branches.

    The backtrack algorithm uses three lists plus one variable:

    SL, The state list, lists the states in the current path being tried , if a goal is found , SL contai

    the ordered list of states on the solution path.

    NSL, The new state list, contains nodes a waiting evaluation, nodes whose descendants have

    not yet been generated and searched.

    DE, dead ends, lists states whose descendants have failed to contain a goal end. If these state

    are encountered again, they will be immediately eliminated from consideration.

    CS, The current state.

    The backtrack Algorithm

    {

    SL:=[start]; NSL:=[start]; DE:=[ ]; CS:=start;

    While NSL!=[]

    {IF CS=goal (or meets goal description)

    Return SL; //SUCCESS//

    IF CS has no children ("except on DE, SL, NSL).

    {

    WHILE SL!= [] and CS=first element of SL

    {

    Add CS to DE; //Dead end//

  • 7/27/2019 AI Good Notes

    14/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Remove first element of SL; //Backtrack//

    Remove first element of NSL;

    CS:=first element of NSL;}

    Add CS to SL;

    }

    Place children of CS (except those on DE, SL,NSL) on NSL

    CS:= first element of NSL;

    Add CS to SL;

    }

    } [End algorithm]

    Return fail; //failure//

    Example: A trace of backtrack Algorithm

    Iteration CS SL NSL DE

    0 A [A] [A] [ ]

    1 B [B A] [B C D A] [ ]

    2 E [E B A] [E F B C D A] [ ]

    3 H [H E B A] [H I E F B C D A] [ ]

    4 I [I E B A] [I E F B C D A] [H]

    5 F [F B A] [F B C D A] [E I H]

    6 J [J F B A] [J F B C D A] [E I H]

    7 C [C A] [C D A] [B F J E I H]

    8 G [G C A] [G C D A] [B F J E I H]

    A

    B C D

    GF

    E

    H I J

  • 7/27/2019 AI Good Notes

    15/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Blind Search

    This type of search takes all nodes of tree in specific order until it reaches to goal. The order c

    be in breath and the strategy will be called breadth first search, or in depth and the strategy w

    be called depth first search.

    Breadth First Search

    In breadth first search , when a state is examined , all of its siblings are examined befo

    any of its children. The space is searched level-by-level , proceeding all the way across one le

    before doing down to the next level.

    Breadth first search Algorithm

    begin

    open: = [start];

    closed: = [ ];

    while open [ ] do

    begin

    remove left most state from open, call it x;

    if x is a goal the return (success)

    else

    begin

    generate children of x;

    put x on closed;

    eliminate children of x on open or closed;

    put remaining children on right end of open

    end

  • 7/27/2019 AI Good Notes

    16/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    end

    return (failure)

    end.

    A

    B C D

    E F G H F J

    K L M N O P Q R

    Y

    Fig (2 1): Breadth first search

    1 Open = [A]; closed = [ ].

    2 Open = [B, C, D]; closed = [A].

    3 Open = [C, D, E, F]; closed = [B, A].

    4 Open = [D, E, F, G, H]; closed = [C, B, A].

    5 Open = [E, F, G, H, I, J]; closed = [D, C, B, A].

    6 Open = [F, G, H, I, J, K, L]; closed = [E, D, C, B, A].

    7 Open = [G, H, I, J, K, L, M]; closed = [F, E, D, C, B, A].

    8 Open = [H, I, J, K, L, M, N,]; closed = [G, F, E, D, C, B, A].9 and so on until either U is found or open = [ ].

  • 7/27/2019 AI Good Notes

    17/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Depth first search

    In depth first search, when a state is examined, all of its children and their descendants aexamined before any of its siblings.

    Depth first search goes deeper in to the search space when ever this is possible only when

    further descendants of a state cam found owe its

    Depth first search Algorithm

    BeginOpen: = [start];

    Closed: = [ ];

    While open [ ] do

    Remove leftmost state from open, callitx;

    Ifxis agoal then return (success)

    Else begin

    Geerate children of x;

    Put x on closed;

    Eliminate children of x on open or closed; put remaining children on left end of open end

    End;

    Return (failure)

    End.

  • 7/27/2019 AI Good Notes

    18/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    A

    B C D

    E F G H I J

    K L M N O P Q R

    S T U

    Fig (2 2) Depth first search

    1 Open = [A]; closed = [ ].

    2 Open = [B, C, D]; closed = [A].

    3 Open = [E, F, C, D]; closed = [B, A].

    4 Open = [K, L, F, , D]; closed = [E, B, A].

    5 Open = [S, L, F, C, D]; closed = [K, E, B, A].

    6 Open = [L, F, C, D]; closed = [S, K, E, B, A].

    7 Open = [T, F, C, D]; closed = [L, S, K, E, B, A].

    8 Open = [F, C, D,]; closed = [T, L, S, K, E, B, A].

    9 Open = [M, C, D] as L is already on; closed = [F, T, L, S, K, E, B, A].

  • 7/27/2019 AI Good Notes

    19/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Heuristic Search

    A heuristic is a method that might not always find the best solution but is guaranteed to fi

    a good solution in reasonable time. By sacrificing completeness it increase efficiency. Heuristic

    search is useful in solving problems which:-

    Could not be solved any other way.

    Solution take an infinite time or very long time to compute.

    Heuristic search methods generate and test algorithm , from these methods are:-

    1- Hill Climbing.

    2- Best-First Search.

    3- A and A* algorithm.

    1) Hill Climbing

    The idea here is that , you dont keep the big list of states around you just keep track of the one state you

    are considering , and the path that got you there from the initial state. At every state you choose the state

    leads you closer to the goal (according to the heuristic estimate ), and continue from there.

    The name Hill Climbing comes from the idea that you are trying to find the top of a hill , and you go in

    the direction that is up from wherever you are. This technique often works, but since it only uses local

    information.

    The smaller peak is an example of a local maxima in a domain (or local minima). Hil

    climbing search works well (and is fast ,takes a little memory) if an accurate heuristic measure i

    available in the domain , and there are now local maxima.

  • 7/27/2019 AI Good Notes

    20/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Hill Climbing Algorithm

    BeginCs=start state;

    Open=[start];

    Stop=false;

    Path=[start];

    While (not stop) do

    {

    if (cs=goal) then

    return (path);

    generate all children of cs and put it into openif (open=[]) then

    stop=true

    else

    {

    x:= cs;

    for each state in open do

    {

    compute the heuristic value of y (h(y));

    if y is better than x then

    x=y}

    if x is better than cs then

    cs=x

    else

    stop =true;

    }

    }

    return failure;

    }

    A trace of Hill Climbing Algorithm

    Searches for R4 (local maxima)

  • 7/27/2019 AI Good Notes

    21/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Open Close XA _ A

    C3 B2 D1 A C3

    G4 F2 A C3 G4

    N5 M4 A C3 N5

    R4 S4 A C3 G4 N5 R4

    The solution path is : A-C3-G4-N5

    Hill climbing Problems:-

    Hill climbing may fail due to one or more of the following reasons:-1- a local maxima: Is a state that is better than all of its neighbors but is not better than som

    other states.

    A

    B2 C3 D1

    E3 L4 G4 F2Q5 H1 P7

    T5 R4N5

    R4 S4

    U7 O6

    R4

    M4

  • 7/27/2019 AI Good Notes

    22/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    2- A Plateau: Is a flat area of the search space in which a number of states have the same be

    value , on plateau its not possible to determine the best direction in which to move.

    3- A ridge: Is an area of the search space that is higher than surrounding areas , but that can

    not be traversed by a single move in any one direction.

    A

    B 10 C 20 D 15E 25

    F 10 G 30 I 15J 20

    K 20L 15

    O 20 L 25P 15

    M 20

    R 10

    S 15N 35

    X 15 Y 25Z 20

    ZX

    Goal state

    A

    B 20 C 20 D 20 E 20

  • 7/27/2019 AI Good Notes

    23/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    2) Best-First-Search

    {

    Open:=[start];Closed:=[];

    While open [] do

    {

    Remove the leftmost from open, call it x;

    If x= goal then

    Return the path from start to x

    Else

    {

    Generate children of x;

    For each child of x do

    Do case

    A

    B 10 C 20 D 15E 25

    F 10 G 20 H 25J 20

    I 10H 15

  • 7/27/2019 AI Good Notes

    24/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    The child is not already on open or closed;

    { assign a heuristic value to the child state ;Add the child state to open;

    }

    The child is already on open:

    If the child was reached along a shorter path than the state currently on open then give th

    state on open this shorter path value

    The child is already on closed:

    If the child was reached along a shoreter path than tha state currently on open then {

    Give the state on closed this shorter path value

    Move this state from closed to open

    }

    }

    Put x on closed;

    Re-order state on open according to heuristic (best value first)

    }

    Return (failure);

    }

  • 7/27/2019 AI Good Notes

    25/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    open closed

    [A5] [ ]

    [B4 C4 D6] [A5]

    [C4 E5 F5 D6] [B4 A5]

    [H3 G4 E5 F5 D6] [C4 B4 A5]

    [O2 P3 G4 E5 F5 D6] H3 C4 B4 A5]

    P3 G4 E5 F5 D6] [O2 H3 C4 B4 A5]

    The solution path is: A5 - B4 - C4 - H3 O2- P3

    A

    B4 C4 D6

    E5 F5 G4 H3I J

    T5 R4 N P3 Q

    R4O2

  • 7/27/2019 AI Good Notes

    26/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    8_PUZZLE AS APPLICATION OF (BFS)

  • 7/27/2019 AI Good Notes

    27/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

  • 7/27/2019 AI Good Notes

    28/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Implementing Heuristic Evaluation Function:-

    )Best First Search()node(.

    ...)(

    )Heuristic function(..

    -:Heuristic FunctionFn= g(n) + h(n)

    g(n):- Measures the actual length of path from any state (n) to the start state.

    H(n):- is a heuristic estimate of the distance from state n to the goal.

    Best-FirstHeuristic Function)1(A- Algorithm.

    A Algorithm

    Trace of A- Algorithm (Search

    Connect(a,b,3)

    Connect(a,c,2)

    Connect(a,d,4)

    Connect(b,e,7)

    Connect(b,f,7)Connect(c,g,3).

    Connect(c,h,2).

    Connect(d,I,4)

    Connect(d,j,3).

    Connect(f,k,3).

  • 7/27/2019 AI Good Notes

    29/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Connect(h,k,1).

    Connect(I,k,2).

    The tree after evaluation function calculation is :

    Connect(a,b,4)

    Connect(a,c,3)

    Connect(a,d,5)

    Connect(b,e,9)

    Connect(b,f,9)

    Connect(c,g,5).

    Connect(c,h,4).Connect(d,I,6)

    Connect(d,j,5).

    Connect(f, k6).

    Connect(h, k4).

    Connect(I, k5).

    A

    B3 C2 D4

    E7 F7 H2 G3I4 J3

    K3 K1 K2

  • 7/27/2019 AI Good Notes

    30/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Open Close

    [A] [ ]

    [C3 B4 D5] [A]

    [H4 B4 D5 G5] [C3 A]

    [K4 B4 D5 G5] [H4 C3 A]

    [K4 H4 C3 A]

    The path is : A-C3- H4- K4

    A* Algorithm

    Definition:-if A used with an evaluation function in which h(n) is less than or equal to the cost

    the minimal path from n to the goal , the resulting search algorithm is called A* Algorithm.

    A

    B 4 C3 D5

    E 9 F9 H 4 G 5I 6 J 5

    K6 K4 K5

  • 7/27/2019 AI Good Notes

    31/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    A* Algorithm Properties:-

    1) AdmissibilityA search algorithm is admissible if it is guaranteed to find a minimal cost to a solution

    whenever such a path exists.

    Admissibility Definition:

    Consider the evaluation function f(n)=g(n)+h(n).

    In determining the properties of admissible heuristics it is useful to define first an evaluation

    function f*:

    F*(n)=g*(n)+h*(n)

    Where:

    g*(n) is the cost of the shortest path from the start node n.

    h*(n) returns the actual cost of the shortest path from n to the goal.

    F*(n) is the actual cost of the optimal path from a start node to a goal node that passes through

    node n.

    If we employ best-first search with the evaluation function F* ,the resulting search strategy is

    admissible.

    In A algorithm , g(n) , The cost of the current path to state n , is a reasonable estimate of g*(n),

    but they may not be equal g(n)g*(n).These are equal only if the graph search has discovered th

    optimal the optimal path to state n.

    Similarly, We replace h*(n) with h(n) , a heuristic estimate of the minimal path to a goal state. I

    A Algorithm uses an evaluation F in which h(n) h* (n) it is called A* Algorithm .So all A*

    Algorithm are admissible.

  • 7/27/2019 AI Good Notes

    32/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    2) Monotonicity

    A heuristic function h is monotone if :-

    a. For all state ni and nj , where nj is a descendant of ni

    h(ni)-h(nj) cost(ni,nj).

    Where cost (ni,nj) is the actual cost of going from state ni to nj.

    b. The heuristic evaluation of the goal state is zero , or h(goal )=0.

    3) Informedness

    For two A* heuristics h1 and h2 , if h1(n) h2(n), for all states n in the search space , heuristics

    is said to be more informed than h1.

    Open Close

    [A] [ ]

    [C2+2 B3+4 D4+4] [A]

    [C4 B7 D8] [A]

    [H2+1G3+3 B7 D8] [C4 A]

    [H3G6 B7 D8] [C4 A]

    [K1+0 G6 B7 D8] [H3 C4 A]

    [K1G6 B7 D8] [K1 H3 C4 A]

  • 7/27/2019 AI Good Notes

    33/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Complex Search Space and problem solving Approach

    Tic Tac Toe Game

    The complexity of the search space is 9!9! =9*8*7*.*1

    Therefore it is necessary to implement two conditions:

    1- Problem reduction2- Guarantee the solution

  • 7/27/2019 AI Good Notes

    34/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

  • 7/27/2019 AI Good Notes

    35/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Using Heuristic in Games

    1- Minimax Search

    Maximizing for MAX parents and Minimizing for MIN, The values go backup the graph

    the children of the current state. These values are then used by the current state to select among

    children. Figure below shows minimax on hypothetical state space with four-ply-look-ahead.

    Implementing (nim game) with Minimax Search

  • 7/27/2019 AI Good Notes

    36/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    2- Alpha -Beta Search

    Maxminimax(.

    nod(.

  • 7/27/2019 AI Good Notes

    37/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    A has =3 (A will be no larger than 3)

    B is pruned since 5>3Chas =3 (C will be no smaller than 3)

    D is pruned, since 0

  • 7/27/2019 AI Good Notes

    38/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

  • 7/27/2019 AI Good Notes

    39/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

  • 7/27/2019 AI Good Notes

    40/68

    . MIN MAX -. MIN

    .MAX MIN -:

    By : Nuha Jameel Ibrahim

    A.I Strategies and Algorithms Lectures

  • 7/27/2019 AI Good Notes

    41/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Problem Reduction1. AO* (And\Or)

    The A* Algorithm have considered search strategies for OR graph which we want to find

    single path to a goal, another kind of structure, the AND-OR graph (or tree), is useful

    representing the solution of problems that can be solved decomposing them into a set

    smaller problems, all of which must then be solved. This decomposition or reduction genera

    arcs that we will call AND arcs. Just as in an OR graph, several arcs may emerge from a sin

    node, indicating a variety of ways in which the original problem might be solved. This is w

    the structure is called not simply an AND graph but rather an AND-OR graph.

    In order to find solution in an AND-OR graph, we need an algorithm similar to A*, but w

    the ability to handle the AND arc appropriaty. This algorithm should find a path from t

    starting node of the graph to a set of nodes representing solution states.

    The graph below illustrate why the A* Algorithm not adequate for searching AND-OR graph

  • 7/27/2019 AI Good Notes

    42/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    ())9*f))node Cnode D()AND arc(f*)node D(D

    ))38))17*f))node B.FEBAB*fD*f

    To search an implicit AND-OR graph, It is necessary to do three things at each step:

    1- Traverse the graph, starting the initial node and following the current best path, and

    accumulate the set of nodes that are on that path and have not yet been expanded.

    2- Pick one of these unexpanded nodes and expand it. Add its successors to the graph and

    compute f*.

    3- Change the f* estimate of the newly expanded node to reflect the new information provid

    by its successors.

    2.Constraint Satisfaction

    Many problems in AI can be viewed as problems ofConstraint Satisfaction in which the goato discover some problem state that satisfies a given set of constraints.

    By viewing a problem as one of constraint satisfaction, it is often possible to reduce substantia

    the amount of search that is required as compared with a method that attempts to form partsolutions directly by choosing specific values for components of the eventual solution.

    Constraint Satisfaction is a search procedure that operate in a space of constraints. The initial stcontains the Constraints that are originally given in the problem description. A goal state is a

    state that has been constrained enough where enough most be defined for each problem.

    Algorithm : Constraint Satisfaction1. Propagate available constraints. To do this, first set OPEN to the set of all objects that m

    have values assigned to them in a complete solution. Then do until an inconsistency is detecteduntil OPEN is empty:

    (a) Select an object OB from open. Strengthen as much as possible the set of constraints tapply to OB.

  • 7/27/2019 AI Good Notes

    43/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    (b) If this set is different from the set that was assigned the last time OB was examined o

    this is the first time OB has been examined, then add to OPEN all objects that share a

    constraints with OB.(c) Remove OB from OPEN.

    2. If the union of the constraints discovered above defines a solution, then quit and report tsolution.

    3. If the union of the constraints discovered above defines a contradiction, then return failure.

    4. If neither of the above occurs, then it is necessary to make a guess at something in order

    proceed. To do this, loop until a solution is found or all possible solutions have been eliminated(a) Select an object whose value is not yet determined and select a way of strengthening t

    constraints on that object.(b) Recursively invoke constraint satisfaction with the current set of constraints augment

    by the strengthening constraint just selected.

    Example: consider the crypt arithmetic problemProblem: SEND

    +MORE

    --------------MONEY

    Initial state: No two letters have the same value.

    The sums of the digits must be as shown in the problem.

    M=1, since two single-digit numbers plus a carry cannot total more than 19.

    S=8 or 9, since S + M+C3 > 9(to generate the carry) and M=1, S+1+C3>9 so S + C3 >

    and C3 is at most.

    O=0, since S + M(l) + C3 (

  • 7/27/2019 AI Good Notes

    44/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    2+ D= Y or 2 + D= l0+y from the sum in the right most column.

    3. Mean-End Analysis

    The means-ends analysis process centers around the detection of differences between current state and the goal state. once such a difference is isolated, an operator that can reduce tdifference must be foun

  • 7/27/2019 AI Good Notes

    45/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Example: Solve the problem of moving a desk with two things on it from one room to another

    The robots operators

    Push Carry Walk Pickup Putdown Place

    Move object * *Move robot *

    Clear object *

    Get object on object *

    Get arm empty * *

    Be holding object *

    A Difference Table

    The progress of the Means-Ends Analysis Method

    More progress of the Means-Ends Analysis Method

  • 7/27/2019 AI Good Notes

    46/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Knowledge Representation

    There are many methods can be used for knowledge representation and they can be

    described as follows:-

    1- Semantic net.

    2- Conceptual graph. Conceptual representation

    3- Frames

    4- Prepositional and Predicates logic. Logical representation

    5- Clause forms

    1) Semantic Net

    It is consist of a set of nodes and arcs , each node is represented as a rectangle to describe

    the objects, the concepts and the events. The arcs are used to connect the nodes and they

    divided to three parts:-

    Is a: for objects & types

    Is To define the object or describe it

    Has a

    can

  • 7/27/2019 AI Good Notes

    47/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    ))Reciever))agentarcs.,)object(

    Example1: Computer has many part like a CPU and the computer divided into two type, the fir

    one is the mainframe and the second is the personal computer ,Mainframe has line printer with

    large sheet but the personal computer has laser printer , IBM as example to the mainframe and P

    and PIV as example to the personal computer.

    Computer CPU

    Has a

    MainframePCLaser

    printer

    Line

    printer

    IBMPIIPIV

    Is aIs a

    Is a Is a Is a

    Has aHas a

  • 7/27/2019 AI Good Notes

    48/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Example 2: Layla gave Selma a book

    Example 3: Layla told Suha that she gave Selma a book

    time

    Layla gave Selma

    agent receiver

    object

    bookPast

    time

    Layla told Suha

    agent receiver

    time

    past

    Gave

    time

    Selma

    a book

    receiver

    object

    past

    proposition

  • 7/27/2019 AI Good Notes

    49/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Example 4: Ali gave Ban a disk which is Zaki bought

    2) The Conceptual Graph

    :Semantic Net

    Ali gave Ban

    agent receiver

    object

    diskPast

    time

    bought

    Past

    Zaki

    agent

    object

    time

  • 7/27/2019 AI Good Notes

    50/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Example 1: Ahmed read a letter Yesterday

    Example 2:- The dog Scratch it ear with is paw

    Ahmed agent read object letter

    time

    present

    The dog agent scratch object ear

    time

    present

    instrument

    pawPart of

  • 7/27/2019 AI Good Notes

    51/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Example 3: Ahmed tell Saad that he saw Suha

    Ahmed agent tell receiver Saad

    time

    present

    saw receiver Suhaproposition

    time

    past

  • 7/27/2019 AI Good Notes

    52/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    3) Frame:

    Frame-list( node-name, parent, [child]).

    Slot-list(node-name, parent).

    Example:

    Frame list( computer,_ ,[Internal structure, monitor, keyboard , peripherals]).

    Frame-list(Internal structure, computer, [disk controller, mother board]).

    Frame- list(printer, peripheral, [speed, ports]).

    Slot-list(motherboard, Internal structure).

    Slot-list(mouse, peripheral).

    Frame-list

    Slot-list

    computer

    Internal

    Structure

    peripherals

    keyboard

    monitor

    Disk controller

    Mother board

    No. of function key

    plotters mouse

    printerports

    speed

  • 7/27/2019 AI Good Notes

    53/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Homework 1: solve with Semantic net

    Ships are divided in two types , the first is Ocean lines and the second is Oil tankthe ships has an engine , the oil tank are specified to transfer oil therefore it has fire tools , th

    ocean lines are specified to transfer the traveler therefore it has swimming poot , Ibnkaldon a

    an example to oil tank and ship b and ship n as an example to ocean line.

    Homework 2: Using Semantic Net and Conceptual graph to solve the following

    statement:) Suha send a book to Tom.

    2) Tom believe that Mustafa like cheese.

    3) Monkey ema grasp the banana with hand.

    4) The Prepositional Calculus:

    :Symbols and Sentences definitionsSymbols:Sets of symbols: P, Q, R, S, Zpropositions or statements.

    Truth symbols: true & false,

    Connectives: , , , ,

    Sentences:

    propositions & truth symbols; e.g. P , Q , true , . . .

    negative of a sentence; e.g. P , true , . . .conjunction ( AND ); e.g. P Q , . . .disjunction (OR ); e.g. P Q , . . .implication; e.g. P Qequivalence; e.g. ( PQ ) R

  • 7/27/2019 AI Good Notes

    54/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    5)The Predicate Calculus:

    Any proposition consists of some components; predicate calculus provides a way to accessthese components.

    Example:Proposition P represents "it rained on Tuesday". So,

    we can create a predicate weather that describe a relationship between a day & weather,

    e.g. weather(tuesday, rain)

    Semantics of Propositional Calculus:

    It is concerned with the "meanings" of statements, which is required for reasoning in AI.Example1:

    P means "it is raining"

    Or Q means "I live in a brown house

    Example2:X means The food is good

    and Y means The service is good.

    implies Z means The restaurant is good too

    * Expressions may contain variables, such as:For all values of X (X is a day of the week), Then weather(X, rain) means it rains every day.

    Also variable quantifiers and are usede.g. X likes(X, ice_cream)

    Y friends (Y, ali)

    Where

    is Universal quantifier; the sentence is true for all values of variable X. And isExistential quantifier; the sentence is true for at least one value in the domain.

  • 7/27/2019 AI Good Notes

    55/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Example1:

    1) Fido is a dog

    Dog (Fido).

    2)All dogs are animals.

    (dog(x) animal(x))

    1) All animals will die.

    (animal(y) die(y)).

    2) Prove that ,Fido will die

    die (Fido)

    Example 2:-

    1) Any one passing their history exam and winning the lottery is happy.

    X (pass(x, history exam) win (x, the lottery)happy(x))

    2) Any one who studies or is lucky can pass all the exam

    X y (study(x) V lucky(x) pass(x, y)).

    3) John did not study but he is lucky

    study (John) lucky(John).

    4) Any one is lucky wins the lottery

    X (lucky(x) win(x, the lottery)).

    5) Prove that John is happy.

    happy(John).

  • 7/27/2019 AI Good Notes

    56/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Example 3:- All people that are not poor and smart are happy. Those people that read are not

    stupid. John can read and wealthy. Happy people have exciting lives. Can any one be found wit

    an exciting life?

    1) All people that are not poor and smart are happy.

    X ( poor(x) smart(x) happy(x).

    2) Those people that read are not stupid.

    X (read (x) stupid(x)).

    3) John can read and wealthy.

    Read (John) wealthy (John).

    4) Happy people have exciting lives.

    W (happy (w) exciting (w)).

    5) The negation of the conclusion is:

    6) W ( exciting (w)).

    7)

    Homework:- Convert the following statements to predicate logic?

    Marcus was a man. Marcus was a Pompeian. All Pompeian were Romans. Caeser w

    assassinate to someone. Prove that, People not try to assassinate Caeser.

    The statements that produced from predicate logic method are nested and very comple

    to understand, so this will lead to more complexity in resolution stage , therefore the following

    algorithm is used to convert the predicate logic to clause forms:-

    6) Clause Forms:-

    ruler . All Romans were either loyal to Caeser or hated him. Everyone is loyal to someone but n

  • 7/27/2019 AI Good Notes

    57/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

  • 7/27/2019 AI Good Notes

    58/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

  • 7/27/2019 AI Good Notes

    59/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

  • 7/27/2019 AI Good Notes

    60/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Resolution Theorem Proving:

    Resolution is a technique for proving theorems in the predicate calculus that has been part of A.I Problem solving research using Resolution by refutation.

    The resolution refutation proof procedure answers a query or deduces a new result by

    reducing the set of clause to a contradiction , represented by the full clause ( ).

    Resolution by Refutation Algorithm:-

    1- Convert the statement to predicate logic.

    2- Convert the statement from predicate logic to clause form.

    3- Add the negation of what is to be proved to the clause forms.

    4- Resolve these clauses together , producing new clauses.

    5- Produce a contradication by generating the empty clause

    Example: Consider now an example from the propositional calculus , where we want to

    prove (a) from the following axioms:-

  • 7/27/2019 AI Good Notes

    61/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

  • 7/27/2019 AI Good Notes

    62/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

  • 7/27/2019 AI Good Notes

    63/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

  • 7/27/2019 AI Good Notes

    64/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Statistical ReasoningIn many practical problem-solving situations, the available knowledge is incomplete

    inexact. In these cases, the knowledge is inadequate to support the desired sorts of logiinferences. The probabilistic reasoning methods allow AI systems to use uncertain or probabilis

    knowledge in ways that take the uncertainty in to account.

    1. Probability ReasoningProbabilistic techniques, generally, are capable of managing imprecision of data aoccasionally uncertainty of knowledge.

    Example:

    PRi { IF (the-observed-evidences-is-rash) (x ),AND (the-observed-evidences-is-fever) (y),

    AND (the-observed-evidences-is-high-pain) (z ),THEN (the-patient-bears-German-Measles)} (CF )

    where x, y, z denote the degree of precision / beliefs / conditional probabilities that the patibears a symptom, assuming he has German Measles.

    CF represents the degree of certainty of the rule or certainty factor/ probability that the patiebears German Measles, assuming the prior occurrence of the antecedent clauses.

    Bayesian Reasoning

    The Definition of Conditional probability

    P (H / E) is given by P(H / E) = P(H E) / P(E) = P(H & E) / P(E),

    where H and E are two events and P (H E) denotes the joint occurrence of the events H &Analogously, P(E / H) = P(E & H) / P(H) .

    Now, since P(E & H) = P(H & E), we findP(E & H) = P(E / H) . P (H) = P(H / E) . P (E)

  • 7/27/2019 AI Good Notes

    65/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    Example: H= John has malaria,

    E= John has a high fever.

    General Knowledge consist of1. P(H): probability that a person has malaria,

    2. P(E|H): probability that a person has high fever, given that he has malaria,3. P(E|H): probability that a person has high fever, given that he does not have malaria,

    * the fact that john has the symptom of high feverP(H|E) which represents the probability that John has malaria, given that he has a high feve

  • 7/27/2019 AI Good Notes

    66/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    2. Bayesian NetworkThe main idea in this approach is that to describe the real world, it is not necessary to use

    huge joint probability table in which we list the probabilities of all conceivable combinationsevents. Most events are conditionally independent of most other ones, so their interactions ne

    not be considered. Instead, we can use a more local representation in which we will descriclusters of events that interact.

    Example: Suppose that there are two events which could cause grass to be wet: either t

    sprinkler is on or it's raining. Also, suppose that the rain has a direct effect on the use of t

    sprinkler (namely that when it rains, the sprinkler is usually not turned on). Then the situation c

    be modeled with a Bayesian network (shown). All three variables have two possible values, T (

    true) and F (for false).

    The joint probability function is: P(G,S,R) = P(G | S,R)P(S|R)P(R)

    where the names of the variables have been abbreviated to G = Grass wet, S = Sprinkler, andR

    Rain. The model can answer questions like "What is the probability that it is raining, given thegrass is wet?"

  • 7/27/2019 AI Good Notes

    67/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    3.Dempster-Shafer TheoryThis new approch considers set of propositions and assigns to each of them an interval

    [Belief, Plausibility]

    In which the degree of belief must lie. Belief measures the strength of the evidence in favor of aset of propositions. It ranges from 0 (indicating no evidence) to 1 (denoting certainty)

    Pl(s)= 1- Bel(~s)

    Suppose that we have two pieces of uncertain relevant to the same , and that they are represenby basic probability assignments m1 and m2, respectively. Dempsters rule of combination allow

    us to combine any two belief functions.

    Example: in a simplified diagnosis problem, might consist of the set{ All,Flu,Cold,Pneu}

    All: allergy

    Flu: flu

    Cold: coldPneu: pneumonia

    m1 corresponds to our belief after observing fever:{ Flu,Cold,Pneu} (0.6) (0.4)

    m2 corresponds to our belief after observing a runny nose:

    { All,Flu,Cold } (0.8)

    (0.2)

    Then we can compute the combination m3 using the following table:

    {A,F,C} (0.8) (0.2){F,C,P} (0.6) {F,C} (0.48) {F,C,P} (0.12)

    (0.4) {A,F,C} (0.32) (0.08)

    M3(A)

  • 7/27/2019 AI Good Notes

    68/68

    A.I Strategies and Algorithms Lectures

    By : Nuha Jameel Ibrahim

    As a result of applying m1 and m2, we produced m3:

    {Flu,Cold} (0.48)

    {All,Flu,Cold} (0.32){Flu,Cold,Pneu} (0.12) (0.08)

    Let m4 corresponds to our belief given just the evidence that the problem go away when the

    patient goes on a trip{ All} (0.9)

    (0.1)

    {A} (0.9) (0.1){F,C} (0.48) (0.432) {F,C} (0.048){A,F,C} (0.32) {A,F,C} (0.288) {A,F,C} (0.032)

    {F,C,P} (0.12) (0.108) {F,C,P} (0.012) (0.08) {A} (0.072) (0.008)

    Then the final combined belief function, m5:

    {Flu,Cold} (0.104){All,Flu,Cold} (0.696)

    {Flu,Cold,Pneu} (0.026){All} (0.157) (0.017)