Level 5 — MasteryMachine Learning (Aerospace Applications)

Machine Learning (Aerospace Applications)

2 minutes60 marksprintable — key stays hidden on paper

Level 5 — Mastery (Cross-domain: Mathematics + Physics + Coding) Time limit: 2 hours 30 minutes Total marks: 60

Instructions: Attempt all three questions. Show full derivations; state assumptions. Pseudocode/NumPy-style code is accepted where requested. Marks are indicated per part.


Question 1 — Regularized Regression, Bias–Variance & Cross-Validation (20 marks)

An aerospace team fits a linear model y^=Xθ\hat{y} = X\theta (with XRn×dX\in\mathbb{R}^{n\times d}, yRny\in\mathbb{R}^n) to estimate aerodynamic drag from sensor features.

(a) Starting from the ridge objective J(θ)=12Xθy22+λ2θ22,J(\theta) = \tfrac{1}{2}\lVert X\theta - y\rVert_2^2 + \tfrac{\lambda}{2}\lVert\theta\rVert_2^2, derive the closed-form (normal-equation) solution θ\theta^\star. Prove that for any λ>0\lambda>0 the solution is unique even when XXX^\top X is singular. (6)

(b) Consider the scalar case X=1X = \mathbf{1} shape (n,1)(n,1) of all-ones and a single parameter θ\theta, so y^=θ\hat y=\theta. With data mean yˉ=1nyi\bar y = \tfrac1n\sum y_i, show that the ridge estimate is θ=nyˉn+λ\theta^\star = \dfrac{n\bar y}{n+\lambda}, and interpret the shrinkage as λ\lambda increases. (4)

(c) Decompose the expected squared prediction error at a point into (irreducible) noise, bias2^2, and variance. Explain physically why increasing λ\lambda moves a drag-estimation model along the bias–variance trade-off, and sketch the qualitative curves of bias2^2, variance, and total error vs. λ\lambda. (6)

(d) You have n=100n=100 flight-test samples and use k=5k=5-fold cross-validation to select λ\lambda. State how many models are trained, the size of each train/validation split, and one reason why L1 (lasso) rather than L2 might be preferred if only a few of d=50d=50 sensors are truly informative. (4)


Question 2 — Backpropagation Through a Small Network (22 marks)

Consider a single hidden-layer network for binary fault detection: z(1)=W1x+b1,h=tanh(z(1)),z(2)=W2h+b2,p^=σ(z(2)),z^{(1)} = W_1 x + b_1,\quad h = \tanh(z^{(1)}),\quad z^{(2)} = W_2 h + b_2,\quad \hat p = \sigma(z^{(2)}), with scalar output, binary cross-entropy loss L=[ylnp^+(1y)ln(1p^)]L = -\big[y\ln\hat p + (1-y)\ln(1-\hat p)\big].

(a) Prove that Lz(2)=p^y\dfrac{\partial L}{\partial z^{(2)}} = \hat p - y. Show every step (do not skip the sigmoid derivative). (5)

(b) Using the chain rule, derive expressions for LW2\dfrac{\partial L}{\partial W_2}, LW1\dfrac{\partial L}{\partial W_1}, and Lb1\dfrac{\partial L}{\partial b_1} in terms of the forward-pass quantities. Recall tanh(u)=1tanh2(u)\tanh'(u)=1-\tanh^2(u). (7)

(c) Numerically evaluate one backprop step for the following 22-input, 11-hidden-unit network. Given x=[12], W1=[0.50.5], b1=0, W2=[1.0], b2=0, y=1.x=\begin{bmatrix}1\\2\end{bmatrix},\ W_1=\begin{bmatrix}0.5 & -0.5\end{bmatrix},\ b_1=0,\ W_2=[1.0],\ b_2=0,\ y=1. Compute (i) z(1)z^{(1)}, hh, z(2)z^{(2)}, p^\hat p; (ii) L/z(2)\partial L/\partial z^{(2)}; (iii) the gradient L/W2\partial L/\partial W_2. Give values to 4 decimal places. (6)

(d) Explain why ReLU is often preferred over tanh\tanh in deep networks, referencing the gradient behaviour of tanh\tanh in part (b), and state one drawback of ReLU. (4)


Question 3 — Reinforcement Learning for Learned Guidance (18 marks)

A guidance controller for a lunar-descent thruster is modelled as an MDP (S,A,P,R,γ)(\mathcal S,\mathcal A,P,R,\gamma).

(a) Write the Bellman optimality equation for the action-value function Q(s,a)Q^\star(s,a) and derive the tabular Q-learning update rule from it, stating the role of the learning rate α\alpha and why it is an off-policy method. (6)

