HW3 Sol PDF
HW3 Sol PDF
Homework 3
Informed search
4.1 A* search: From Lugoj to Bucharest
100
Craiova
A* search: From Lugoj to Bucharest
Lugoj
f = 111 + 329 = 440 f = 70 + 241 = 311
Timisoara
Mehadia
Craiova
f = 604 f = 503
Rimnicu
Pitesti
A* search: From Lugoj to Bucharest
Lugoj
f = 111 + 329 = 440 f = 70 + 241 = 311
Timisoara
Mehadia
Craiova
f = 604 f = 503
Rimnicu
Pitesti
A* search: From Lugoj to Bucharest
Lugoj
f = 111 + 329 = 440 f = 70 + 241 = 311
Timisoara
Mehadia
Craiova
f = 604 f = 503
Rimnicu
Pitesti
f = 693 f = 504
Rimnicu
Bucharest
f = 70+75+120+138+101 = 504
4.2 Heuristic path algorithm
f(n) = (2 – w)g(n) + wh(n)
For what value of w is this algorithm guaranteed to be
optimal?
w1
4.2 Heuristic path algorithm
d p1 , p 2 =∣x 1 − x 2∣∣ y 1 − y 2∣
8
Heuristic: h=∑ d n
n= 1
•Tiles cannot move along diagonals, so each tile has to move at least d(n)
steps to its goal
1
2
2
3
0
2
2
2
5. Eight Queens problem
Thus, h = Σ( # queens that are on the same row – 1) for all conflicting rows
4.11
(a) Local beam search with k=1
– Equivalent to HILL-CLIMBING
4.11
(b) Local beam search with k=∞
Pick Q2 randomly
1 3 1 2
3 Q2 We can move Q2 to
B2 or B4
2 1 3 1
Randomly, move
2 Q3 Q2 to B4
1 2 1 3
1 Q4
Number of conflicts
4-Queens problem
A B C D
3 1 2 2 All queens are
4 Q1 Q2 attacked.
Pick Q1 randomly
1 3 1 1
3 We can move Q1 to
A1 ~ A3
1 1 2 2
Randomly, move
2 Q3 Q1 to A2
1 2 1 2
1 Q4
4-Queens problem
A B C D
3 0 2 1 Q1, Q3 and Q4 are
4 Q2 attacked.
Pick Q3 randomly
1 3 1 1
3 We can move Q3 to
C1 or C3
1 2 2 3
Randomly, we
2 Q1 Q3 select C1
1 3 1 1
1 Q4
4-Queens problem
A B C D
2 0 2 1 Q3 and Q4 are
4 Q2 attacked.
Pick Q4 randomly
2 2 1 0
3 We can move Q4
D3
0 2 2 3
2 Q1
2 3 1 1
1 Q3 Q4
4-Queens problem
A B C D
2 0 2 1 No conflicts!
4 Q2
2 2 1 0
3 Q4
0 2 2 3
2 Q1
2 3 1 1
1 Q3
8. Compute the following gradients
f ( x, y, z , t ) ( x 1)(2 y ) z (t 3 1) xyz
1
g ( x, y )
1 exp( (ax by c))
h( x, y, z ) ( x 1) 2 exp( x) ( y 2) 3 z 3
c ( x, y , z ) ( x z 2 y 2 ) b
g ( x, y ) 2( x 1) 2 2( y 2) 2 2( x 1)( y 2)
a, b, c are some arbitrary constants
8. Compute the following gradients
f ( x, y, z , t ) ( x 1)(2 y ) z (t 3 1) xyz
1
g ( x, y )
1 exp( (ax by c))
h( x, y, z ) ( x 1) 2 exp( x) ( y 2) 3 z 3
c ( x, y , z ) ( x z 2 y 2 ) b
g ( x, y ) 2( x 1) 2 2( y 2) 2 2( x 1)( y 2)
8. Compute the following gradients
f x , y , z , t = x −1 2− y zt 3−1 xyz
3 3 3 2
∇ f = 2− y z t −1 yz ,− x−1 zt −1 xz , x −1 2− y t −1 xy , 3 t xyz
1
g x , y =
1exp − axby c
a exp − ax by c b exp − ax by c
∇ g= 2
, 2
1exp − ax byc 1exp − axby c
2 2
g x , y = 2 x−1 2 y −2 − 2 x−1 y−2
∇ g= 4x−2y , −2x4y −6
Pseudo code for gradient descent
algorithm that minimize g(x, y)
Uniform Cost Search
B
G 3 5
1
A
I
4
2
C 1 F
4 3
H D
2
Goal: path AI
Queue: A (root)
Uniform Cost Search
B
G 3 5
1
A
I
4
2
C 1 F
4 3
H D
2
Step 1: E
At node A:
Queue: D=2, G=3, C=4, B=5
Note: nodes in the queue are sorted by distance from the root
Uniform Cost Search
B
G 3 5
1
A
I
4
2
C 1 F
4 3
H D
2
Step 2: E
At node D:
Queue: G=3, C=4, E=4, B=5, H=5
Note: nodes in the queue are sorted by distance from the root
Uniform Cost Search
B
G 3 5
1
A
I
4
2
C 1 F
4 3
H D
2
E
Step 3:
At node G:
Queue: I=4, C=4, E=4, B=5, H=5
Note: nodes in the queue are sorted by distance from the root
Uniform Cost Search
B
G 3 5
1
A
I
4
2
C 1 F
4 3
H D
2
E
Step 4:
At node I:
GOAL NODE FOUND!!!!!
A* Search
f(n) = g(n) + h(n)
Where:
f(n) – estimated total cost of path
through n to goal
R
9 g(n) – cost so far to reach n
1
h(n) – estimated cost from n to goal
A B
1 2 Heuristic Estimates:
C
D
h(B -> G2) = 9
h(D -> G2) = 10
1 h(A -> G1) = 2
10
G1 G2
h(C -> G1) = 1
A* Search f(n) = g(n) + h(n)
C
D
G1 G2
A* Search f(n) = g(n) + h(n)
A B
G1 G2
A* Search f(n) = g(n) + h(n)
A B
f = (1 + 2) + 10 = 13
G1 G2
A* Search f(n) = g(n) + h(n)
A B
f = (9 + 1) + 1 = 11 f = (1 + 2) + 10 = 13
C
D f (G1) = 11 < f(D) = 13
f = 11
G1 G2
A* Search Order:
R – B – A – C – G1
A B
f = (9 + 1) + 1 = 11 f = (1 + 2) + 10 = 13
C
D f (G1) = 11 < f(D) = 13
f = 11
G1 G2