Skip to main content
The final exam covers the whole syllabus: learning and neural networks, object detection, state estimation, wheeled-robot kinematics, SLAM, planning, MDPs, reinforcement learning, and vision-language models and transfer to real robots. The questions below are the kind you can expect. Each has a worked solution. Try each question before you read its solution.

Question 1, Multinomial Log-Likelihood (15 points)

A multiclass classifier with KK classes outputs the probability of class kk given input x\mathbf{x} via the softmax: P(y=k∣x)=exp⁡(x⊤wk)∑j=1Kexp⁡(x⊤wj)P(y = k \mid \mathbf{x}) = \frac{\exp(\mathbf{x}^\top \mathbf{w}_k)}{\sum_{j=1}^{K} \exp(\mathbf{x}^\top \mathbf{w}_j)} Write down the log-likelihood expression for a single training example (x,y)(\mathbf{x}, y) under this multinomial model. Your derivation should follow the same steps used in the course for the binary cross-entropy loss.

Solution

For a single example with true class yy, the probability assigned by the model is P(y∣x)P(y \mid \mathbf{x}). Using indicator notation, we can write the log-likelihood as: log⁡p(y∣x)=∑k=1K1[y=k] log⁡P(y=k∣x)\log p(y \mid \mathbf{x}) = \sum_{k=1}^{K} \mathbf{1}[y = k]\, \log P(y = k \mid \mathbf{x}) Substituting the softmax expression: =∑k=1K1[y=k][x⊤wk−ln⁡∑j=1Kexp⁡(x⊤wj)]= \sum_{k=1}^{K} \mathbf{1}[y = k] \left[ \mathbf{x}^\top \mathbf{w}_k - \ln\sum_{j=1}^{K} \exp(\mathbf{x}^\top \mathbf{w}_j) \right] Since exactly one indicator is 1 (the true class cc), this simplifies to: =x⊤wc−ln⁡∑j=1Kexp⁡(x⊤wj)= \mathbf{x}^\top \mathbf{w}_c - \ln\sum_{j=1}^{K}\exp(\mathbf{x}^\top \mathbf{w}_j) The negative of this expression (averaged over mm training examples) is the categorical cross-entropy loss minimized during training. Providing the expression for the full dataset (summed over mm examples) is also acceptable.

Question 2, SGD Jitter, Momentum, and Convergence (15 points)

The figure in your notes shows a contour plot of a loss function in weight space together with the SGD trajectory as it searches for the minimum. The trajectory exhibits substantial jitter. (A) (5 points) Is this the best trajectory you can think of? (B) (5 points) Why is there so much jitter? (C) (5 points) A colleague suggests that adding a fraction of the previous update vector to the current update improves convergence. Do you agree? If so, why? Recall the weight update: wk+1=wk−η∇wL(wk)\mathbf{w}_{k+1} = \mathbf{w}_k - \eta \nabla_{\mathbf{w}} L(\mathbf{w}_k)

Solution

(A) No. The jittery trajectory converges very slowly; a smoother, more direct path would be preferable. (B) The axes of the contour plot represent the model parameters w\mathbf{w}. The jitter arises because the two parameter dimensions have very different dynamic ranges (the loss surface is elongated). A single learning rate η\eta is simultaneously too large for the steep direction and too small for the flat direction, causing oscillation in the steep direction. (C) Yes. Adding a fraction β\beta of the previous update implements a momentum (exponential moving average) update: Vk+1=βVk+(1−β) ∇wL(wk),wk+1=wk−η Vk+1V_{k+1} = \beta V_k + (1-\beta)\, \nabla_{\mathbf{w}} L(\mathbf{w}_k), \qquad \mathbf{w}_{k+1} = \mathbf{w}_k - \eta\, V_{k+1} The averaging filters out high-frequency noise in the gradient, resulting in a much smoother, more direct trajectory and faster convergence, as illustrated by the right-hand plot in the notes.

Question 3, CNN Parameter Count and Output Size (15 points)

Consider a CNN trained to classify 64×64 RGB images (3 channels) into 3 vehicle classes (cars, trucks, motorcycles). The architecture is:
  • Conv1: 32 filters, kernel 3×33 \times 3, stride 1, ReLU
  • MaxPool1: 2×22 \times 2, stride 2
  • Conv2: 64 filters, kernel 3×33 \times 3, stride 1, ReLU
  • MaxPool2: 2×22 \times 2, stride 2
  • Conv3: 128 filters, kernel 3×33 \times 3, stride 1, ReLU
  • MaxPool3: 2×22 \times 2, stride 2
  • FC1: 512 neurons, ReLU
  • Output: 3 neurons, softmax

