Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Artificial Intelligence "Search": Lecture Note

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 25

Lecture Note

Artificial Intelligence “Search”

Professor dr. Hiroyuki Iida


JAIST

2012-11-15
An Overview of Search Algorithm
Depth-first search (DFS) is an algorithm for traversing
or searching a tree, tree structure, or graph.

One starts at the root


(selecting some node as the
root in the graph case) and
explores as far as possible
along each branch before
backtracking.
(from Wikipedia)
Depth-First Search
Formally, DFS is an
uninformed search that
progresses by expanding the first
child node of the search tree that
appears and thus going deeper
and deeper until a goal node is
found, or until it hits a node that
has no children. Then the search
backtracks, returning to the most
recent node it hasn't finished
exploring. In a non-recursive
implementation, all freshly
expanded nodes are added to a
stack for exploration.
The time and space analysis of DFS differs according to its
application area. In theoretical computer science, DFS is
typically used to traverse an entire graph, and takes time
O(|V| + |E|), linear in the size of the graph.
In these applications it also
uses space O(|V|) in the
worst case to store the stack
of vertices on the current
search path as well as the
set of already-visited
vertices.
Thus, in this setting, the time and space bounds are the
same as for breadth first search and the choice of which of
these two algorithms to use depends less on their complexity
and more on the different properties of the vertex orderings
the two algorithms produce.
For applications of DFS to search
problems in artificial intelligence,
however, the graph to be
searched is often either too large
to visit in its entirety or even
infinite, and DFS may suffer from
non-termination when the length
of a path in the search tree is
infinite. Therefore, the search is
only performed to a limited depth,
and due to limited memory
availability one typically does not
use data structures that keep
track of the set of all previously
visited vertices.
In this case, the time is still linear
in the number of expanded
vertices and edges (although
this number is not the same as
the size of the entire graph
because some vertices may be
searched more than once and
others not at all) but the space
complexity of this variant of DFS
is only proportional to the depth
limit, much smaller than the
space needed for searching to
the same depth using
breadth-first search.
For such applications, DFS also
lends itself much better to heuristic
methods of choosing a likely-looking
branch. When an appropriate depth
limit is not known a priori,
iterative deepening depth-first searc
h
applies DFS repeatedly with a
sequence of increasing limits; in the
artificial intelligence mode of
analysis, with a branching factor
greater than one, iterative
deepening increases the running
time by only a constant factor over
the case in which the correct depth
limit is known due to the geometric
growth of the number of nodes per
level.
Branch and bound
Branch and bound (BB or B&B) is a general
algorithm for finding optimal solutions of various
optimization problems, especially in discrete and
combinatorial optimization. It consists of a
systematic enumeration of all candidate solutions,
where large subsets of fruitless candidates are
discarded en masse, by using upper and lower
estimated bounds of the quantity being optimized.
The method was first proposed by A. H. Land and
A. G. Doig[1] in 1960 for discrete programming.
[1] A. H. Land and A. G. Doig (July 1960). "An automatic method of solving discrete
programming problems". Econometrica 28 (3): pp. 497-520.
Hill climbing
In computer science, hill climbing
is a mathematical optimization
technique which belongs to the
family of local search. It is relatively
simple to implement, making it a
popular first choice. Although more
advanced algorithms, e.g.,
Simulated annealing or tabu
search, may give better results, in
some situations hill climbing works
just as well. Especially for some
real-time systems, hill climbing can
get a relatively better solution in a
limited time.
Hill climbing
Hill climbing can be used to solve problems that have many solutions, we
call it a search space. In the search space, different solutions usually
have different values. Hill climbing starts with a random (potentially poor)
solution, and iteratively makes small changes to the solution to generate
a neighborhood solution.
If the neighborhood solution is
better than the current solution,
then we use the neighborhood
solution to substitute the current
solution. When the current solution
can no longer be improved, it
terminates. Ideally, at that point the
current solution is close to optimal,
but it is not guaranteed that hill
climbing will ever come close to the
optimal solution. However, it may
obtain the local optimal solution.
Cont.
For example, hill climbing can be applied to
the traveling salesman problem. It is easy
to find a solution that visits all the cities but
will be very poor compared to the optimal
solution. The algorithm starts with such a
solution and makes small improvements to
it, such as switching the order in which two
cities are visited. Eventually, a much better
route is obtained.

Hill climbing is used widely in artificial


intelligence, for reaching a goal state from
a starting node. Choice of next node and
starting node can be varied to give a list of
related algorithms.
IDA*
IDA* is a variant of the A* search algorithm which
uses iterative deepening to keep the memory
usage lower than in A*.

It is an informed search based on the idea of the


uninformed iterative deepening depth-first
search.
The main difference to IDS is that it uses the f-
costs (g + h) as the next limit and not just an
iterated depth.

Korf, Richard (1985). "Depth-first Iterative-Deepening: An Optimal Admissible


