Download Artificial Intelligence

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Network science wikipedia , lookup

Computational phylogenetics wikipedia , lookup

Minimax wikipedia , lookup

Signal-flow graph wikipedia , lookup

Corecursion wikipedia , lookup

Transcript
Artificial Intelligence
Exercises & Solutions
Chapters 3-4: Search methods
1. Defining a search problem
You want to design a search algorithm for finding person B in a social media
network who has the most similar music taste to person A. First you have to
define the problem formally. What kind of initial state, successor
function, goal test and path cost there might be? The algorithm can
access each person's details only through other people who are connected to
her/him.
2. Search efficiency
a) Use a depth-first search to find B in the following search tree:
A
E
C
D
D
G
C
G
B
G
B
B
b) Compute the number of operations required for finding B. Opening a node
is considered an operation.
3. Search tree
Draw the complete search tree (starting from S and ending at G) of the graph below.
The numbers beside the nodes represent the estimated distances from the goal
state. Show how the search
procedure
proceeds in the tree by using:

depth-first

breadth-first

hill-climbing

beam-search (w=2)

best-first
methods.
4. Search traces
Consider the graph shown in the figure to the right. We
can search it with a variety of different algorithms,
resulting in different search trees. Each of the trees
(labelled G1 though G7, next page) was generated by
searching this graph, but with a different algorithm.
Assume that children of a node are visited in
alphabetical order when no other order is specified by
the search. Each tree shows all the nodes that have
been seen during search. Numbers next to nodes
indicate the relevant “score” used by the algorithm for
those nodes. For each tree, indicate whether it was
generated with

Depth first search

Breadth first search

Uniform cost search

A* search

Best-first (greedy) search
In all cases a strict expanded list was used. Furthermore, if you choose an algorithm
that uses a heuristic function, say whether we used

H1: heuristic 1 = {h(A) = 3, h(B) = 6, h(C) = 4, h(D) = 3}

H2: heuristic 2 = {h(A) = 3, h(B) = 3, h(C) = 0, h(D) = 2}
Also, for all algorithms, say whether the result was an optimal path (measured by
sum of link costs), and if not, why not.
5. Search problem
Consider the 3-puzzle problem, which is a simpler version of the 8-puzzle where the
board is 2 x 2 and there are three tiles, numbered 1, 2, and 3, and one blank. There
are four operators, which move the blank up, down, left, and right. The start and
goal states are given below. Show how the path to the goal can be found using:
a) breath first searh
b) depth first search
c) A* search with the heuristic being the sum of
number of moves and the number of misplaced tiles.
Assume that there is no possibility to remember states that have been visited
earlier. Also, use the given operators in the given order unless the search method
defines otherwise. Label each visited node with a number indicating the order in
which they are visited. If a search method doesn’t find a solution, explain why this
happened.
1. Defining a search problem - solution
Initial state: This is the location in the network database where the search agent
starts. In this case, it is the data structure containing the personal details of the
person A. We could describe it as In(person A).
Successor function: This function returns a set of <action, successor> ordered
pairs, where each successor is a state that can be reached from current state. For
example, from the state In(person A) the successor could return {<Open(person C),
In(person C)>, <Open(person D), In(person D)>} if person A is directly connected to
persons C and D.
Goal test: This could be the comparison of music tastes by counting the number of
common artists, styles, etc. If there are a lot of similarities, it could also be a good
idea to go through the friends of this person. They might have even more similar
music taste.
Path cost: For example, this could be the number of nodes opened while reaching
the current node from the root node (person A).
2. Search efficiency – solution
a) Depth-first search:
A
E
C
D
D
G
C
G
B
G
B
B
b) Opening sequence is {A, E, C, D, G, B}, so the number of operations is 6.
3. Search Tree – solution
The complete search tree can be generated by finding all possible routes that start
from the node S and lead to a node that has not yet been visited on the route. The
tree below has been constructed by always choosing the rightmost (from the nodes
point of view) unvisited route. Note that the branches could be in different order if
routes were selected in different order. The nodes are numbered (1-18) to ease the
analysis of the search methods.

In depth first search method the tree is searched in the depth direction. The
search always branches to the leftmost unvisited node. In case a leaf node is
found or there are no more unvisited nodes, the search returns to the
preceding level. In this case, the tree is searched in the order indicated by the
node numbers and is illustrated with the dotted line. If one solution for
reaching G was enough, the search would end at the node five. If the whole
tree is searched, the best route to G can be selected at the end.

Breadth-first search method searches the tree in the breadth direction. In this
case the nodes are searched in the following order: 1, 2, 10, 3, 4, 7, 11, 15, 5,
6, 8, 12, 13, 16, 18, 9, 14 and 17. Again, if one solution was enough, the
search would end at node 5.