PS3.A (5 points)

How many trainable parameters does Conv1 have?

PS3.B (5 points)

What is the output spatial size of Conv1 (assuming no padding)?

PS3.C (5 points)

What is the effect of increasing the number of filters in a convolutional layer on the parameter count and on the model’s performance?

Solution

PS3.A, Parameters in Conv1. Each of the 32 filters has size 3×3×33 \times 3 \times 3 (spatial × input channels). Including one bias per filter: params=32×(3×3×3+1)=32×28=896\text{params} = 32 \times (3 \times 3 \times 3 + 1) = 32 \times 28 = \mathbf{896} (Without biases: 32×27=86432 \times 27 = 864. Both values are acceptable.) PS3.B, Output size of Conv1 (no padding, stride 1): output=64−31+1=62⇒62×62×32\text{output} = \frac{64 - 3}{1} + 1 = 62 \quad \Rightarrow \quad \mathbf{62 \times 62 \times 32} PS3.C, Effect of more filters. Increasing the filter count proportionally increases the number of trainable parameters (more weights to store and update). With more filters the network can learn a richer set of feature detectors, which generally improves performance on complex tasks. The trade-offs are higher memory and compute cost, and a greater risk of overfitting on small datasets.

Question 4, IoU and Non-Maximum Suppression (15 points)

Boxes are given as (x1,y1,x2,y2)(x_1, y_1, x_2, y_2) in pixels, the top left and bottom right corners. A detector returns three person detections:
  1. (5 points) Compute the intersection over union (IoU) of D1 with D2, and of D1 with D3.
  2. (5 points) Apply non-maximum suppression (NMS) with an IoU threshold of 0.5. Which detections remain?
  3. (5 points) Suppose D1 and D2 are in fact two different people, one standing behind the other. What does NMS do to the recall in that case, and what can you change to reduce the damage?

Solution

1. IoU. Each box is 40×4040 \times 40, so each has area 1600. D1 and D2 overlap on (12,12,50,50)(12, 12, 50, 50), an area of 38×38=144438 \times 38 = 1444: IoU(D1,D2)=14441600+1600−1444=14441756≈0.82\text{IoU}(D1, D2) = \frac{1444}{1600 + 1600 - 1444} = \frac{1444}{1756} \approx 0.82 D1 and D3 overlap on (30,30,50,50)(30, 30, 50, 50), an area of 20×20=40020 \times 20 = 400: IoU(D1,D3)=4001600+1600−400=4002800≈0.14\text{IoU}(D1, D3) = \frac{400}{1600 + 1600 - 400} = \frac{400}{2800} \approx 0.14 2. NMS. Sort by score and keep D1, the highest. D2 overlaps D1 with IoU 0.82 > 0.5, so it is suppressed. D3 overlaps D1 with IoU 0.14 < 0.5, so it is kept. The output is D1 and D3. 3. Crowded scenes. NMS assumes that two boxes with a large overlap describe the same object. When two people really do overlap, the lower-scoring one is removed, and the detector misses it, so recall drops. A higher IoU threshold keeps more overlapping boxes but lets more duplicates through, which lowers precision. Soft-NMS reduces the score of an overlapping box in proportion to the overlap instead of deleting it, so a second object can survive if its score was high. Detectors that predict a set of boxes directly, such as DETR, do not need NMS at all.

Question 5, Hidden Markov Model Transition / Observation Models (15 points)

To model humidity as a proxy for temperature, let the hidden state xt∈{H,C}x_t \in \{H,C\} (hot, cold) with transition table Ht+1Ct+1Ht0.70.3Ct0.40.6\begin{array}{c|cc} & H_{t+1} & C_{t+1} \\ \hline H_t & 0.7 & 0.3 \\ C_t & 0.4 & 0.6 \end{array} and observable humidity zt∈{S,M,L}z_t \in \{S, M, L\} with emission table SMLH0.10.40.5C0.70.20.1\begin{array}{c|ccc} & S & M & L \\ \hline H & 0.1 & 0.4 & 0.5 \\ C & 0.7 & 0.2 & 0.1 \end{array} (a) Write out the transition and measurement models as conditional probabilities. (b) Explain qualitatively how you would compute the posterior p(xt∣z1:t)p(x_t | z_{1:t}) for the observation sequence “SMSL” using the forward algorithm.

