skoro v0.0.0

A sliding window

The example sliding_window, read top-down: a model kept to its last few poses as a robot drives an open path, each tick appended, solved and the oldest retired with a linearized replacement, and its estimates set beside the truth and the batch.

Builds on A pose graph

A robot that drives on cannot keep every pose it has had. The example sliding_window keeps a window: the last five poses, the landmarks they see, and one factor standing in for everything before. At every tick it appends the new pose and its measurements, finds the window’s mode, and retires the oldest pose with the landmarks only it still sees, replacing their terms by their linearization. It is the model of the pose graph, on an open path, built one tick at a time:

cargo run --release -p skoro --example sliding_window
One of the hundred datasets: the path from above and from the side, and each tick's position error in all three dimensions, for dead reckoning, the window as each pose arrives, and the batch with every measurement. Dead reckoning drifts mostly in height, which only the side view shows.
A sliding-window filter over an open path: its estimates against the truth, dead reckoning and the batch, and each tick’s position error A sliding window, retiring as it goes One of 100 datasets: 80 poses along an open path the window: last 5 poses 10 m Top view (x, y) Height along the path, which the top view hides side view: the height axis is stretched 0 m +1 m +2 m +3 m +4 m +5 m +6 m +7 m 0 10 20 30 40 50 60 70 tick dead reckoning Position error at each tick, in all three dimensions 1 cm 10 cm 1 m 0 10 20 30 40 50 60 70 tick dead reckoning window batch Truth Dead reckoning Window, filtering: each pose as it arrives Batch, every measurement Window’s 90% radius filtering coverage 92.8% against 90% · gap to the batch at the end 0.10 σ

One of the hundred datasets: the path from above and from the side, and each tick's position error in all three dimensions, for dead reckoning, the window as each pose arrives, and the batch with every measurement. Dead reckoning drifts mostly in height, which only the side view shows.

A tick#

The truth and the measurements come from the whole path’s model, drawn as the batch draws them. The window is a second model, written by its own Writer, which observes the measurements as they arrive:

A window of two poses, retiring as it goes
t0t_0 x0\randomPoint_0 x1\randomPoint_1 x2\randomPoint_2 x3\randomPoint_3 t1ut^u_1 t2ut^u_2 t3ut^u_3 t0yt^y_0 y0\otherRandomPoint_0 t1yt^y_1 y1\otherRandomPoint_1 t2yt^y_2 y2\otherRandomPoint_2 t01zt^z_{01} z01\bfz_{01} t11zt^z_{11} z11\bfz_{11} t22zt^z_{22} z22\bfz_{22} t32zt^z_{32} z32\bfz_{32} m1\bfm_1 t1mt^m_1 m2\bfm_2 t2mt^m_2 ψ1\psi_1 ψ2\psi_2
  • Free quantity
  • Observed quantity
  • Term scoring a quantity
  • Replacement
  • Retiring quantity
  • Retiring measurement
  • Term joined to them
  • Replacement joined to them
  • Quantity in the blanket
  • conditions a term
  • scores a quantity
