Background → Markov Chains

Markov Chains as Matrices

Exercise 6.1 - Restless Robot

Robot has no AI. At each time step, it either moves left or right (each with at 50% chance) Moving into an edge (e.g. moving left at state 0) causes the robot to stay in the same state. The robot starts in state 2. This system can be modelled as a Markov Chain.
**a)** What are the dimensions of the transition matrix? **b)** Construct the transition matrix in code
p = np.array([
	[0.5, 0.5, 0.0, 0.0, 0.0, 0.0],
	[0.5, 0.0, 0.5, 0.0, 0.0, 0.0],
	[0.0, 0.5, 0.0, 0.5, 0.0, 0.0],
	[0.0, 0.0, 0.5, 0.0, 0.5, 0.0],
	[0.0, 0.0, 0.0, 0.5, 0.0, 0.5],
	[0.0, 0.0, 0.0, 0.0, 0.5, 0.5]
])
[0.50.500000.500.500000.500.500000.500.500000.500.500000.50.5]\begin{bmatrix} 0.5&0.5&0&0&0&0\\ 0.5&0&0.5&0&0&0\\ 0&0.5&0&0.5&0&0\\ 0&0&0.5&0&0.5&0\\ 0&0&0&0.5&0&0.5\\ 0&0&0&0&0.5&0.5\\ \end{bmatrix}

c) Give the initial state vector for starting at state 2, and compute the state distribution at t=1t=1

# Initial state distribution at time t=0. This is our one-hot vector
x0 = np.array([0, 0, 1, 0, 0, 0])
# matrix multiplication instead of element multiplication
x1 = np.matmul(x0, p)
x1 = [0.0, 0.5, 0.0, 0.5, 0.0, 0.0]

d) Compute the state distribution for t=2, t=4, t=10, t=20

x2 = np.matmul(x0, np.linalg.matrix_power(p, 2))
x2: [0.25, 0.00, 0.50, 0.00, 0.25, 0.00]

x4 = np.matmul(x0, np.linalg.matrix_power(p, 4))
x4: [0.2500, 0.0625, 0.3750, 0.00, 0.250, 0.0625]

x10 = np.matmul(x0, np.linalg.matrix_power(p, 10))
x10: [0.2060, 0.1269, 0.2460, 0.878, 0.2060, 0.1269]

x20 = np.matmul(x0, np.linalg.matrix_power(p, 20))
x20: [0.1760, 0.1572, 0.1854, 0.1478, 0.1760, 0.1572]

Exercise 6.2 - Navigation Agent

Parts of the AND-OR Tree

Exercise 6.3 - Car Rental

  1. Option One

    𝔼(5 GenCars)=5×(330($175$25)25×$30$40,000)=5×$8,450=$42,250𝔼(\text{5 GenCars})=5\times(330(\$175-\$25)-25\times\$30-\$40,000)=5\times\$8,450\\=\$42,250

  2. Option Two

    𝔼(2 Teslas)=2×(0.75(330($500$10)35×($30+$5))+0.25(330($5)35×($30+$5))$120,000)=$60,712.5$61,437.5=$725𝔼(\text{2 Teslas})=2\times (0.75(330(\$500-\$10)-35\times(\$30+\$5))+0.25(330(-\$5)-35\times(\$30+\$5))-\$120,000)=\$60,712.5-\$61,437.5\\=-\$725

  3. Option Three

    𝔼(2 +Teslas)=725+2(0.75(330×$100$20,000)+0.25(330($5)35×($30+5))$120,000)=$725+$9,500=$8,775𝔼(\text{2 +Teslas})=-725+2(0.75(330\times\$100-\$20,000)+0.25(330(-\$5)-35\times(\$30+5))-\$120,000)=-\$725+\$9,500\\=\$8,775

3