Solution

(a) Transition model: p(xt+1=H∣xt=H)=0.7,p(xt+1=C∣xt=H)=0.3p(x_{t+1}=H \mid x_t=H) = 0.7, \quad p(x_{t+1}=C \mid x_t=H) = 0.3 p(xt+1=H∣xt=C)=0.4,p(xt+1=C∣xt=C)=0.6p(x_{t+1}=H \mid x_t=C) = 0.4, \quad p(x_{t+1}=C \mid x_t=C) = 0.6 Measurement model: p(z=S∣H)=0.1, p(z=M∣H)=0.4, p(z=L∣H)=0.5p(z=S|H)=0.1,\ p(z=M|H)=0.4,\ p(z=L|H)=0.5 p(z=S∣C)=0.7, p(z=M∣C)=0.2, p(z=L∣C)=0.1p(z=S|C)=0.7,\ p(z=M|C)=0.2,\ p(z=L|C)=0.1 (b) The forward algorithm initializes α1(x1)=p(x1) p(z1∣x1)\alpha_1(x_1) = p(x_1)\,p(z_1\mid x_1) with a prior over the initial state, then recursively updates αt(xt)=p(zt∣xt)∑xt−1p(xt∣xt−1) αt−1(xt−1).\alpha_t(x_t) = p(z_t\mid x_t) \sum_{x_{t-1}} p(x_t\mid x_{t-1})\, \alpha_{t-1}(x_{t-1}). The filtered posterior is p(xt∣z1:t)=αt(xt)/∑xtαt(xt)p(x_t\mid z_{1:t}) = \alpha_t(x_t) / \sum_{x_t} \alpha_t(x_t). Apply this once per observation in “SMSL” to obtain the posterior at each step.

Question 6, Localization in a Cyclic World (20 points)

A car lives in a cyclic world of three cells, st∈{b0,b1,b2}s_t \in \{b_0, b_1, b_2\}. Moving right from b2b_2 brings it to b0b_0. Each cell has a waypoint that a sensor can detect: At t=0t = 0 you know nothing about the state. At each of t=1,2,3t = 1, 2, 3 the car is commanded to move one cell right, but its control is faulty: p(st+1=bi+1∣st=bi)=0.9,p(st+1=bi∣st=bi)=0.05,p(st+1=bi+2∣st=bi)=0.05,\begin{aligned} p(s_{t+1} = b_{i+1} \mid s_t = b_i) &= 0.9, \\ p(s_{t+1} = b_i \mid s_t = b_i) &= 0.05, \\ p(s_{t+1} = b_{i+2} \mid s_t = b_i) &= 0.05, \end{aligned} with indices modulo 3. The sensor model is p(z=w∣b1)=0.9,p(z=w∣b0 or b2)=0.1,p(z=w′∣b1)=0.1,p(z=w′∣b0 or b2)=0.9.\begin{aligned} p(z = w \mid b_1) &= 0.9, & p(z = w \mid b_0 \text{ or } b_2) &= 0.1, \\ p(z = w' \mid b_1) &= 0.1, & p(z = w' \mid b_0 \text{ or } b_2) &= 0.9. \end{aligned} After each move the sensor reports z1=w′z_1 = w', z2=w′z_2 = w' and z3=wz_3 = w. Using the Bayes filter, find the most probable location at t=3t = 3. You may leave the calculations as matrix-vector products.

Solution

Write the belief as a vector over (b0,b1,b2)(b_0, b_1, b_2). Each step predicts with the transition matrix, then multiplies by the likelihood of the measurement and normalizes. The likelihood vectors are (0.9,0.1,0.9)(0.9, 0.1, 0.9) for w′w' and (0.1,0.9,0.1)(0.1, 0.9, 0.1) for ww. For example, at t=2t = 2 the prediction for b1b_1 is 0.9⋅0.474+0.05⋅0.053+0.05⋅0.474=0.4530.9 \cdot 0.474 + 0.05 \cdot 0.053 + 0.05 \cdot 0.474 = 0.453: the car moved right from b0b_0, stayed in b1b_1, or jumped two cells from b2b_2. The uniform prior stays uniform under the first prediction, because every cell receives the same total probability. At t=3t = 3 the car is most probably in b1b_1, with probability 0.95. The two w′w' readings favor b0b_0 after t=2t = 2, the faulty but mostly reliable move takes it to b1b_1, and the ww reading confirms it.

