5.6.19Machine Learning (Aerospace Applications)

Application to GNC — learned guidance laws

1,768 words8 min readdifficulty · medium

What exactly is being learned?


Recipe 1 — Imitation Learning (Behavioral Cloning)

WHAT: treat guidance as plain supervised regression. Generate many optimal trajectories offline with a trusted optimizer; each timestep gives a (si,ai)(s_i, a_i^\star) pair. Fit a net to reproduce aa^\star.

WHY it works: the optimizer already knows the right answer; we only need a fast approximator of the map sas\mapsto a^\star. We are compressing a lookup-into-solver into weights.

HOW — derive the loss from first principles. We want πθ(s)a(s)\pi_\theta(s)\approx a^\star(s). "Approximate" means minimize expected squared error over the state distribution ρ\rho we'll actually see:

J(θ)=Esρ[πθ(s)a(s)2].J(\theta)=\mathbb E_{s\sim\rho}\big[\,\lVert \pi_\theta(s)-a^\star(s)\rVert^2\,\big].

Why squared error? Under a Gaussian noise model a=πθ(s)+ε, εN(0,σ2I)a^\star = \pi_\theta(s)+\varepsilon,\ \varepsilon\sim\mathcal N(0,\sigma^2 I), maximizing the log-likelihood of the data gives exactly 12σ2aiπθ(si)2+const-\tfrac1{2\sigma^2}\sum\lVert a_i^\star-\pi_\theta(s_i)\rVert^2 + \text{const}. Dropping constants, MLE is least squares. With NN samples the empirical loss is

J^(θ)=1Ni=1Nπθ(si)ai2.\hat J(\theta)=\frac1N\sum_{i=1}^N \lVert \pi_\theta(s_i)-a_i^\star\rVert^2 .

Gradient step: θθηθJ^\theta \leftarrow \theta - \eta\,\nabla_\theta \hat J.


Recipe 2 — Reinforcement Learning

WHAT: define a reward r(s,a)r(s,a) (e.g. -miss-distance, -fuel), and learn πθ\pi_\theta that maximizes expected discounted return

G=Eπθ ⁣[t=0Tγtr(st,at)],0<γ1.G=\mathbb E_{\pi_\theta}\!\Big[\sum_{t=0}^{T}\gamma^t r(s_t,a_t)\Big],\qquad 0<\gamma\le1.

WHY: no expert optimizer required — useful when the optimal law is unknown or the dynamics are messy/uncertain.

HOW — the policy gradient, derived. We want θJ\nabla_\theta J where J=Eτpθ[R(τ)]J=\mathbb E_{\tau\sim p_\theta}[R(\tau)], τ\tau a trajectory, RR its return.

θJ=θ ⁣pθ(τ)R(τ)dτ=R(τ)θpθ(τ)dτ.\nabla_\theta J=\nabla_\theta\!\int p_\theta(\tau)R(\tau)\,d\tau=\int R(\tau)\,\nabla_\theta p_\theta(\tau)\,d\tau.

Use the log-derivative trick θpθ=pθθlogpθ\nabla_\theta p_\theta = p_\theta\,\nabla_\theta\log p_\theta:

θJ=pθ(τ)R(τ)θlogpθ(τ)dτ=Eτ[R(τ)θlogpθ(τ)].\nabla_\theta J=\int p_\theta(\tau)R(\tau)\nabla_\theta\log p_\theta(\tau)\,d\tau=\mathbb E_\tau\big[R(\tau)\,\nabla_\theta\log p_\theta(\tau)\big].

