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.
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_windowA 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:
- 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
- Tick 0: the window appends the first pose with its prior, and its sighting of the landmark , seen for the first time, with its prior.
- Tick 1: the next pose, the motion term from the last, the odometry between them, and a second sighting of . The odometry and the sightings are observed, at the values the whole model drew.
- Tick 2: a third pose, and a new landmark .
- 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 .
- The oldest pose retires, with the odometry and the sighting taken from it, observed. No landmark retires: still sees .
- Every term joined to them goes: the prior , the odometry and sighting terms, and the motion term , which scores but is conditioned on . What they involve beyond the retired quantities is the Markov blanket: and .
- The retired terms, linearized at the window's mode and integrated over , leave one factor over the blanket, and the retirement puts it in their place. is now scored by nothing but is held by .
- Tick 3: the window appends a pose and its sighting of , and solves again.
- Now retires, and with it , which no other pose of the window sees. A path that never returns never sights it again.
- The terms joined to them include the replacement and the prior of . Their blanket is alone.
- One factor over replaces them all, and the window holds its last two poses again. Everything before them is in .
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 must be within 1.5 times its largest over the first full windows, ticks to , 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:
- Least squares, motivated from MAP estimation and trust regions Done This entry reordered the mathematics' part on least squares and Gaussian approximations so that it begins with the estimate sought and ends with the linear algebra that computes it. Five notes are…
- Free the constants a retirement leaves with no consumer Done A retirement removed the retired quantities and every node computed from them, but never a constant, or a value folded from constants, since those are computed from no quantity: the scales, the…
- Examples that run Done This entry gave skoro two examples that run, in the umbrella crate, each a cargo run --example target that CI runs and that fails when a check of its mathematics fails. pose_graph draws a hundred…