Skip to main content

The Search in One Dimension

The setup

Three clocks sit on a line; somewhere on a parallel track hides a single mass. Two unknowns — position \(x\) and mass \(M\) — and a stream of noisy tick rates. Here is the full search, animated:

The 1D search, one simulated run. Clockwise from top left: the physical setup; the particle cloud in (x, M) space; the convergence of both estimates with uncertainty bands; the observed tick rates being fed to the filter.

Meet the detective

The inference engine is a particle filter: a cloud of hypotheses — one thousand of them in the animation above — each one a guess at \((x, M)\). Every time a new observation arrives, each hypothesis is reweighted by how well it predicts the observed rates. Adaptive likelihood tempering prevents one sharp observation from destroying the cloud at once; resampling multiplies hypotheses that survive, and Metropolis-Hastings moves restore diversity while preserving each tempered target. The weighted cloud approximates the posterior — its spread is the claimed uncertainty. Mechanics, controls, and failure modes live in The Particle Filter.

Watch it converge

The same scenario, run small and live on this page:

Code
import matplotlib.pyplot as plt
import numpy as np
from clocks import (
    ClockArray, InferenceConfig, MassConfig, NoiseConfig,
    PriorConfig, SimulationConfig, infer, simulate,
)
from clocks.viz import THEMES, show, style

clock_array = ClockArray(positions=np.array([[-5.0], [0.0], [5.0]]), track_offset=1.0)
truth = MassConfig(positions=np.array([[2.5]]), masses=np.array([0.10]))
sim = simulate(SimulationConfig(
    clock_array=clock_array, ground_truth=truth,
    noise=NoiseConfig(observation_std=0.005), n_observations=25, seed=42,
))
result = infer(sim.observations, InferenceConfig(
    clock_array=clock_array, noise=NoiseConfig(observation_std=0.005),
    prior=PriorConfig(position_range=(-8.0, 8.0), mass_range=(0.005, 0.15)),
    n_particles=400, n_masses=1,
    ess_target=0.8, rejuvenation_steps=2, proposal_scale=2.38, seed=42,
))

steps = np.arange(1, len(result.history) + 1)
means = np.array([entry.mean for entry in result.history])
stds = np.array([entry.std for entry in result.history])

for theme in THEMES:
    with style(theme) as colors:
        fig, axes = plt.subplots(2, 1, sharex=True, figsize=(7.5, 5.4))
        for j, (ax, label, true_val) in enumerate(
            zip(axes, ["position x", "mass M"], [2.5, 0.10])
        ):
            ax.fill_between(
                steps, means[:, j] - stds[:, j], means[:, j] + stds[:, j],
                alpha=0.15, color=colors.belief, linewidth=0,
            )
            # Drawn before the mean, so the estimate stays visible where
            # it lies on the truth.
            ax.axhline(true_val, color=colors.truth, linewidth=1.3)
            ax.plot(steps, means[:, j], color=colors.belief)
            ax.set_ylabel(label)
        axes[-1].set_xlabel("observation #")
        for ax, true_val in zip(axes, [2.5, 0.10]):
            ax.annotate(
                "truth", xy=(ax.get_xlim()[1], true_val),
                xytext=(-2, 3), textcoords="offset points",
                ha="right", va="bottom", color=colors.truth,
            )
        show(fig)

Posterior mean ± one standard deviation per observation, position above and mass below. Solid lines mark the truth: x = 2.5, M = 0.10.

Posterior mean ± one standard deviation per observation, position above and mass below. Solid lines mark the truth: x = 2.5, M = 0.10.

What to notice

The two estimates tighten together. Relative to the true values, the posterior standard deviation of each is about 10% after the first reading and about 2% after twenty-five: close to the improvement you would expect from averaging independent noise, one over the square root of the number of readings. Neither unknown is the hard one here. The rate profile across the three clock positions constrains both at once: its shape constrains position, and its depth constrains mass once the position is known. The bands are the filter’s own statement of what the data have and have not settled, and they matter more when we add a second dimension.