Since logpθ(τ)=logp(s0)+t[logP(st+1st,at)+logπθ(atst)]\log p_\theta(\tau)=\log p(s_0)+\sum_t[\log P(s_{t+1}|s_t,a_t)+\log\pi_\theta(a_t|s_t)], only the policy term depends on θ\theta (dynamics don't!), so

  θJ=E[tθlogπθ(atst)  R(τ)]  \boxed{\;\nabla_\theta J=\mathbb E\Big[\sum_t \nabla_\theta\log\pi_\theta(a_t|s_t)\;R(\tau)\Big]\;}

This is REINFORCE. The dynamics dropping out is why RL works even when the plant model is unknown.

Figure — Application to GNC — learned guidance laws

Sanity check against a classical law

Proportional Navigation commands acceleration ac=NVcλ˙a_c=N V_c \dot\lambda (navigation gain NN, closing speed VcV_c, LOS rate λ˙\dot\lambda). A well-trained net should recover PN-like behavior on nominal engagements — a great Forecast-then-Verify test: predict "the net's command scales linearly with λ˙\dot\lambda," then plot net output vs λ˙\dot\lambda and check the slope NVc\approx N V_c.


Worked examples


Recall Feynman: explain to a 12-year-old

Imagine steering a rocket toward a target is like catching a ball. A pro (the optimizer) knows exactly how to move, but he thinks slowly. You watch him play thousands of games and copy his moves until you can react instantly without thinking — that's imitation learning. Or, nobody teaches you, but every time you catch the ball you get a candy and when you miss you get nothing; over many tries your brain learns which moves earn candy — that's reinforcement learning. Either way, the rocket ends up with fast "instincts" (the neural net) baked in before flight.


Active-recall flashcards

What is a learned guidance law?
A policy πθ:sa\pi_\theta:s\mapsto a (usually a neural net) mapping vehicle state to a command, with θ\theta trained offline instead of the law being derived analytically.
Why prefer a learned law onboard over solving the optimization in flight?
Inference is one cheap forward pass (µs) vs. seconds for an optimal solver; it amortizes expensive optimization into weights for slow, power-limited flight computers.
Behavioral Cloning loss and why squared error?
J^=1Nπθ(si)ai2\hat J=\frac1N\sum\lVert\pi_\theta(s_i)-a_i^\star\rVert^2; squared error = MLE under Gaussian action noise.
What failure mode does naive Behavioral Cloning suffer?
Distribution/covariate shift — the policy visits states the expert never showed, errors compound. Fixed by DAgger.
What does DAgger do?
Runs the current policy, queries the expert on the newly visited states, adds those pairs, retrains — aligning training data with policy-induced state distribution.
State the REINFORCE policy gradient.
θJ=E[tθlogπθ(atst)R(τ)]\nabla_\theta J=\mathbb E[\sum_t \nabla_\theta\log\pi_\theta(a_t|s_t)\,R(\tau)].
Why do the environment dynamics drop out of the policy gradient?
In logpθ(τ)\log p_\theta(\tau) the transition terms logP(st+1st,at)\log P(s_{t+1}|s_t,a_t) don't depend on θ\theta, so their gradient is zero — RL needs no plant model.
Purpose of a baseline in policy gradient?
Reduces variance without introducing bias since E[logπθb]=0\mathbb E[\nabla\log\pi_\theta\cdot b]=0.
Proportional Navigation command formula?
ac=NVcλ˙a_c=N V_c\dot\lambda (nav gain NN, closing speed VcV_c, LOS rate λ˙\dot\lambda).
Two useful engineered state features for guidance nets?
Time-to-go tgo=R/Vct_{go}=R/V_c and LOS rate λ˙=(y˙xx˙y)/(x2+y2)\dot\lambda=(\dot y x-\dot x y)/(x^2+y^2).

Connections

Concept Map

slow costly online

motivates

maps state to command

trained

enables

recipe 1

recipe 2

needs

gives pairs

fit via

derived from

fails on

Classical GNC solver

Onboard compute limits

Learned guidance law pi_theta

Policy s to a

Offline training of theta

Cheap online forward pass

Imitation Learning / BC

Reinforcement Learning

Optimal solver expert data

State-action pairs

Squared error loss J

Gaussian MLE assumption

Distribution shift off training states

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, GNC ka matlab hai Guidance, Navigation aur Control — yaani rocket ya missile ko decide karna padta hai ki "kis direction mein, kitna zor lagाun" har second. Classical tareeka yeh hai ki har instant pe ek optimization solve karo ya proportional navigation jaisa hand-derived formula lagao. Problem: flight computer slow hota hai, radiation-hardened, power limited. Optimal solver seconds le sakta hai — flight mein itna time nahi hai.

Isliye learned guidance law ka idea aata hai: ek neural network πθ\pi_\theta ko pehle se, ground pe, train kar lo — state (position, velocity, time-to-go, LOS rate) daalo, command bahar aaye. Flight mein bas ek forward pass, microseconds mein kaam khatam. Do main tarike: Behavioral Cloning (BC) — ek expert optimizer ke jawab copy karo, simple supervised regression, loss squared error; aur Reinforcement Learning (RL) — reward do (kam miss-distance, kam fuel) aur net khud try-and-learn kare, expert ki zaroorat nahi.

Ek bada trap yaad rakhna: seedha BC copy karne se distribution shift hota hai — net apni hi galtiyon se aise states mein pahunch jaata hai jo expert ne kabhi dikhaye hi nahi, aur error compound hota jaata hai. Iska ilaaj hai DAgger: apni policy chalao, jo naye states aaye unpe expert se poocho, dataset mein daalo, phir se train karo. RL mein sabse important insight yeh hai ki policy gradient θJ=E[logπθ(atst)R]\nabla_\theta J=\mathbb E[\sum \nabla\log\pi_\theta(a_t|s_t)R] mein dynamics cancel ho jaati hain — isliye plant model na pata ho tab bhi RL kaam karta hai.

Verify karne ka mazedaar tareeka (Forecast-then-Verify): predict karo ki trained net ka command LOS rate ke saath linearly badhega slope NVc\approx NV_c ke saath, phir plot karke check karo — agar match hua to net ne PN-jaisa behavior seekh liya, bas actuator limits ke saath. Yahi 80/20 hai: features tgot_{go} aur λ˙\dot\lambda hi zyaadatar signal carry karte hain.

Test yourself — Machine Learning (Aerospace Applications)

Connections