Question 7, Kalman Filter Behaviour and Noise Trade-offs (10 points)

An agent moves in a 1-D world with constant velocity. A scalar Kalman filter is implemented with equal process and measurement noise standard deviations σv=σw=5\sigma_v = \sigma_w = 5. (a) Explain why, at the start of filtering, the estimate tracks the noisy measurements closely, whereas after several steps the estimate smooths over them. (b) What happens if the process-noise variance is set too low? Too high? (c) If the measurement matrix Ct=0C_t = 0, is a meaningful state estimate still possible? Why or why not?

Solution

(a) The Kalman gain Kt=Pt∣t−1Pt∣t−1+σw2K_t = \frac{P_{t|t-1}}{P_{t|t-1} + \sigma_w^2} is close to 1 when the predicted covariance Pt∣t−1P_{t|t-1} is large (initial uncertainty), so the update weights the measurement heavily. As iterations proceed, Pt∣tP_{t|t} decreases and the gain converges to its (nonzero) steady-state value, so the filter blends prediction and measurement in a fixed ratio rather than tracking each measurement directly, visually this looks like smoothing. (b) If the process variance is set artificially low, the filter becomes over-confident in its model and fails to react to real changes in the system. Set it too high and the filter becomes over-reactive, essentially mirroring the noisy measurements. (c) No. If Ct=0C_t = 0, the measurement carries no information about the state (ztz_t is independent of xtx_t), so the correction step is a no-op. The filter degenerates into pure prediction and its covariance grows unboundedly.

Question 8, Kalman Filter Statements (15 points)

A linear Gaussian system has the motion and measurement models st=Atst−1+Btat+εt,εt∼N(0,Qt),zt=Ctst+δt,δt∼N(0,Rt),s_t = A_t s_{t-1} + B_t a_t + \varepsilon_t, \quad \varepsilon_t \sim \mathcal N(0, Q_t), \qquad z_t = C_t s_t + \delta_t, \quad \delta_t \sim \mathcal N(0, R_t), with st∈Rns_t \in \mathbb R^n, at∈Rma_t \in \mathbb R^m and zt∈Rkz_t \in \mathbb R^k. The Kalman filter computes μˉt=Atμt−1+Btat,Σˉt=AtΣt−1At⊤+QtKt=ΣˉtCt⊤(CtΣˉtCt⊤+Rt)−1μt=μˉt+Kt(zt−Ctμˉt),Σt=(I−KtCt) Σˉt\begin{aligned} \bar\mu_t &= A_t \mu_{t-1} + B_t a_t, \qquad \bar\Sigma_t = A_t \Sigma_{t-1} A_t^\top + Q_t \\ K_t &= \bar\Sigma_t C_t^\top \big(C_t \bar\Sigma_t C_t^\top + R_t\big)^{-1} \\ \mu_t &= \bar\mu_t + K_t (z_t - C_t \bar\mu_t), \qquad \Sigma_t = (I - K_t C_t)\, \bar\Sigma_t \end{aligned} Which of the following statements is or are correct? A. If Ct=0C_t = \mathbf 0 for all tt, then the Kalman filter cannot compute a meaningful estimate of the state from the measurements. B. The Kalman gain KtK_t depends on the measurements z1:tz_{1:t}. C. None of the statements above is correct.

Solution

A is correct. With Ct=0C_t = \mathbf 0 the measurement zt=δtz_t = \delta_t is pure noise and carries no information about the state. The gain is Kt=0K_t = \mathbf 0, so the update leaves μˉt\bar\mu_t and Σˉt\bar\Sigma_t unchanged. The filter only predicts, and its covariance grows with every step. B is wrong. KtK_t is computed from Σˉt\bar\Sigma_t, CtC_t and RtR_t only. The covariances do not depend on the measured values, so the gains for a linear system can even be computed before any measurement arrives. The measurements enter only through the innovation zt−Ctμˉtz_t - C_t \bar\mu_t in the mean update. C is therefore wrong as well.

Question 9, Differential-Drive Kinematics and Odometry (20 points)