(b) For the REINFORCE policy-gradient method with policy πθ(as)\pi_\theta(a|s), prove that θJ(θ)=Eτπθ ⁣[tθlnπθ(atst)Gt],\nabla_\theta J(\theta) = \mathbb{E}_{\tau\sim\pi_\theta}\!\Big[\sum_t \nabla_\theta \ln\pi_\theta(a_t|s_t)\, G_t\Big], using the log-derivative ("score function") trick. Explain why subtracting a baseline b(st)b(s_t) leaves the estimator unbiased. (7)

(c) A two-state descent task has γ=0.9\gamma=0.9. From state s1s_1, the greedy action gives immediate reward R=5R=5 and transitions to terminal state with Q(term,)=0Q^\star(\text{term},\cdot)=0. After one Q-learning update with α=0.5\alpha=0.5 from initial Q(s1,a)=0Q(s_1,a)=0, compute the new Q(s1,a)Q(s_1,a). Then state the converged value if this reward/transition repeats deterministically. (5)


End of paper.

Answer keyMark scheme & solutions

Question 1

(a) [6] Gradient: J=X(Xθy)+λθ=0\nabla J = X^\top(X\theta - y) + \lambda\theta = 0 (2). Rearranging: (XX+λI)θ=Xy(X^\top X + \lambda I)\theta = X^\top y (1), hence θ=(XX+λI)1Xy.\theta^\star = (X^\top X + \lambda I)^{-1}X^\top y. (1) Uniqueness: XXX^\top X is symmetric PSD with eigenvalues μi0\mu_i\ge 0. Adding λI\lambda I shifts eigenvalues to μi+λ>0\mu_i+\lambda>0 for λ>0\lambda>0, so XX+λIX^\top X+\lambda I is positive-definite, hence invertible; JJ is strictly convex ⇒ unique minimiser (2).

(b) [4] XX=nX^\top X = n, Xy=yi=nyˉX^\top y = \sum y_i = n\bar y (2). Then θ=nyˉn+λ.\theta^\star=\frac{n\bar y}{n+\lambda}. (1) As λ0\lambda\to0, θyˉ\theta^\star\to\bar y (OLS mean); as λ\lambda\to\infty, θ0\theta^\star\to0 — shrinkage toward zero, reducing variance at the cost of bias (1).

(c) [6] E[(yf^)2]=σ2+(Bias[f^])2+Var[f^]\mathbb E[(y-\hat f)^2] = \sigma^2 + (\text{Bias}[\hat f])^2 + \text{Var}[\hat f] (3) where σ2\sigma^2 irreducible noise, Bias =E[f^]f=\mathbb E[\hat f]-f, Var =E[(f^Ef^)2]=\mathbb E[(\hat f-\mathbb E\hat f)^2]. Increasing λ\lambda constrains parameters → less sensitivity to noise in flight data → variance ↓ but model less flexible → bias ↑ (2). Sketch: bias2^2 increasing curve, variance decreasing curve, total error U-shaped with minimum at optimal λ\lambda (1).

(d) [4] 5-fold ⇒ 5 models trained per λ\lambda value (1). Each fold: train on 8080 samples, validate on 2020 (2). L1 induces sparsity (drives irrelevant weights to exactly zero) performing feature selection when only a few sensors matter (1).


Question 2

(a) [5] σ(z)=σ(z)(1σ(z))=p^(1p^)\sigma'(z)=\sigma(z)(1-\sigma(z))=\hat p(1-\hat p) (1). Lp^=yp^+1y1p^=p^yp^(1p^)\dfrac{\partial L}{\partial\hat p} = -\dfrac{y}{\hat p}+\dfrac{1-y}{1-\hat p} = \dfrac{\hat p - y}{\hat p(1-\hat p)} (2). Chain: Lz(2)=Lp^p^(1p^)=p^y\dfrac{\partial L}{\partial z^{(2)}}=\dfrac{\partial L}{\partial\hat p}\cdot\hat p(1-\hat p)=\hat p - y (2).

(b) [7] Let δ2=p^y\delta_2=\hat p-y (scalar). LW2=δ2h\dfrac{\partial L}{\partial W_2}=\delta_2\,h^\top (2). Backprop to hidden: δ1=(W2δ2)(1tanh2z(1))=(W2δ2)(1h2)\delta_1 = (W_2^\top\delta_2)\odot(1-\tanh^2 z^{(1)})=(W_2^\top\delta_2)\odot(1-h^2) (3). LW1=δ1x\dfrac{\partial L}{\partial W_1}=\delta_1 x^\top (1); Lb1=δ1\dfrac{\partial L}{\partial b_1}=\delta_1 (1).

