artificial intelligence - student help62.com · 5 artificial intelligence 2012 lecture 06 delivered...
TRANSCRIPT
ARTIFICIAL
INTELLIGENCE
LECTURE # 06
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 1
Review of Last Lecture
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 2
Recap
1. Problem solving
2. Classical approach
3. Generate and test (hit and trial method)
4. Problem representation (graphics and diagram)
5. Example ( two one problem)
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 3
Today’s Lecture
• Searching
• State Space Search
• Depth First Search
• Breath First Search
• Depth Limited
• Iterative Deepening Search
• Bi-Directional Search
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 4
Searching
• All the problems that we have looked at can be converted
to a form where we have to start from a start state and
search for a goal state by traveling through a solution
space.
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 5
Problem Solving and Search
• Most AI Problems can be represented in the form of a Non-linear Data structure (Such as a tree or a graph)
• Once the representation is performed successfully, the only problem is solved by searching for a path from start state to goal state
• Background required in “GRAPH THEORY”
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 6
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 7
A tree is a type of a graph
Ancestor_of
g, h and i
GRAPH THEORY: STRUCTURE
Leaf or tip
Root
parent
child
1
2
3 4
5
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 8
State Space Search
• If the general action is known, but the actions that lead to solution is not known then search methods can be applied
• Example • Sequence of steps that solve a puzzle
• State space search characterizes problem solving as the process of finding a solution path from the start state to a goal.
Initial State Goal State
Through all Possible actions
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 9
State Space
• A state space is all possible configurations/states of the domain
• A state space should describe • Everything that is needed to solve the problem.
• Nothing that is not needed to solve the problem.
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 10
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 11
State Space Search
• We don’t in fact need to store each and every state of the state space to perform a search, rather we specify a start state, a goal state and a set of “operators” to move from one state to another. (E.g. move blank in case of 8-puzzle problem)
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 12
State Space Representation of a Problem..8 puzzle
State space of the 8-puzzle generated by “move blank” operations
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 13
State Space Representation of a Problem..TSP
An instance of the traveling salesperson problem.
Complexity of exhaustive search is (N-1)!
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 14
State Space Representation of a Problem..TSP
Search of the traveling salesperson problem. Each arc
is marked with the total weight of all paths from
the start node (A) to its endpoint.
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 15
State Space Search
• State Space need not be finite, there can be infinite state spaces
• For example, if we are working with transition operators that work with real numbers, then there may be potentially infinite states
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 16
ANALYSIS OF SEARCH STRATEGIES
Completeness: is the strategy guaranteed to find a solution where there is one?
Time Complexity: How long does it take to find a solution?
To find out the best strategy for solving a problem address the following issue.
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 17
ANALYSIS OF SEARCH STRATEGIES
Space Complexity: How much memory does it need to perform the search?
Optimality: Does the strategy find the highest quality solution when there are several different solutions?
main factors for complexity considerations:
branching factor b, depth d of the shallowest goal node, maximum path length m
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 18
Search strategies
• Very powerful tool used in AI
• Used where problem have larger SS.
• Categories of Search strategies; • Uninformed/blind:
• Informed/ heuristic
• Any path/ non-optimal
• Optimal path
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 19
Uninformed/blind:
Have no information about the legal move, state
Many routes/direction to follow any of them until the dead-end arrive.
No control over using operator
• Maze problem
• Going to airport in big city
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 20
Categories of Uninformed/blind:
Depth first search
Breadth first search
Iterative deepening search
Bidirectional search
Depth limited search
Uniform cost search
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 21
Simple search Algorithm
Search algo( this algorithm search a goal state, in a tree shape solution space)
Let S be the start state
1. Initialize Q with the start node Q=(S) as the only entry; set Visited = (S)
2.If Q is empty, fail, else pick node x from Q
4. If X is a goal, return X, we have reached the goal state.
5. (otherwise) remove X form Q.
6. Find all the children of state X not in visited.
7. Add these to Q, add children of X to visited.
8. Go to Step 2.
9. exit
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 22
Simple search Algorithm
• Q represent a priority queue
• Visited also represent another queue
• How to pick a node X from the Q is a critical step.?????????
• Implement a priority function P(n).
• The node with the highest priority will have the smallest value of the functions P(n) i.e. P(n)= 1
height(n)
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 23
Depth-First Search
• DFS is blind search algo. • You pick one direction and go deep and deep
down in the solution space, until either you hit a dead end or find a solution.
• If don’t find a solution again come back and going down into deep…again & again until goal.
• Store only a single path from the root to a leaf, along with the remaining unexpanded sibling nodes for each node on the path
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 24
Depth-First Search
• Expands the node at the deepest level • Only when the search hits a dead end does the
search go back and expand nodes at shallower levels
• Store only a single path from the root to a leaf, along with the remaining unexpanded sibling nodes for each node on the path
• For branching factor b and maximum depth d, requires only storage of bd nodes, so space complexity is O(bd)
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 25
Depth-First Search
• DFS has very modest memory requirements. • May actually be faster the BFS • It requires less time as compared to BFS. • It requires less memory as compared to BFS.
• Can get stuck going down the wrong path, if a problem
have very deep or infinite search tree. • Imagine if the shallow solution is exist ????????? • Neither complete, • Nor optimal • So avoid it for a large search tree.
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 26
Depth-First Search
• . S
C
B
D
A
F
H G
E
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 27
Q visited
1
2
3
4
5
6
S
C
B
D
A
F
H G
E
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 28
Q visited
1 S
2
3
4
5
6
.
Q visited
1 S
2 A,B S
3
4
5
6
S
C
B
D
A
F
H G
E
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 29
.
• .
S
C
B
D
A
F
H G
E
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 30
Q visited
1 S
2 A,B S
3 C,D,B A,S
4
5
6
.
S
C
B
D
A
F
H G
E
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 31
Q visited
1 S
2 A,B S
3 C,D,B A,S
4 G,H,D,B C,A,S
5
6
.
S
C
B
D
A
F
H G
E
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 32
Q visited
1 S
2 A,B S
3 C,D,B A,S
4 G,H,D,B C,A,S
5 H,D,B G,C,A,S
6
.
• .
S
C
B
D
A
F
H G
E
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 33
Q visited
1 S
2 A,B S
3 C,D,B A,S
4 G,H,D,B C,A,S
5 H,D,B G,C,A,S
6 D,B H,G,C,A,S
Example graph for breadth-first and depth-first search tree
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 34
Function depth_first_search
Begin
open := [Start];
closed := [];
while open != [] do
begin
remove leftmost state from open, call it X;
if X is a goal then return SUCCESS
else begin
generate children of X;
put X on closed;
discard children of X if already on open or closed;
put remaining children on left end of open
end
end
return fail
End
Note: open is maintained as a stack.
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 35
36
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,C,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;
closed = [F,T,L,S,K,E,B,A]
10. Open = [C,D]; closed = [M,F,T,L,S,K,E,B,A]
11. Open = [G.H.D]; closed = [C,M,F,T,L,S,K,E,B,A]
Depth First Search
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 37
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 38
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 39
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 40
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 41
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 42
Depth-First Search
• For b=10, d=12, and a node takes 0.1 Kilobytes to store
we need only 12 kilobytes memory
• Time complexity O(bd)
• Can get stuck going down the wrong path
• Neither complete nor optimal
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 43
Breadth-First Search
• In DFS you imagine your solution/goal state is too long/deep in the search tree
• In BFS you imagine your solution/goal state is round about
the start state
• All the nodes at depth d in the search tree are expanded before the node of depth d+1
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 44
Breadth-First Search
• If there is a solution, breadth-first search is guaranteed to find it
• p(n)= height(n) • If there are several solutions, breadth-first search
will always find the shallowest goal state first. • • But is not the strategy of choice always. • Consider the amount of time and memory. • Bigger memory problem.????????????? • Need a huge time?????????????
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 45
Function breadth_first_search
Begin
open := [Start];
closed := [];
while open != [] do
begin
remove leftmost state from open, call it X;
if X is a goal then return SUCCESS
else begin
generate children of X;
put X on closed;
discard children of X if already on open or closed;
put remaining children on right end of open
end
end
return fail
End
Note: open is maintained as a queue.
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 46
47
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 = []
Breath First Search
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 48
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 49
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 50
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 51
Time and Memory Requirements of BFS
• Branching factor: b, Depth of the goal: d • Maximum number of nodes expanded before finding a
solution with a path length d: 1+b+b2+b3+…+bd, so the time complexity is O(bd)
• The space complexity is the same (O(bd)) as the time complexity, because all the leaf nodes of the tree must be maintained in memory at the same time. Most significant disadvantage of BFS. Even 15-puzzle problem is enough to kill a desktop computer in terms of memory.
• If b = 10, and dealing with one node takes 1 ms as well as 100 bytes, we will need 111 megabytes for depth 6 (bd~106), and 11111 terabytes for depth 14 (bd~1014)
• Complete, if you have a goal in finite depth you will terminate.
• Optimal, will find the shallowest goal node
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 52
Depth-Limited Search
• Simply put an upper limit on the depth of paths allowed
• prevents search diving into deep solutions
• Guaranteed to find the solution if it exists within the depth limit
• Not guaranteed to find the shortest solution first • Time complexity: O(bl), l is the depth limit • Space complexity: O(bl)
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 53
Depth-Limited Search
• Simply put an upper limit on the depth of paths
that are to be searched
• Only add nodes to the queue if their depth does not
exceed the bound
• Do this iteratively until goal is found (Success) or a
certain depth is reached (Failure)
• Motivation:
• prevents search diving into deep solutions
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 54
Trees: Depth-Limited
• Depth limit of 2 would
mean that children of E are
ignored J
B C
D
E
F
G
A
H
I
d=0
d=1
d=2
d=3
d=4
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 55
Depth-Limited
• Guaranteed to find the solution, if one exist, but not
shortest solution first.
• DLS is complete but not optimal.
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 56
Iterative Deepening
• BFS • good for optimality
• bad on memory, O(bd)
• DFS • solutions not guaranteed optimal: dives and misses good
nodes
• good for memory O(bd)
• “Iterative Deepening” refers to a method that tries to combine the best of the above
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 57
Iterative deepening search L=0
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 58
Iterative deepening search L=1
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 59
Iterative deepening search L=2
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 60
Iterative Deepening Search L=3
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 61
Iterative deepening search
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid
Iqbal 62
Properties of IDS
• Memory Usage • Same as DFS O(bd)
• Time Usage: • Worse than BFS because nodes at each level will be
expanded again at each later level • BUT often is not much worse because almost all the effort is
at the last level anyway, because trees are “leaf –heavy”
• IDS combines the small memory footprint of DFS, and has the completeness guarantee of BFS
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 63
Summary of Different Search Algorithms
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 64
Bidirectional Search
• Start searching downwards from start state as well as
searching upwards from the goal state
• If, during the search both searches meet at a common
node, then we have found a path from the start state to
the goal state
• Possible only if operators are reversible, so that you can
start from the goal and work upwards
• Works in O(bd/2) time and O(bd/2) space complexity
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 65
Bidirectional Search
G
S
O(bd/2)
O(bd/2)
+ = O(bd/2)
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 66
Uninformed vs. Informed Search
• Uninformed Search Strategies • Breadth-First search • Depth-First search • Uniform-Cost search • Depth limited search • Depth-First Iterative Deepening search • Bidirectional search
• Informed / heuristic Search Strategies • Hill climbing • Best-first search • Greedy Search • Beam search • Algorithm A • Algorithm A*
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 67
References
• Artificial Intelligence, A modern approach by Russell:
(Chapter 3rd)
• Artificial Intelligence: Structures and Strategies for
Complex Problem Solving by George F Luger:
• (Chapter 3rd)
Artificial Intelligence 2012 Lecture 05 Delivered By Zahid Iqbal 68
End of Lecture
Artificial Intelligence 2012 Lecture 06 Delivered By Zahid Iqbal 69