A TurtleBot3 has wheel radius r=0.033r = 0.033 m and half track d=0.08d = 0.08 m (the wheels are 2d=0.162d = 0.16 m apart). Its configuration is q=(θ,x,y)q = (\theta, x, y). The left and right wheels turn at uL=5u_L = 5 rad/s and uR=7u_R = 7 rad/s.
  1. (5 points) Compute the forward speed vv, the turn rate ω\omega, and the radius of the circle the robot drives.
  2. (8 points) The robot starts at q=(0,0,0)q = (0, 0, 0) and holds these wheel speeds for Δt=1\Delta t = 1 s. Compute its exact pose at the end. Compare it with the single Euler step x←x+vcos⁡θ Δtx \leftarrow x + v \cos\theta\,\Delta t, y←y+vsin⁡θ Δty \leftarrow y + v \sin\theta\,\Delta t, θ←θ+ω Δt\theta \leftarrow \theta + \omega\,\Delta t.
  3. (4 points) Write the constraint that makes this robot nonholonomic. Can the robot reach the pose (0,0,0.5)(0, 0, 0.5), 0.5 m to its left with the same heading? Explain.
  4. (3 points) Give one systematic and one random source of odometry error, and say which one calibration can remove.

Solution

1. Body twist. v=r2(uL+uR)=0.0332⋅12=0.198 m/s,ω=r2d(uR−uL)=0.0330.16⋅2=0.4125 rad/s\begin{aligned} v &= \frac{r}{2}(u_L + u_R) = \frac{0.033}{2} \cdot 12 = 0.198 \text{ m/s}, \\ \omega &= \frac{r}{2d}(u_R - u_L) = \frac{0.033}{0.16} \cdot 2 = 0.4125 \text{ rad/s} \end{aligned} The radius is v/ω=0.198/0.4125=0.48v / \omega = 0.198 / 0.4125 = 0.48 m, with the center of the circle to the robot’s left. 2. Exact pose. With a constant twist the robot drives an arc. After Δt=1\Delta t = 1 s, θ=ω Δt=0.4125\theta = \omega\,\Delta t = 0.4125 rad, and x=vωsin⁡θ=0.48⋅0.4009≈0.192 m,y=vω(1−cos⁡θ)=0.48⋅0.0839≈0.040 m\begin{aligned} x &= \frac{v}{\omega}\sin\theta = 0.48 \cdot 0.4009 \approx 0.192 \text{ m}, \\ y &= \frac{v}{\omega}(1 - \cos\theta) = 0.48 \cdot 0.0839 \approx 0.040 \text{ m} \end{aligned} The Euler step uses the initial heading for the whole second and gives (θ,x,y)=(0.4125,0.198,0)(\theta, x, y) = (0.4125, 0.198, 0). It misses the 4 cm of sideways displacement and overshoots in xx by 6 mm. Odometry therefore integrates over short steps, or uses the exact arc (the matrix exponential of the twist). 3. Nonholonomic constraint. The wheels do not slide sideways, so the lateral body velocity is zero: vby=−sin⁡θ x˙+cos⁡θ y˙=0v_{by} = -\sin\theta\,\dot x + \cos\theta\,\dot y = 0 This restricts velocities, not configurations, so it cannot be integrated into a constraint on qq. The robot cannot move straight sideways, but it can still reach (0,0,0.5)(0, 0, 0.5) by maneuvering: turn left, drive, turn right, drive back, as when you parallel-park a car. 4. Odometry errors. A systematic error is a wheel radius or a track width that differs from its nominal value; it biases every step in the same direction, and calibration removes it. A random error is wheel slip on a smooth or uneven floor, or quantization of the encoder counts; it differs from step to step, calibration cannot remove it, and it is why the uncertainty of the pose estimate grows over time.

Question 10, EKF SLAM State and Cost (15 points)

A planar robot runs EKF SLAM with NN point landmarks. The state stacks the robot pose (x,y,θ)(x, y, \theta) and the position (mj,x,mj,y)(m_{j,x}, m_{j,y}) of each landmark.
  1. (4 points) For N=100N = 100, what are the dimensions of the state vector and of its covariance matrix Σt\Sigma_t? How many numbers does Σt\Sigma_t hold?
  2. (4 points) How does the cost of one measurement update grow with NN? What limits EKF SLAM in large environments?
  3. (4 points) At the start, the landmark estimates are uncorrelated. Explain why they become correlated with each other as the robot drives, even though the landmarks do not move.
  4. (3 points) The robot returns to a landmark it saw at the start (a loop closure). What happens to the uncertainty of the other landmarks, and why?