(c) [6] (i) z(1)=0.5(1)+(0.5)(2)=0.51.0=0.5z^{(1)}=0.5(1)+(-0.5)(2)=0.5-1.0=-0.5 (1). h=tanh(0.5)=0.46212h=\tanh(-0.5)=-0.46212 (1). z(2)=1.0(0.46212)=0.46212z^{(2)}=1.0\cdot(-0.46212)=-0.46212; p^=σ(0.46212)=0.38648\hat p=\sigma(-0.46212)=0.38648 (2). (ii) L/z(2)=p^y=0.386481=0.61352\partial L/\partial z^{(2)}=\hat p-y=0.38648-1=-0.61352 (1). (iii) L/W2=δ2h=(0.61352)(0.46212)=0.28352\partial L/\partial W_2=\delta_2 h=(-0.61352)(-0.46212)=0.28352 (1).

(d) [4] tanh\tanh' saturates to 00 for large z|z| ⇒ vanishing gradients in deep stacks slowing learning (2). ReLU has gradient 11 for z>0z>0, avoiding saturation and giving sparse activations (1). Drawback: "dying ReLU" — units stuck at 00 with zero gradient (or non-differentiable at 0) (1).


Question 3

(a) [6] Q(s,a)=E[R+γmaxaQ(s,a)s,a]Q^\star(s,a)=\mathbb E\big[R + \gamma\max_{a'}Q^\star(s',a')\mid s,a\big] (2). Sample-based stochastic approximation gives update: Q(s,a)Q(s,a)+α[r+γmaxaQ(s,a)Q(s,a)].Q(s,a)\leftarrow Q(s,a)+\alpha\big[r+\gamma\max_{a'}Q(s',a')-Q(s,a)\big]. (2) α\alpha weights new TD-target vs. current estimate (controls learning speed/stability) (1). Off-policy: the update uses maxa\max_{a'} (greedy target) regardless of the behaviour policy that generated the action (1).

(b) [7] J(θ)=Eτ[R(τ)]=τPθ(τ)R(τ)J(\theta)=\mathbb E_\tau[R(\tau)]=\sum_\tau P_\theta(\tau)R(\tau). θJ=τθPθ(τ)R(τ)=τPθ(τ)θlnPθ(τ)R(τ)\nabla_\theta J=\sum_\tau \nabla_\theta P_\theta(\tau)R(\tau)=\sum_\tau P_\theta(\tau)\nabla_\theta\ln P_\theta(\tau)R(\tau) (log-trick) (3). lnPθ(τ)=tlnπθ(atst)+(dynamics terms independent of θ)\ln P_\theta(\tau)=\sum_t\ln\pi_\theta(a_t|s_t)+\text{(dynamics terms independent of }\theta), so θlnPθ=tθlnπθ(atst)\nabla_\theta\ln P_\theta=\sum_t\nabla_\theta\ln\pi_\theta(a_t|s_t) (2). Replacing R(τ)R(\tau) with return-to-go GtG_t gives the stated form (1). Baseline unbiased: E[θlnπθ(as)b(s)]=b(s)aθπθ(as)=b(s)θ1=0\mathbb E[\nabla_\theta\ln\pi_\theta(a|s)\,b(s)]=b(s)\sum_a\nabla_\theta\pi_\theta(a|s)=b(s)\nabla_\theta 1=0 (1).

(c) [5] Target =r+γmaxaQ(term,)=5+0.9(0)=5=r+\gamma\max_{a'}Q(\text{term},\cdot)=5+0.9(0)=5 (1). Update: Q0+0.5(50)=2.5Q\leftarrow 0+0.5(5-0)=2.5 (2). Converged (deterministic, terminal next): fixed point Q=r+γ0=5Q=r+\gamma\cdot0=5 (2).

[
  {"claim":"Ridge scalar all-ones estimate n*ybar/(n+lambda)", "code":"n,lam=5,3; ys=[1,2,3,4,5]; ybar=sum(ys)/n; theta=n*ybar/(n+lam); result = abs(theta - (n*ybar/(n+lam)))<1e-12 and abs(theta-2.8125)<1e-9"},
  {"claim":"Q2c forward/backward numeric values", "code":"import sympy as sp; z1=sp.Rational(1,2)*1 + sp.Rational(-1,2)*2; h=sp.tanh(z1); z2=1*h; phat=1/(1+sp.exp(-z2)); d2=phat-1; gW2=d2*h; result = abs(float(z1)+0.5)<1e-9 and abs(float(h)+0.46211715)<1e-6 and abs(float(phat)-0.38648)<1e-4 and abs(float(gW2)-0.28352)<1e-4"},
  {"claim":"Q-learning single update yields 2.5 and converges to 5", "code":"alpha,gamma,r=0.5,0.9,5; Q=0; Q=Q+alpha*(r+gamma*0-Q); conv=r+gamma*0; result = abs(Q-2.5)<1e-12 and abs(conv-5)<1e-12"},
  {"claim":"Sigmoid derivative identity used in Q2a", "code":"import sympy as sp; z=sp.symbols('z'); s=1/(1+sp.exp(-z)); result = sp.simplify(sp.diff(s,z) - s*(1-s))==0"}
]