Tree Search". Artificial Intelligence 27: 97–109.
TREE SEARCH ALGORITHM
TECHNICAL ASPECTS
Terminology
Mathematical Game
Directed Cyclic Graph Tree
(with loops)
Directed Acyclic Graph
(with
transpositions)
Node Position
Depth

Directed Edge Move


G Leaf Node Leaf Node
Breadth
Terminal Node
Purpose of Tree Search
• Find a goal (e.g. knapsack problem)
• Show the path
• Find the optimal path (e.g. )
Basic Algorithms
Depth First Breadth First
Traversing order 0 0

1 1 2 3

2 3 4

G G

Memory Low  High 


Requirement
Can find the No  Yes 
optimal?
Node management Stack Queue
Iterative Deepening

0 Iterative Deepening
code for threshold in 1, 2,
3,…
threshold = 1 1 2 3
depth-
first(threshold)
threshold = 2 4 memory Low 

optimal Yes 
threshold = 3 G
manage Stack(or
ment Transposition Table)
Using Heuristic
• What’s Heuristic
– Something not proven to be optimal
– evaluation, knowledge, estimation
• What’s Cost
– Number of edges
– Length of the path
– Speed for the path
– Etc.

Theoretical Estimation

Equation f(n) = g(n) +h(n) f’(n) = g’(n) + h’(n)


Descriptio f (Optimal cost from the f’( estimated cost from the
n root to a goal through n) is root to a goal through n) is g’(
g(optimal cost from the optimal cost from the root to n
root to n) plus h(optimal currently) plus h’(estimated
cost from n to the goal). cost from n to the goal)
An Example of Heuristic
Function
0 (10)
X Y
1 2 1
g 2 3
1 1 (7) 3 (8) 2 (5) h inf 2
2 1 1 3 f = g+ h inf 5
(inf) 5 4 (6) (3) g’ (on 2(4, 6,…) 3(4)
2 1 edges)
X h’ (on 6 3
Y G (0) (inf)
nodes)
f’ = g’ + h’ 8 6
Order in f’ = g’
Heuristic Based Algorithm
Name Heuristic Target Note
Hill Climbing f’(n) = g’(n) + 0 Child
Hill Descending nodes
Branch and Bound f’(n) = g’(n) + 0 All ref. Dikestra’s
Optimal unsolved method
nodes
Best First f’(n) = 0 + h’(n) All Fast as possible
unsolved
nodes
A Algorithm f’(n) = g’(n) + All
h’(n) unsolved
nodes
A* Algorithm f’(n) = g’(n) All h*(n) <= h(n) for all n
+h*(n) unsolved
nodes
General Code
function search(root)
container.push(root)
Algorithm Container
while (Open List)
( container.hasNode() ) Depth First Stack(LIFO)
node = container.pop() Breadth First Queue(FIFO)
Require Memory
if ( node.isSolved() ) 
return SOLVED Heuristic Search Heap sorted by f()
Require Memory
children = 
node.expand()
Ignoring path for the answer
container.push(children)
return UNSOLVABLE
IDA/IDA*

0 (10)
Iterative Deepening
threshold = 1 1 2 1 A/A*
1 (7) 3 (8) 2 (5) code for threshold in 1, 2, 3,…
1
threshold = 2
2 1 1 3
heuristicSearch(threshold
(inf) 5 4 (6) (3) )
threshold = 3 2 1 memory Low 

G (0) (inf) optimal depend on f’()


manage Stack(or Transposition
ment Table)
Order in f’ = g’
Demo in 15 puzzle
Heuristic function(Manhattan Distance):
9 A F E
MH ( position)   x( p)  x( goalof ( p ))  y ( p)  y ( goalof ( p))
Start 8 1 0 C p0

6 5 3 D
7 4 B 2
Loops/Transpostions:
h’ ( ) = MH() =

1 2 3 4 N S E W

5 6 7 8
Goal
9 A B C N W

D E F 0
h’( ) = MH = 0
Demo in 15 Puzzle
• Size 3 (rand 1000)
– Depth, Breadth(10^6), ID
– Best, A, IDA
• Size 4 (rand 500)
– A(10^6), IDA
Remarks
Optimal

Depth First ID Breadth First

Less Memory

IDA* A* Branch & Bound

IDA
A

Hill Climbing Best


First
Heuristic
Exercise
• Q. Improve ID(not IDA/IDA*) with using h*()
– A. Start with threshold = h*() instead of 1.
• Q. How efficient is to avoid stupid repetition (such as
NSNS…) in 15 puzzle?
– A. Great. Branching factor affects search efficiency lot.
• Q. Fix the general code to Hill Climbing.
– A. Clear the container before push().
• Q. Fix the general code to be able to get the optimal
path
– A. ref. Dikstra’s method
• Q. What if goals are not be able to be reached in
practical time?
– A. Open question. Game tree search is an instance.

You might also like