Solution

1. Dimensions. The state has 3+2N=2033 + 2N = 203 entries and Σt\Sigma_t is 203×203203 \times 203, holding 2032=41,209203^2 = 41{,}209 numbers (about half of them distinct, since Σt\Sigma_t is symmetric). 2. Cost. The update touches the whole covariance: Σt=(I−KtHt)Σˉt\Sigma_t = (I - K_t H_t)\bar\Sigma_t costs O(N2)O(N^2) per observed landmark, and memory is also O(N2)O(N^2). With thousands of landmarks this becomes too slow for real time. A second limit is data association: EKF SLAM assumes each measurement is matched to the right landmark, and one wrong match can corrupt the estimate permanently. 3. Correlations. The robot measures each landmark relative to its own uncertain pose. Two landmarks observed from the same pose inherit the same pose error, so if the robot’s estimate is 10 cm too far left, both landmark estimates are shifted 10 cm left together. The off-diagonal blocks of Σt\Sigma_t record this shared error. The correlations are not a defect: they are what lets the map be consistent. 4. Loop closure. Re-observing a well-known landmark sharply reduces the uncertainty of the robot pose. Through the correlations in Σt\Sigma_t, the update then also corrects and shrinks the uncertainty of every landmark that was observed from the poses along the loop. Without the off-diagonal terms, the correction would stay with the one re-observed landmark.

Question 11, Gridworld Policies and the Bellman Equation (15 points)

Consider a 3×4 gridworld with 2 terminal states and 1 wall (impassable). The agent has 4 deterministic actions (N, S, E, W). (a) How many deterministic policies exist in this gridworld? Give both the general formula and the numerical answer. (b) In a separate 5×5 gridworld under a uniform random policy with discount γ=0.9\gamma = 0.9, there are two special states A and B. State A teleports the agent to A’ with reward +10; state B teleports to B’ with reward +5. Using the Bellman policy-evaluation equation v(s)=∑aπ(a∣s)∑s′p(s′∣s,a)[r(s,a,s′)+γv(s′)],v(s) = \sum_a \pi(a|s) \sum_{s'} p(s'|s,a)\bigl[r(s,a,s') + \gamma v(s')\bigr], explain qualitatively why v(A)<10v(A) < 10 while v(B)>5v(B) > 5.

Solution

(a) The number of deterministic policies is ∣Π∣=∣A∣∣S∣|\Pi| = |A|^{|S|} where ∣S∣|S| is the number of non-terminal states. The grid has 3×4=123\times 4 = 12 cells minus 2 terminal and 1 wall, giving ∣S∣=9|S|=9. Hence ∣Π∣=49=262,144.|\Pi| = 4^9 = 262{,}144. (A common error is to write ∣S∣∣A∣|S|^{|A|}, which is incorrect.) (b) Because the teleports are deterministic, the Bellman equation reduces to v(A)=10+γ v(A′)v(A) = 10 + \gamma\, v(A') and v(B)=5+γ v(B′)v(B) = 5 + \gamma\, v(B'). The value of A depends on where the teleport lands, not only on its reward. A’ is on the bottom edge of the grid. From there the random policy often tries to step off the grid, which costs −1-1 and leaves the agent where it is, so v(A′)v(A') is negative, about −1.3-1.3 in Sutton and Barto’s example. Then v(A)≈10+0.9⋅(−1.3)≈8.8<10v(A) \approx 10 + 0.9 \cdot (-1.3) \approx 8.8 < 10. B’ is in the middle row, away from the edges and close enough to A and B to collect some of their rewards later, so v(B′)≈0.4>0v(B') \approx 0.4 > 0. Then v(B)≈5+0.9⋅0.4≈5.3>5v(B) \approx 5 + 0.9 \cdot 0.4 \approx 5.3 > 5. The Bellman equation counts the whole discounted stream of rewards after the teleport, and the stream after A’ is negative while the stream after B’ is positive.

Question 12, Return Computation and Discounting (15 points)

