The problem in brief
A hiker is lost in a simulated mountain range. Before his radio died he sent only two numbers: his altitude (from an altimeter) and the compass bearing of the path he was on. You must choose, for each such reading, the point where a rescue helicopter lands. You get 1334 simulated training scenarios with the true position in metres plus the two readings, and 1335 test readings without positions. Your program prints one landing point per test reading (on Kattis the predictions are simply printed by the submitted program).
How you are scored
For one reading, the error is the area of the circle the team must search, with radius the distance between landing point and hiker:
averaged over the test readings. With and ,
The baseline is exactly what you get by always landing at the average training position: . The target, , means cutting the mean squared distance by 41 %. The test positions are private, so we evaluate by 5-fold cross-validation on the training set (repeated with two random splits).
The metric is a mean squared distance. That fact decides the whole approach: for squared error, the best single answer given the evidence is the conditional mean , not the most likely point.
First look at the data
Plot the training positions and the structure jumps out.

- The hiker is always on a trail. Positions are not spread over the map but lie on a few long curves. Neighbouring training points are typically 70 m apart.
- Elevation varies smoothly along a trail: two neighbouring points differ by 2 m (median).
- The compass gives the direction of the trail, up to a U-turn. Fitting a local line through each point's neighbours, the compass reading agrees with the trail's bearing modulo 180 degrees (median gap 12 degrees). Modulo 360 it does not: half of the neighbouring pairs point in opposite directions, because the hiker may walk either way. So the right feature for an angle is , not itself and not even .
- A reading is ambiguous: an altitude of 143 m and a bearing of 34 degrees occur at several places on the network (right panel).
A first baseline
Landing at the mean position scores 0.7 (by construction). A k-nearest-neighbours regressor on the features , which looks for training readings similar to the test reading and averages their positions, already does much better: 74.7 with . A random forest on the same features gives the same 74.7. Note how bad small is (49.7 with ): averaging few neighbours throws away the hedging that squared error rewards.
The key idea
Think like a Bayesian. The unknown is the position on the trail network; the evidence is the reading . Bayes' rule gives
where is the elevation and the trail bearing at , with Gaussian altimeter noise and an axial von Mises compass noise (the factor 2 makes and equivalent). The training points are samples of the prior , so the posterior mean is a weighted average of trail points:
This is kernel (Nadaraya-Watson) regression, but derived from a model of the measurement noise, which tells us which kernel to use. Why is the weighted mean optimal? For any landing point ,
which is smallest at . In the figure, the posterior has several clusters and the best landing point sits between them, possibly off any trail. Landing on the single most plausible spot would be a gamble that the squared metric punishes hard when it fails.
One more improvement comes from the trail structure: 1334 points leave gaps along the trails, and their compass readings are noisy. We densify the network: each point is joined to its 3 nearest neighbours closer than 800 m, the segment is sampled every 25 m with linearly interpolated elevation, and each sample receives the segment's bearing, which is less noisy than a single compass reading. The posterior is then computed on these dense samples.
The full solution
- Read
train.csv; convert directions to radians. - Densify the trails (about 25 m spacing) as described above.
- For each test reading, compute the log-weights of all trail samples, subtract the maximum (numerical stability) and exponentiate:
logw = -(e - ed[None])**2 / (2 * S_ELEV**2) + KAPPA * (np.cos(2 * (th - ad[None])) - 1)
w = np.exp(logw - logw.max(1, keepdims=True))
pred = (w @ Pd) / w.sum(1, keepdims=True) # posterior mean position
- Choose and by cross-validation; the grid m, gives a flat optimum around m, (for the doubled angle has a spread of about rad, so about 15 degrees on the bearing itself, consistent with the 12-degree median gap measured above). The densification itself is retrained inside each fold, so the validation points never help build the trails they are scored on.
- Print
x yfor each test row.
Results
5-fold cross-validation on the training set (the official test positions are private):
| approach | mean error | score |
|---|---|---|
| land at the mean training position (baseline) | 0.7 | |
| kNN on , | 49.7 | |
| kNN, | 74.7 | |
| random forest, same features | 74.7 | |
| Bayesian kernel weights on training points (, ) | 75.5 | |
| same on the densified trail network (final) | 78.6 (79.5 and 77.7 on two splits) |
We reach about 79 % of the way from the baseline to the reference solution. The remaining gap is mostly irreducible ambiguity: a reading often matches several distant stretches of trail, and no landing point can be close to all of them. Differences of one or two points between methods are within the noise of a 1334-point cross-validation (a few large errors dominate a squared metric).
What to remember
- Plot the targets on a map before modelling. Seeing that every position lies on a trail turns a blind regression into a structured inference problem.
- Under squared error, predict the conditional mean. When the posterior is multimodal, the optimal answer lies between the modes, not on the most likely one.
- Kernel regression is Bayes in disguise: the kernel is the likelihood of the measurement noise, and the training points are samples of the prior.
- Encode angles by what they mean. A direction that is ambiguous up to a U-turn lives on a circle of period 180 degrees: use , .
- Exploit known structure to create data: interpolating along the trails gives a denser, cleaner prior than the raw samples.