Machine Learning (Aerospace Applications)
Chapter: 5.6 Machine Learning for Aerospace Level: 3 — Production (from-scratch derivations, code-from-memory, explain-out-loud) Time limit: 45 minutes Total marks: 60
Instructions: Show every derivation step. Where code is requested, write it from memory (NumPy-style pseudocode acceptable if syntactically consistent). Use / for math.
Question 1 — Linear Regression from Scratch (10 marks)
(a) Starting from the mean-squared-error cost derive the normal equation by setting . Show the gradient explicitly. (4)
(b) Add L2 (ridge) regularization and derive the modified closed-form solution. State one numerical benefit of the regularizer. (3)
(c) Write the batch gradient-descent update rule for the unregularized cost and give the vectorized gradient expression. (3)
Question 2 — Logistic Regression & Cross-Entropy (10 marks)
(a) Define the sigmoid and prove that . (3)
(b) For a single training example with label , prediction , write the binary cross-entropy loss . Derive and show it simplifies to . (5)
(c) Explain in one sentence why cross-entropy is preferred over MSE for logistic regression training. (2)
Question 3 — Backpropagation by Hand (12 marks)
Consider a 2-layer network: input (scalar), hidden unit , output , loss .
(a) Do the forward pass symbolically. (2)
(b) Using the chain rule, derive , , and . Recall . (6)
(c) Numerically evaluate all three gradients for . Show intermediate values. (4)
Question 4 — Optimizers from Memory (10 marks)
(a) Write the update equations for SGD with momentum (velocity form) and explain the role of the momentum coefficient . (3)
(b) Write the full Adam update equations including bias correction. Define every symbol. (5)
(c) In one sentence each, contrast batch, mini-batch, and stochastic gradient descent by variance and compute cost. (2)
Question 5 — Attention / Self-Attention (8 marks)
(a) Write the scaled dot-product attention formula and explain the purpose of the scaling factor. (3)
(b) Given query/key/value matrices , explain out loud (in words) the shape flow and what each matrix multiplication computes in self-attention. (3)
(c) State why self-attention is more parallelizable than an RNN for sequence modeling. (2)
Question 6 — Reinforcement Learning for GNC (10 marks)
(a) Write the Bellman optimality equation for the action-value function . (3)
(b) Write the tabular Q-learning update rule and identify the learning rate and discount factor. (3)
(c) A guidance agent in state takes action , receives reward , lands in where . With current , learning rate , discount , compute the updated . (4)
Answer keyMark scheme & solutions
Question 1 (10)
(a) Expand . Gradient: (2) — from matrix calculus . Set to zero: → (2).
(b) Cost gradient → (2). Benefit: is always invertible / better conditioned (reduces variance) (1).
(c) Update: (3) ( = learning rate).
Question 2 (10)
(a) (1). (2).
(b) (1). (2). With , , . Chain: (2).
(c) MSE with sigmoid is non-convex and its gradient vanishes when saturated; cross-entropy gives convex loss and non-vanishing gradient (2).
Question 3 (12)
(a) , , (2).
(b) Let . (2). (2). (2).
(c) , , , . .
- (1.5)
- (1.5)
- (same, ) (1)
Question 4 (10)
(a) (or ); (2). accumulates an exponentially-weighted average of past gradients, damping oscillations and accelerating along consistent directions (1).
(b) (5) (1st moment) (2nd moment) , (bias correction) . Symbols: gradient, step size, decay rates, numerical stabilizer.
(c) Batch: uses all data → lowest gradient variance, highest per-step cost. Mini-batch: subset → moderate variance and cost (standard). Stochastic: one sample → highest variance, cheapest per step (2).
Question 5 (8)
(a) (2). Scaling by keeps dot-product magnitudes bounded so softmax gradients don't vanish (avoids saturation) (1).
(b) → score matrix comparing each query to each key; softmax normalizes rows into attention weights; multiply by () to get weighted sums → output (3).
(c) All positions attend simultaneously via matrix multiply (no sequential recurrence), so computation parallelizes across the sequence (2).
Question 6 (10)
(a) (3).
(b) (2); = learning rate, = discount (1).
(c) TD target . TD error . Update (4).
[
{"claim":"Q3 gradient dL/dw2 = 0.21356 for given inputs","code":"import math; h=math.tanh(0.5); yhat=1*h; delta=yhat-0; dw2=delta*h; result = abs(dw2-0.21356)<1e-4"},
{"claim":"Q3 dL/dw1 = 0.36343","code":"import math; h=math.tanh(0.5); yhat=h; delta=yhat; dw1=delta*1*(1-h**2)*1; result = abs(dw1-0.36343)<1e-4"},
{"claim":"Q6 Q-learning update yields 5.6","code":"Q=5; r=2; g=0.9; a=0.1; maxQ=10; newQ=Q+a*(r+g*maxQ-Q); result = abs(newQ-5.6)<1e-9"},
{"claim":"sigmoid derivative identity at z=0 equals 0.25","code":"import math; s=1/(1+math.exp(0)); dsig=s*(1-s); result = abs(dsig-0.25)<1e-9"}
]