An MDP has a single non-terminal state S0S_0 with two actions, LL and RR. Action LL yields rewards 1,0,1,0,…1, 0, 1, 0, \dots, while action RR yields 0,2,0,2,…0, 2, 0, 2, \dots. Compute VL(S0)V_L(S_0) and VR(S0)V_R(S_0) in closed form as functions of the discount γ\gamma, and determine the values of γ\gamma for which LL is preferred over RR.

Solution

For action LL: VL(S0)=1+γ2+γ4+⋯=∑k=0∞γ2k=11−γ2.V_L(S_0) = 1 + \gamma^2 + \gamma^4 + \cdots = \sum_{k=0}^{\infty} \gamma^{2k} = \frac{1}{1-\gamma^2}. Equivalently, the Bellman recursion VL(S0)=1+γ2VL(S0)V_L(S_0) = 1 + \gamma^2 V_L(S_0) gives the same answer. For action RR: VR(S0)=2γ+2γ3+⋯=2γ∑k=0∞γ2k=2γ1−γ2.V_R(S_0) = 2\gamma + 2\gamma^3 + \cdots = 2\gamma \sum_{k=0}^{\infty} \gamma^{2k} = \frac{2\gamma}{1-\gamma^2}. Comparing:
  • If γ<0.5\gamma < 0.5: VL>VRV_L > V_R, prefer LL.
  • If γ=0.5\gamma = 0.5: they are equal.
  • If γ>0.5\gamma > 0.5: VR>VLV_R > V_L, prefer RR.
A far-sighted agent (large γ\gamma) prefers the larger but delayed reward; a myopic agent prefers the immediate reward.

Question 13, Maze With an Unknown Goal (20 points)

The maze below has a start S and two terminal cells, both marked H. A maze of white cells on a black background. Two H cells sit at the top left and top right corners, joined by a horizontal corridor of seven cells. A vertical corridor runs down from the middle of that corridor through the start cell S to a bottom corridor that turns right for three more cells. The agent does not know which H gives the positive reward: one gives +100 and the other −100, each with probability 0.5. Every move costs −1. The agent may stay put, or move one cell north, south, east or west. Once it reaches an H, the episode ends.
  1. (5 points) What is the expected reward at a terminal state?
  2. (5 points) What is the optimal policy if the agent may stay put? Write the state values in the white cells.
  3. (5 points) What is the optimal policy if the agent must move? Write the state values in the white cells.
  4. (5 points) How many deterministic policies does this gridworld have? Explain.

Solution

1. The expected reward at either H is 0.5⋅100+0.5⋅(−100)=00.5 \cdot 100 + 0.5 \cdot (-100) = 0. 2. Reaching an H is worth 0 in expectation, and every move costs 1, so moving can only lose. The optimal policy is to stay put, and every white cell has value 0. 3. Now the agent must pay −1 per step, and the episode ends only at an H, which is worth 0. The best it can do is reach the nearest H as fast as possible, so each cell’s value is minus its distance to the nearest H: The same maze with the value of each cell. The H cells are 0. The top corridor reads -1, -2, -3, -4, -3, -2, -1 from left to right. The vertical corridor reads -5, -6, -7 at S, -8, -9 going down, and the bottom corridor reads -10, -11, -12, -13 going right. The optimal policy moves toward the nearest H. In the middle of the top corridor, at value −4, both directions are optimal. 4. A deterministic policy picks one action in every non-terminal state, so ∣Π∣=∣A∣∣S∣|\Pi| = |A|^{|S|}. The maze has 16 non-terminal white cells: 7 in the top corridor, 5 in the vertical corridor and 4 in the bottom corridor. With the four moves only, ∣Π∣=416≈4.3×109|\Pi| = 4^{16} \approx 4.3 \times 10^9. If staying put is also an action, ∣Π∣=516≈1.5×1011|\Pi| = 5^{16} \approx 1.5 \times 10^{11}.

Question 14, Recycling Robot Optimal Policy (20 points)

The recycling robot has battery states high and low. In high it can search or wait; in low it can search, wait or recharge.
  • Searching from high keeps the battery high with probability α=0.8\alpha = 0.8 and drains it to low with probability 0.20.2. The reward is rsearch=2r_{\text{search}} = 2 either way.
  • Searching from low keeps it low with probability β=0.4\beta = 0.4, with reward 2. With probability 0.60.6 the battery runs flat, the robot is rescued and recharged to high, and the reward is −3-3.
  • Waiting keeps the battery state and gives rwait=1r_{\text{wait}} = 1.
  • Recharging moves low to high with reward 0.
