Every filter so far knew which measurement came from which target. A real sensor sends an unlabelled cloud with false alarms in it. In this toy, with 10 false alarms a frame, hard nearest neighbour loses a track in 16 of 100 runs; soft JPDA loses 3.
Pick a method and watch two targets cross through clutter. Raise the clutter and replay. Then we build each method piece by piece: the gate, nearest neighbour, the optimal assignment, PDA, JPDA and MHT.
You need the Kalman filter from Lesson 5, in particular the innovation and its covariance S. We build the rest from zero.
Lesson 12 of 22 in Sensor Fusion: Classical to Modern. Before: Covariance Intersection. Next: IMU and Inertial Navigation.
Toy simulation, illustrative: a 60 m by 40 m field, 60 frames, sensor noise 1 m, a 20% chance to miss each target each frame. The 100-run counts come from this same simulation with seeds 1 to 100.
Chapter 0
See why a tracker must pair measurements with targets before it can fuse anything
A radar watches five aircraft. Each sweep it returns a list of blips with no names on them. Some blips are aircraft. Some are rain or birds. One aircraft gave no blip at all this sweep.
The Kalman filter in Lesson 5 took one measurement z and fused it. It never asked which target z came from. Data association is the step that answers that question: it pairs each measurement with a track, or calls it clutter. It runs before every update.
Two tracks predict where their targets will be. The ellipse around each is its gate. Guess the owner of each dot, then press Show the truth.
Illustrative toy: the sensor detects each target with probability 0.9, and 4 to 8 false alarms fall at random.
Three problems arrive together.
| Problem | What happens | What it costs |
|---|---|---|
| Clutter | A false alarm is a detection with no target behind it. | It can pull a track off course or start a phantom track. |
| Missed detection | The probability of detection PD is below 1, so a target can go silent for a frame. | The track must coast on its prediction and not die. |
| Ambiguity | Two targets come close, so one dot fits both gates. | A wrong pick swaps the two tracks for good. |
The cost of a wrong pairing is high. The filter trusts the pairing completely. It pulls the estimate toward the wrong point, so the next gate is in the wrong place, so the next pick is likely wrong too.
Chapter 1
Measure a miss in standard deviations, and reject a measurement before any pairing starts
A car drives along a lane. Its track is sure of the car's sideways position and unsure how far it went forward. The track's doubt is an ellipse: long along the road, thin across it. A detection 3 m ahead is normal. A detection 3 m to the side is not.
Lesson 5 gave the tools. The track predicts where its measurement should land: the predicted measurement ẑ ("z-hat"). The real measurement z misses it by the innovation ν ("nu"), with ν = z − ẑ. The innovation covariance S says how big a miss to expect in each direction.
d squared equals nu-transpose, times S-inverse, times nu.
Subtract the prediction z-hat from the measurement z to get nu. When S is diagonal, square each part of nu and divide it by the variance S gives that direction. Add the parts. That sum is d squared.
With made-up numbers: z-hat = (10, 5) m and S = diag(4, 1) m². The spread is 2 m in x and 1 m in y. For z1 = (13, 5), nu = (3, 0) and d² = 9/4 + 0 = 2.25. For z2 = (10, 7.5), nu = (0, 2.5) and d² = 0 + 6.25/1 = 6.25. z1 is farther in metres but nearer in standard deviations.
If the measurement truly came from this track, d² follows a known curve. It is the chi-square distribution, with one degree of freedom per number in the measurement. So we can choose the share of true measurements to keep, the gate probability PG, and read the threshold off a table.
d squared is less than gamma.
Look up gamma for your measurement's dimension and the share P-G of true measurements you want to keep. Keep a measurement as a candidate only if its d squared is below gamma.
A 2-D position with P-G = 0.95 gives gamma = 5.99. z1 at d² = 2.25 is inside. z2 at d² = 6.25 is outside. A circle gate would keep z2 (2.5 m) before z1 (3 m).
| Measurement numbers | γ at PG = 0.95 | γ at 0.99 | γ at 0.999 |
|---|---|---|---|
| 1 (range only) | 3.84 | 6.63 | 10.83 |
| 2 (x, y) | 5.99 | 9.21 | 13.82 |
| 3 (x, y, z) | 7.81 | 11.34 | 16.27 |
The teal ellipse is the gate. Warm dots are inside; grey rings are outside. Drag the large dot, stretch S and change PG.
Exact arithmetic for z-hat = (10, 5) m, variance 1 m² in y. The grid lines are 1 m apart.
The gate fails in two ways. Too tight: a target turns, its measurement lands outside, and the track dies (measure how often a true measurement has d² just above γ). Too loose: clutter enters every gate and the pairing work grows. Chapter 9 shows how to tune it.
Chapter 2
Give each track its closest candidate, and watch the order of the tracks change the answer
The gate leaves each track a short list of candidates. Now each track needs one measurement. The simplest rule is nearest neighbour (NN): give each track the candidate with the smallest d².
Two tracks cannot share one measurement, because one blip has one source. So greedy NN walks the tracks in some order. Each track takes its nearest free candidate and removes it from the pool.
Here is the trap, on a line, with a spread of 1 m for both tracks, so d² is the distance squared. Track A predicts 0 m and track B predicts 2 m. Two measurements arrive: z1 at 1.1 m and z2 at −1.5 m. The 1-D gate at PG = 0.99 is γ = 6.63.
| Order | A takes | B takes | Result |
|---|---|---|---|
| A first | z1, d² = 1.21 | z2 has d² = 12.25, outside the gate: nothing | B coasts; z2 looks like a new target |
| B first | z2, d² = 2.25 | z1, d² = 0.81 | total 3.06, both tracks updated |
Track A is teal, track B purple; each bar is a gate. Drag z1 and z2 along the line, then switch the order.
Illustrative toy: spread 1 m for both tracks, so d² is the distance squared; gate 6.63.
Track A grabbed z1 because it was A's nearest. But B needed z1 more: z1 was B's only candidate. Greedy NN is order-dependent and local: each track ignores the others.
The failure compounds. A wrong pick feeds the wrong point into the Kalman update, so the next gate centres in the wrong place. Symptom: a track jumps onto a clutter dot near another track and stays there. Measure it by counting tracks that end far from any target. Fix: decide all tracks at once (Chapter 3) or stop making hard picks (Chapter 4).
Chapter 3
Fill a cost matrix, then pick the one-to-one pairing with the smallest total
Greedy NN decided track by track. Global nearest neighbour (GNN) decides all tracks together. It writes every track-measurement cost into a table and picks the pairing with the smallest sum. This is the assignment problem.
What should one cell cost? We want the most likely pairing. Call the cost of giving measurement j to track i Cij. A good cost is the negative log of the Gaussian likelihood, because adding logs is the same as multiplying probabilities.
C-i-j equals one half d-i-j squared, plus one half the log of the determinant of two pi S-i.
Halve the distance d-i-j squared. Add half the log of the size of track i's gate. A wide gate can swallow a big miss cheaply, so the second term charges it for being wide.
The Chapter 1 track has S = diag(4, 1), so |2πS| = (2π)² × 4 = 157.9 and half its log is 2.53. For z1, d² = 2.25, so C = 1.125 + 2.53 = 3.66. A track with S = diag(1, 1) and the same d² pays 1.125 + 1.84 = 2.96.
Now choose one measurement per track, never the same one twice. Call that choice the assignment a, so a(i) is the measurement it gives track i.
J of a equals the sum over i of C-i, a-of-i.
Pick one cell in each row, each in a different column. Add the picked cells to get J. Try every legal pick and keep the one with the smallest J.
Take the "greedy trap" matrix below. Smallest cell first gives A→z1 (1), C→z3 (3), B→z2 (7): J = 11. The pairing A→z2 (2), B→z1 (2), C→z3 (3) gives J = 7.
Rows are tracks, columns are measurements. The dashed yellow cells are the greedy pick (smallest cell first); the green cells are the best total. Click a cell to raise its cost.
The best total comes from checking all 6 pairings, which is what the Hungarian algorithm returns. Every cost is a made-up d² value.
Trying every pairing grows as n!: 6 for 3 tracks, 3.6 million for 10. The Hungarian algorithm (Kuhn and Munkres) finds the same best pairing in about n³ steps. In Python it is scipy.optimize.linear_sum_assignment.
Real frames are not square. Add one dummy column per track with the cost of a miss, and one dummy row per measurement with the cost of clutter. A track that lands in its dummy column coasts. A measurement in a dummy row may start a new track. A pair outside the gate gets a huge cost.
Chapter 4
Give every candidate a probability, keep one for "none of them", and update with the blend
A track has two dots in its gate, and either could be the target. NN and GNN must throw one away. Probabilistic data association (PDA), from Bar-Shalom and Tse (1975), keeps both and weights each by how likely it is to be the target.
For each candidate i, PDA needs its likelihood Li: the Gaussian density at its innovation, exp(−di²/2) divided by √|2πS|. It also needs the clutter density λ ("lambda"), the false alarms per square metre per frame.
beta-i equals P-D times L-i, over: lambda times one minus P-D P-G, plus P-D times the sum over j of L-j.
Score each candidate: P-D times its likelihood L-i. Score the clutter story: lambda times the chance that the target gave nothing in the gate. Divide candidate i's score by the sum of all the scores.
With made-up numbers: d² = 1 and 4, and √|2πS| = 10, so L1 = 0.0607 and L2 = 0.0135. With P-D = 0.9, P-G = 0.99 and lambda = 0.02, the clutter score is 0.02 × 0.109 = 0.00218. The candidate scores are 0.0546 and 0.0122. All three sum to 0.0689. beta-1 = 0.0546/0.0689 = 0.792 and beta-2 = 0.177.
The clutter story gets its own weight, β0 ("beta-zero"): the chance that none of the candidates is the target.
beta-zero equals lambda times one minus P-D P-G, over the same sum as before.
Divide the clutter story's score by the total. Far candidates or dense clutter make beta-zero grow.
Same numbers: beta-zero = 0.00218/0.0689 = 0.032. Check: 0.792 + 0.177 + 0.032 = 1, after rounding. Move both candidates to d² = 8 and beta-zero rises to 0.40.
Call the innovation of candidate i νi. PDA blends them into one combined innovation ν̄ ("nu-bar").
nu-bar equals the sum over i of beta-i times nu-i.
Multiply each innovation nu-i by its beta-i and add. Beta-zero multiplies nothing, so a large beta-zero shrinks the step and the track coasts.
Say S is round with a spread of 1.26 m each way, which makes √|2πS| = 10. Then nu1 = (1.26, 0) m and nu2 = (0, 2.52) m. nu-bar = 0.792 × (1.26, 0) + 0.177 × (0, 2.52) = (1.00, 0.45) m.
Drag z1 and z2 inside the teal gate. The bars show beta-1, beta-2 and beta-zero; the pink arrow is nu-bar. Raise the clutter density.
Exact PDA weights with PD = 0.9, PG = 0.99 and the round S above; positions are illustrative.
PDA also widens the track's covariance by the spread of the candidates, so an ambiguous frame leaves the track less sure. Its failure: it sees one track alone, so two close tracks can both weight one dot heavily and drift together.
Chapter 5
Score whole joint stories for all tracks, so two tracks cannot both claim one dot
Two tracks close in on each other. A dot z1 sits between them, inside both gates. Single-track PDA lets track A weight z1 heavily and lets track B weight it heavily too. Both tracks move toward z1 and can merge into one. This is track coalescence.
Joint PDA (JPDA), from Fortmann, Bar-Shalom and Scheffe (1983), reasons about all close tracks together. It lists every joint event: a complete hand-out of the measurements that obeys two rules.
Score each pairing by how much better the target explains it than clutter: PD L / λ. Score each track left empty 1 − PDPG. An event's probability P(E) is the product of its scores, divided by the total over all legal events.
beta-t-j equals the sum, over every joint event E that gives measurement j to track t, of P of E.
List every legal way to hand out the dots. Score each one. To get beta-t-j, add the scores of the events where track t owns dot j, and divide by the total of all scores.
With made-up scores: A→z1 is 4, A→z2 is 2, B→z1 is 8, an empty track is 0.109. The total over the five events below is 17.54. beta for A→z1 = 0.436/17.54 = 0.025. Single-track PDA gave A→z1 4/(0.109 + 4 + 2) = 0.65.
| Event | A gets | B gets | Score |
|---|---|---|---|
| E1 | z1 | nothing | 4 × 0.109 = 0.436 |
| E2 | z2 | z1 | 2 × 8 = 16 |
| E3 | z2 | nothing | 2 × 0.109 = 0.218 |
| E4 | nothing | z1 | 0.109 × 8 = 0.872 |
| E5 | nothing | nothing | 0.109 × 0.109 = 0.012 |
"A gets z1 and B gets z1" is missing: it breaks rule 1. That missing row is the whole fix. Because B explains z1 much better, A moves its weight to z2.
Track A is teal, track B purple. Drag the contested dot z1 between them and switch between PDA and JPDA. Arrow thickness is the weight.
Illustrative toy on a line: spread 1 m, PD = 0.9, PG = 0.99, λ = 0.05 per metre.
The cost is the event count. It grows faster than exponentially with the tracks and dots in one cluster. Real JPDA only reasons jointly over tracks whose gates overlap, and approximates large clusters.
Chapter 6
Keep competing stories in a tree, let later frames vote, and prune the tree to fit the budget
A dot appears between a track and empty space. It could extend the track or start a new target. Two frames later the answer is often obvious. Every method so far must decide now.
Multiple hypothesis tracking (MHT), from Reid (1979), does not. A hypothesis is one full story of who made which dot, over all frames so far. At each ambiguous frame, every hypothesis splits into its options. Each branch carries a score built from the same likelihoods and clutter scores as JPDA.
Each ambiguous frame doubles the leaves. The teal path is the true story. Add frames, then lower K, the number of hypotheses kept.
Illustrative scores: each frame the true branch is more likely on average, but not every frame.
Unpruned, the tree doubles with each ambiguous frame: 210 = 1,024 leaves after 10 frames. MHT works only because of pruning.
| Rule | What it does |
|---|---|
| K best | Keep the K highest-scoring hypotheses each frame. |
| Ratio | Delete a hypothesis far less likely than the best one. |
| N-scan | Commit to the best story for frames older than N. N = 1 is close to a per-frame method. |
| Merge | Join hypotheses whose recent pairings are the same. |
Prune too hard and the true story dies early. Symptom: a track swap that a later frame should have fixed. Measure it by checking how often pruning cuts the true hypothesis in replayed data. Fix: raise K or N until the swaps stop or the time budget runs out.
Reid's original form lists global hypotheses. Most modern trackers use track-oriented MHT: they keep a tree per track and rebuild the best global story each frame with an assignment solve.
Chapter 7
Run nearest neighbour, global NN and JPDA on the same scene, then on 100 scenes
Two targets fly right while their paths cross in the middle of the field. Each frame the sensor reports each target with probability PD, plus random false alarms. Two Kalman tracks follow them with a constant-velocity model, a 99% gate and the method you choose.
A track fails in one of two ways. It is lost if it ends more than 4 m from its target. The pair has swapped if the two tracks end on each other's targets.
Choose a method, set the clutter and the miss rate, and press Run. The lower plot is each track's error in metres.
Toy simulation, illustrative; the same engine as the hero.
One run can be lucky. Run 100 scenes with the same settings and count failures.
Each bar counts failed runs out of 100 at the clutter and miss rate set above. Press Run 100 scenes after you change them.
Seeds 1 to 100, fixed, so the counts repeat.
| False alarms per frame (miss rate 0.2) | NN failed | GNN failed | JPDA failed |
|---|---|---|---|
| 6 | 5 | 3 | 0 |
| 10 | 16 | 12 | 3 |
| 14 | 21 | 21 | 6 |
With no clutter all three methods nearly tie. That is the trap: a clean test hides the failure. Hard methods fail when a false alarm lands in a gate while the true dot is missing; they must take it. JPDA gives that dot a small weight and keeps most of the weight on "none of them".
Chapter 8
Start a track on a hunch, confirm it on evidence, and delete it after silence
A dot pairs with no track. It may be a new target. It may be a false alarm. If every such dot starts a permanent track, the screen fills with phantoms. If none does, new targets are never tracked.
The standard answer is a small state machine with an M-of-N rule.
The boxes are a candidate's first 5 frames; filled means a dot paired. Choose the source, set M, and press New candidate. The bars give the exact chance of confirmation.
Illustrative rates: a real target pairs each frame with probability 0.9; a false alarm lands in the same gate again with probability 0.1. Frame 1 always counts as a hit.
Worked number for 3 of 5. Frame 1 is a hit, so the candidate needs 2 more hits in 4 frames. A real target with PD = 0.9 manages that 99.6% of the time. A clutter spot that recurs 10% of the time manages it 5.2% of the time. At 5 of 5, real targets also fail 34% of the time.
| Knob | Start at | If too small | If too large |
|---|---|---|---|
| Gate PG | 0.99 (γ = 9.21 in 2-D) | true dots fall outside; tracks break | clutter enters; more pairing work |
| Clutter λ | count false alarms per area over many frames | PDA trusts clutter | beta-zero wins; the track lags |
| Method | gated GNN | swaps and clutter capture | compute you do not need |
| M of N | 3 of 5 | phantom tracks | new targets confirm late or never |
| Coast limit | a few frames, longer for low PD | tracks die in short occlusions | dead targets linger |
Pick the method by the scene. Far-apart targets and sparse clutter: gated GNN. Gates that overlap often: JPDA. Dense targets, low PD and swaps you cannot afford: MHT. To save compute, group tracks whose gates overlap and run the expensive method only on those groups.
Chapter 9
Plot the d squared the gate already computes, and read the failure from its shape
Association bugs do not crash. The filter fuses the wrong dot, and the error shows up later in the estimate. The best detector costs nothing: the gate already computes d² for the dot each track used.
Logged over time, that number is the normalized innovation squared (NIS). For a healthy 2-D track it follows a chi-square curve with mean 2. About 1 frame in 100 lands above 9.21.
Pink dots are the NIS each frame. The dashed line is the mean of 2; the solid line is the gate at 9.21. Turn on a fault and compare.
Illustrative toy: a constant-velocity track, 2-D position measurements with 1 m noise, seed fixed.
| Failure | Symptom | How to measure it | Fix |
|---|---|---|---|
| Track swap | IDs right before a crossing, wrong after | count ID switches against ground truth | JPDA or MHT; add an appearance cost |
| Broken track | one target gets many short tracks | true dots with d² just above γ | raise PG; make sure S grows after a miss |
| Phantom track | more tracks than targets | confirmed tracks against true count | lower PG; raise λ; stricter M of N |
| Poisoned track | drifts off and stays off, with a small covariance | NIS high for many frames | soft association; check Q and R |
Broken and phantom tracks pull in opposite directions. Tighten the gate to kill phantoms and you start breaking real tracks. That is why PG is the first knob to tune, with the NIS plot open.
Chapter 10
Keep the ladder, the numbers, the checklist and the code in one place
Gate first, always. Then pick the rung of the ladder that matches the scene. The rungs run from hard and local to deferred.
| Method | Decision | Scope | Clutter | Cost | Best for |
|---|---|---|---|---|---|
| NN | hard | one track at a time | poor | tiny | sparse, far-apart targets |
| GNN | hard | all tracks, best per frame | gate only | about n³ | real-time multi-object tracking |
| PDA | soft (β) | one track | good (β0) | low | one target in clutter |
| JPDA | soft (β) | all close tracks | good | grows fast with cluster size | close targets plus clutter |
| MHT | deferred | a tree over frames | best | highest | dense targets, low PD, no swaps allowed |
| Term | Meaning | Number to remember |
|---|---|---|
| Innovation ν | z minus the predicted measurement | metres |
| Mahalanobis d² | νT S−1 ν, the miss in standard deviations, squared | (3, 0) with S = diag(4, 1) gives 2.25 |
| Gate γ | keep a dot if d² < γ | 2-D: 5.99 (95%), 9.21 (99%) |
| Cost Cij | ½ d² + ½ ln|2πS| | greedy trap: 11 against 7 |
| βi, β0 | chance dot i is the target; chance none is | 0.792, 0.177, 0.032 |
| Joint event | a legal hand-out of dots to tracks | A→z1 falls from 0.65 to 0.025 |
| M of N | confirm after M hits in N frames | 3 of 5: 99.6% targets, 5.2% clutter |
| NIS | d² of the dot used, over time | mean = measurement dimension |
pythonimport numpy as np from scipy.optimize import linear_sum_assignment def gnn_assign(tracks, meas, gamma=9.21, big=1e6): # tracks: list of (z_hat, S); meas: list of z. Returns (track, meas) pairs. C = np.full((len(tracks), len(meas)), big) # default: outside the gate for i, (z_hat, S) in enumerate(tracks): Si = np.linalg.inv(S) for j, z in enumerate(meas): nu = z - z_hat d2 = nu @ Si @ nu # Mahalanobis distance squared if d2 < gamma: C[i, j] = 0.5 * d2 + 0.5 * np.log(np.linalg.det(2 * np.pi * S)) rows, cols = linear_sum_assignment(C) # Hungarian: smallest total return [(r, c) for r, c in zip(rows, cols) if C[r, c] < big] def pda_betas(d2, S, P_D=0.9, P_G=0.99, lam=0.02): L = np.exp(-0.5 * d2) / np.sqrt(np.linalg.det(2 * np.pi * S)) # likelihoods clutter = lam * (1 - P_D * P_G) # the "none of them" score denom = clutter + P_D * L.sum() return clutter / denom, P_D * L / denom # beta0, beta_i: they sum to 1 # nu_bar = sum_i beta[i] * nu[i]; x = x_pred + K @ nu_bar; then widen P by the spread
| Domain | Tracked | Usual method |
|---|---|---|
| Air-traffic and defence radar | aircraft, contacts | JPDA, MHT |
| Self-driving perception | cars, people, cyclists | gated GNN with motion, box overlap and appearance costs |
| Video multi-object tracking | people, players | SORT and DeepSORT: Kalman plus the Hungarian algorithm |
| Microscopy | cells, particles | gated assignment; branching for cell division |
SORT (Bewley and others, 2016) is this lesson's GNN: a Kalman filter per track, a cost from box overlap, and the Hungarian algorithm each frame. DeepSORT adds a learned appearance distance and a Mahalanobis gate, so a track can find its target again after an occlusion.
Now press Present or Teach and rebuild the ladder from memory. Start with the gate and end with the tree. Then go back to the hero and say why nearest neighbour lost its track.
Lesson 12 of 22 in Sensor Fusion: Classical to Modern on Engineermaxxing. The methods follow Bar-Shalom and Fortmann (1988) and the original papers above. Every toy number on this page carries the word illustrative.