Hill-climbing is a search algorithm that proceeds like depth-first search but so
that the search order of the nodes is determined by the estimated distance
from a node to the goal node (depth first would choose the leftmost). When
starting from the node S, the search sees the estimated distances from the
nodes 2 (9) and 10 (8) and chooses the node 10 that is estimated to be closer
to the goal. From node 10 the nodes 11 (9) and 15 (5) become visible and the
search proceeds to node 15. From node 15 the goal node becomes visible and
the search has found a solution. One solution is usually enough for Hillclimbing since it usually finds good solutions. However, the image illustrates
the search of the whole tree to better describe the search.

Beam-search proceeds much like breath first, however, at each level only w
number of nodes are checked. First, nodes 2 and 10 are opened. At this point
five nodes can be seen (3 (10), 4 (5), 7 (8), 11 (9) and 15 (5)). Since only two
nodes can be opened, nodes 4 and 15 are selected. After those nodes are
opened four more nodes become visible and as the goal node becomes
visible (actually twice) the search is completed. The nodes were visited in the
following order: 1, 2, 10, 4, 15 and 5.

Best-first search always chooses the best node, independent of where in the
tree it is located. At first, the nodes 2 (9) and 10 (8) can be seen and the
node 10 is opened. Now, the nodes 2 (9), 11 (9) and 15 (5) can be seen and
the node 15 is opened. At this point the nodes nodes 2 (9), 11 (9), 16 (9) and
18 (0) can be seen and as 18 is the goal node, the search is finished.
If one would want to find an alternative route to the goal node, the search
would be continued from where the nodes 2 (9), 11 (9), 16 (9) were seen.
Now all the nodes have the same distance. If the leftmost node of same
valued nodes was opened first the search would continue through nodes 2, 4
and 5. If on the other hand the node that was seen last of the same valued
nodes was to be opened first, the search would continue through nodes 16,
11 ,13 and 14.
4. Search traces – solution
G1:
1. Algorithm: Breadth First Search
2. Heuristic (if any): None
3. Did it find least-cost path? If not, why? No. Breadth first search is only guaranteed
to find a path with the shortest number of links; it does not consider link cost at all.
G2:
1. Algorithm: Best First Search
2. Heuristic (if any): H1
3. Did it find least-cost path? If not, why?
No. Best first search is not guaranteed to find an optimal path. It takes the first path
to goal it finds.
G3:
1. Algorithm: A*
2. Heuristic (if any): H1
3. Did it find least-cost path? If not, why? No. A* is only guaranteed to find an
optimal path when the heuristic is admissible (or consistent with a strict expanded
list). H1 is neither: the heuristic value for C is not an underestimate of the optimal
cost to goal.
G4:
1. Algorithm: Best First Search
2. Heuristic (if any): H2
3. Did it find least-cost path? If not, why? Yes. Though best first search is not
guaranteed to find an optimal path, in this case it did
G5:
1. Algorithm: Depth First Search
2. Heuristic (if any): None
3. Did it find least-cost path? If not, why? No. Depth first search is an any-path
search; it does not consider link cost at all.
G6:
1. Algorithm: A*
2. Heuristic (if any): H2
3. Did it find least-cost path? If not, why? Yes. A* is guaranteed to find an optimal
path when the heuristic is admissible (or consistent with a strict expanded list). H2
is admissible but not consistent, since the link from D to C decreases the heuristic
cost by 2, which is greater than the link cost of 1. Still, the optimal path was found.
G7:
1. Algorithm: Uniform Cost Search
2. Heuristic (if any): None
3. Did it find least-cost path? If not, why? Yes. Uniform Cost is guaranteed to find a
shortest path.
5. Search problem - solution
a)
Breadth first search will start from the
root node, then expands all the
successors of the root node, and then
all their successors and so on.
Breadth first search stops when first
solution is found.
b)
Depth-first
search
expands
the
deepest node in the search tree.
Notice that there was no mechanism
to remember states that have been
visited earlier. Depth first will not find
a solution as it will start oscillating
between movements U and D
c)
A* is a search method that opens the
node with smallest cost function value.
The search begins from the start state.
1. When the start state is opened we
see two states
2. The leftmost state has a lower cost
so that one is choosen and opened. We
now see states with costs 5,3 and 4
3. The state with lowest cost is opened
and we see two more nodes including
the goal node. We notice that the goal
node has the lowest cost so we choose
that and can finish the search. If some
other node with a lower cost function
value was still visible, A* search would
choose that instead of the higher cost
goal node. This is because A* tries to
find the path with lowest cost.