With γ=0.9\gamma = 0.9:
  1. (8 points) Write the Bellman optimality equations for v∗(high)v_*(\text{high}) and v∗(low)v_*(\text{low}).
  2. (12 points) Find the optimal policy and the optimal values, by value iteration or by solving the equations for a guessed policy and checking that it is greedy.

Solution

1. Bellman optimality. v∗(h)=max⁡{ 2+0.9 [0.8 v∗(h)+0.2 v∗(l)],  1+0.9 v∗(h) }v∗(l)=max⁡{ 0.4 [2+0.9 v∗(l)]+0.6 [−3+0.9 v∗(h)],  1+0.9 v∗(l),  0.9 v∗(h) }\begin{aligned} v_*(h) &= \max\big\{\, 2 + 0.9\,[0.8\, v_*(h) + 0.2\, v_*(l)],\ \ 1 + 0.9\, v_*(h) \,\big\} \\ v_*(l) &= \max\big\{\, 0.4\,[2 + 0.9\, v_*(l)] + 0.6\,[-3 + 0.9\, v_*(h)],\ \ 1 + 0.9\, v_*(l),\ \ 0.9\, v_*(h) \,\big\} \end{aligned} 2. Solution. Guess the policy high → search, low → recharge. Its values satisfy v(h)=2+0.72 v(h)+0.18 v(l),v(l)=0.9 v(h),v(h) = 2 + 0.72\, v(h) + 0.18\, v(l), \qquad v(l) = 0.9\, v(h), so v(h)=2/(1−0.72−0.162)=1000/59≈16.95v(h) = 2 / (1 - 0.72 - 0.162) = 1000/59 \approx 16.95 and v(l)=900/59≈15.25v(l) = 900/59 \approx 15.25. The action values are The guessed actions have the largest q∗q_* in both states, so the policy is greedy with respect to its own values, and it is optimal: π∗(high)=search\pi_*(\text{high}) = \text{search} and π∗(low)=recharge\pi_*(\text{low}) = \text{recharge}. Value iteration from v=0v = 0 converges to the same numbers. Searching on a low battery risks the −3 rescue too often to beat recharging.

Question 15, SARSA and Q-Learning Updates (15 points)

A robot is in state ss with Q(s,a)=3Q(s, a) = 3. It takes action aa, receives reward r=−1r = -1 and lands in state s′s', where Q(s′,a1)=2Q(s', a_1) = 2 and Q(s′,a2)=5Q(s', a_2) = 5. Its ϵ\epsilon-greedy policy happens to pick a′=a1a' = a_1 as the next action, an exploratory move. Use α=0.5\alpha = 0.5 and γ=0.9\gamma = 0.9.
  1. (5 points) Compute the updated Q(s,a)Q(s, a) under SARSA.
  2. (5 points) Compute the updated Q(s,a)Q(s, a) under Q-learning.
  3. (5 points) Explain the difference in terms of on-policy and off-policy learning. In a cliff-walking world, which of the two learns the safer path, and why?

Solution

1. SARSA uses the action actually taken next: Q(s,a)←3+0.5 [−1+0.9⋅2−3]=3+0.5⋅(−2.2)=1.9Q(s, a) \leftarrow 3 + 0.5\,\big[-1 + 0.9 \cdot 2 - 3\big] = 3 + 0.5 \cdot (-2.2) = 1.9 2. Q-learning uses the greedy action in the target: Q(s,a)←3+0.5 [−1+0.9⋅max⁡(2,5)−3]=3+0.5⋅0.5=3.25Q(s, a) \leftarrow 3 + 0.5\,\big[-1 + 0.9 \cdot \max(2, 5) - 3\big] = 3 + 0.5 \cdot 0.5 = 3.25 3. On-policy and off-policy. SARSA is on-policy: it learns the value of the ϵ\epsilon-greedy policy it actually follows, including the cost of its exploratory moves. Q-learning is off-policy: it learns the value of the greedy policy, whatever the exploration does. Next to a cliff, random exploratory steps sometimes fall off. SARSA’s values include those falls, so the path it learns stays away from the edge. Q-learning’s values assume the robot will act greedily, so it learns the shortest path along the edge, and while it is still exploring it falls more often. For a physical robot that explores while it learns, the SARSA behavior is usually the one you want.

Found an error on this page? Report an issue.