crates/skoro/examples/sliding_window.rs lines 55–125
// The window's number of nodes after each tick.
let mut nodes: Vec<usize> = Vec::new();
for k in 0..=scenario.last() {
    // 1. Append, and start what was appended.
    let previous = live.newest();
    let landmarks = &mut live.landmarks;
    let appended = window.build(|| tick(&scenario, k, previous, landmarks))?;
    live.append(k, &appended, &whole.ticks[k], &whole.truth)?;
    live.start(&scenario, k, &appended, N, &target)?;

    // 2. Solve, from the previous mode.
    let snapshot = window.snapshot();
    let query = Query::log_density().given(live.observations());
    let linearizer = Linearizer::new(&snapshot, &query, &target, Assembly::Residual)?;
    let schedule = linearizer.schedule()?;
    let minimized = method.minimize(&linearizer, &schedule, &live.point)?;
    let context = format!("the window at tick {k}");
    converged(&minimized.rows, &context)?;
    stationary(
        &decrement(&linearizer, &schedule, &minimized.point)?,
        bound,
        &context,
    )?;
    iterations.extend(minimized.rows.iter().map(|o| o.iterations as f64));
    live.point = minimized.point;

    // 3. Report the newest pose's marginal: the window's filtering law of it.
    let truth = Values::new().with(
        appended.pose,
        value(&whole.truth, whole.ticks[k].pose)?.clone(),
    );
    let quantities = linearizer.layout().quantities().to_vec();
    let chart = linearizer.at_in_chart(&live.point, &quantities)?;
    let marginal =
        normalized_errors(&linearizer, &chart, &live.point, &truth, appended.pose.id())?;
    variance = marginal
        .spread
        .into_iter()
        .flatten()
        .fold(variance, f64::max);
    filtering.push(marginal.errors);
    if figures::wanted() {
        let at = rows(&live.point, appended.pose)?;
        filtered.push(Json::Object(vec![
            ("mode", figures::position(&at, 7, FIGURE_ROW)),
            ("covariance", Json::numbers(&marginal.position[FIGURE_ROW])),
        ]));
    }

    // 4. Retire the oldest pose once the window holds more than W, with the landmarks only it
    // still sees, replacing their terms by their linearization at the window's mode.
    if live.len() > W {
        let a = k - W;
        let (addresses, observed) = live.retiring(a);
        let retirement = window.retire(addresses, observed)?;
        let keep: Vec<QDyn> = retirement.plan().blanket.iter().map(|(q, ..)| *q).collect();
        let replacing = Replacing::new(&retirement, &keep, &Observations::new(), &target)?;
        let replacement = replacing.at(&live.point)?;
        retirement.replace(|_| replacement.build())?;
        live.retire(a);
    }
    nodes.push(window.snapshot().len());
}
// A retirement frees what it leaves needed by nothing, so the window stops growing once it is
// full: its count after tick 2w stays within 1.5 times its largest over the first full
// windows, the spread of the landmarks in view.
let largest = |ticks: &[usize]| ticks.iter().copied().max().unwrap_or(0);
let (first, later) = (largest(&nodes[W + 1..=2 * W]), largest(&nodes[2 * W + 1..]));
check(2 * later <= 3 * first, || {
    format!("the window grew from {first} nodes to {later}")
})?;
Every step
  1. Tick 0: the window appends the first pose with its prior, and its sighting of the landmark m1\bfm_1, seen for the first time, with its prior.
  2. Tick 1: the next pose, the motion term from the last, the odometry between them, and a second sighting of m1\bfm_1. The odometry and the sightings are observed, at the values the whole model drew.
  3. Tick 2: a third pose, and a new landmark m2\bfm_2.
  4. The window solves for its mode, from the last mode and the starts of what was just appended. It now holds three poses, more than w=2w = 2.
  5. The oldest pose x0\randomPoint_0 retires, with the odometry and the sighting taken from it, observed. No landmark retires: x1\randomPoint_1 still sees m1\bfm_1.
  6. Every term joined to them goes: the prior t0t_0, the odometry and sighting terms, and the motion term t1ut^u_1, which scores x1\randomPoint_1 but is conditioned on x0\randomPoint_0. What they involve beyond the retired quantities is the Markov blanket: x1\randomPoint_1 and m1\bfm_1.
  7. The retired terms, linearized at the window's mode and integrated over x0\randomPoint_0, leave one factor ψ1\psi_1 over the blanket, and the retirement puts it in their place. x1\randomPoint_1 is now scored by nothing but is held by ψ1\psi_1.
  8. Tick 3: the window appends a pose and its sighting of m2\bfm_2, and solves again.
  9. Now x1\randomPoint_1 retires, and with it m1\bfm_1, which no other pose of the window sees. A path that never returns never sights it again.
  10. The terms joined to them include the replacement ψ1\psi_1 and the prior of m1\bfm_1. Their blanket is x2\randomPoint_2 alone.
  11. One factor ψ2\psi_2 over x2\randomPoint_2 replaces them all, and the window holds its last two poses again. Everything before them is in ψ2\psi_2.
A window of two poses, retiring as it goes. The window's probabilistic graph. A solid arrow runs from a quantity to a term conditioned on it, a dotted arrow from a term to the quantity it scores. The odometry yk\otherRandomPoint_k and the sightings zkj\bfz_{kj} are observed; the poses xk\randomPoint_k and the landmarks mj\bfm_j are free. A replacement ψ\psi is a likelihood factor over the blanket of what it replaced.

Each tick builds itself with the same tick as the batch, and starts from the window’s previous mode, so a solve takes six or seven iterations. The newest pose’s marginal is the window’s estimate of where the robot is now, given everything measured so far. A retirement names the oldest pose, the odometry and sightings taken from it, and every landmark no other pose of the window sees; their terms are replaced by one factor over what is left, linearized at the window’s mode. A landmark leaves the window with the last pose that sees it, since the path does not come back.

What is reported#

Every tick of every row is checked to have stopped at a stationary point, by its decrement, as the batch is. The window’s size is checked too: a retirement frees the scales, anchors and replacements it leaves needed by nothing, so the number of nodes the window holds stops growing once it is full. Its largest count after tick 2w2w must be within 1.5 times its largest over the first full windows, ticks w+1w + 1 to 2w2w, which is how far the number of landmarks in view varies, and the example prints the largest count and the last. Each tick makes its own scales from numbers, so nothing the window keeps is shared with what it retires; a model that made a measurement noise once for the whole run, as a constant every tick reads, would pin it. Two figures are reported and not checked: how often the truth falls in the window’s 90% ellipsoid, beside the batch’s tolerance, and how far the window’s last pose is from the batch’s, in the batch’s standard deviations. Each replacement is linearized at points the window later moves away from, and the error that makes is not one the mathematics bounds; checking it against the batch’s tolerance would claim more than is known.

How this came to be

The development behind this page, newest first: