A pose graph
The example pose_graph, read top-down: a robot's poses and landmarks on SE(3) built tick by tick, a hundred datasets drawn from the model, estimated together by Levenberg–Marquardt, and the Laplace marginals checked for calibration against the truth.
A robot drives a closed circuit.
It measures its own motion between ticks by odometry, and the landmarks it passes by a range sensor that returns their positions in its frame.
The example pose_graph, in the umbrella crate’s examples/, builds that model once, draws a hundred datasets from it, each with its own truth, and estimates all of them together: the mode of every dataset, and a Laplace marginal for every pose and landmark.
Then it asks whether those marginals are honest, by counting how often the truth falls inside them.
It runs in CI, and fails when a check fails:
cargo run --release -p skoro --example pose_graphThe model, tick by tick#
Each tick adds a pose, scored by a prior at the first tick and by the commanded motion from the previous pose after it; the odometry, the relative motion between the two poses with an error; each landmark seen for the first time, with a broad prior about its nominal position; and each sighting, the landmark’s position in the pose’s frame with an error. Every term is a normal, on for the poses and the odometry and on for the rest:
crates/skoro/examples/common/model.rs lines 24–78/// Adds tick `k` inside the open scope: the pose `pose/k`, scored by the prior at `k = 0` and by
/// the motion term from `previous` after; the odometry `odometry/{k-1}` from `previous`; each
/// landmark `landmark/j` first sighted at `k`, scored by its prior; each sighting `sighting/k/j`.
/// `landmarks` holds every landmark already in the model, by index, and gains the new ones.
pub fn tick(
scenario: &Scenario,
k: usize,
previous: Option<Q<Pose>>,
landmarks: &mut BTreeMap<usize, Q<Vector<3>>>,
) -> Tick {
let scales = &scenario.scales;
let pose = quantity(format!("pose/{k}"), Pose);
let odometry = match previous {
None => {
let first = constant(Pose, scenario.nominal[0]);
Normal::on(Pose, first, Scale::sds(&scales.first)).score(pose);
None
}
Some(previous) => {
// The command u_{k-1}, the nominal motion between the ticks, as a mapped value of
// constants.
let command = constant(Pose, scenario.nominal[k - 1])
.between(constant(Pose, scenario.nominal[k]));
Normal::on(Pose, previous * command, Scale::sds(&scales.motion)).score(pose);
let odometry = quantity(format!("odometry/{}", k - 1), Pose);
Normal::on(Pose, previous.between(pose), Scale::sds(&scales.odometry)).score(odometry);
Some(odometry)
}
};
let mut new_landmarks = Vec::new();
let mut sightings = Vec::new();
for &(_, j) in scenario.sightings.iter().filter(|&&(at, _)| at == k) {
let landmark = *landmarks.entry(j).or_insert_with(|| {
let m = quantity(format!("landmark/{j}"), Vector::<3>);
let nominal = constant(Vector::<3>, scenario.landmarks[j]);
Normal::on(Vector::<3>, nominal, Scale::sd(scales.landmark)).score(m);
new_landmarks.push((j, m));
m
});
let z = quantity(format!("sighting/{k}/{j}"), Vector::<3>);
Normal::on(
Vector::<3>,
pose.untransform(landmark),
Scale::sd(scales.sighting),
)
.score(z);
sightings.push((j, z));
}
Tick {
pose,
odometry,
new_landmarks,
sightings,
}
}The same function serves the sliding window, which calls it once per tick in a build of its own. Which landmark each pose sights is fixed from the nominal trajectory, before anything is drawn: the structure of a model is not random.
A hundred datasets#
The whole circuit is built in one build.
Generating from it with nothing observed draws the truth and its measurements together, a hundred rows of them, each its own dataset with the one structure.
The query observes the measurements, row by row, with observe_value, and each row starts where dead reckoning on its own odometry puts it:
crates/skoro/examples/common/batch.rs lines 27–61/// Builds the scenario's model, draws `rows` datasets from `seed` with nothing observed, observes
/// every odometry and sighting at the drawn rows, and starts every row.
pub fn dataset(scenario: &Scenario, rows: usize, seed: u64, target: &Target) -> Result<Dataset> {
let mut writer = Writer::new();
let ticks: Vec<Tick> = writer.build(|| {
let mut landmarks = BTreeMap::new();
let mut previous = None;
(0..=scenario.last())
.map(|k| {
let t = tick(scenario, k, previous, &mut landmarks);
previous = Some(t.pose);
t
})
.collect()
})?;
let snapshot = writer.snapshot();
let truth = snapshot
.generate(&Observations::new(), &Key::from_seed(seed), rows, target)?
.values;
let mut given = Observations::new();
for t in &ticks {
for q in measurements(t) {
given = given.observe_value(q, value(&truth, q)?);
}
}
let start = start(scenario, &ticks, &truth, rows, target)?;
Ok(Dataset {
snapshot,
ticks,
truth,
given,
start,
rows,
})
}Since the truth is drawn from the model, the model is right by construction: what the example tests is the estimation, not the modelling.
Rows, and what each solves#
A row, in skoro, is one independent copy of the whole computation, as a batch of tensors has rows: here, one dataset. It is not a coordinate of the state, nor a row of a Jacobian. Every value the model holds, generated, observed or estimated, has one entry per row, and the rows never meet:
So the hundred datasets are estimated together only in that they share the compiled programs, the schedule and every pass. Each row is its own estimation problem, and each is a batch estimate in the sense of state estimation: one least-squares problem over every pose and every landmark of its trajectory at once, a smoother rather than a filter. Its Jacobian has a row for each component of each term’s residual and a column for each tangent coordinate, 1,776 rows and 510 columns here, 6 for each of the 73 poses and 3 for each of the 24 landmarks. Its sparsity is the graph’s, drawn here for a graph of eight poses and four landmarks:
The last sighting, of from , reaches back to the start: it closes the loop, and it is why the batch recovers what dead reckoning lost. The sliding window solves a problem of the same kind over its last five poses alone, with everything before them folded into one dense replacement over what they still share with the past. It never makes that closing sighting, since has already been retired.
The mode of every row#
One linearizer and one schedule serve all hundred rows. LevenbergMarquardt finds each row’s mode, damping and stopping each row on its own, and decrement checks that every row stopped at a stationary point of its density:
crates/skoro/examples/pose_graph.rs lines 60–74// 2. The mode of every row.
let linearizer = Linearizer::new(&snapshot, &query, &target, Assembly::Residual)?;
let schedule = linearizer.schedule()?;
let method = LevenbergMarquardt::default();
let minimized = method.minimize(&linearizer, &schedule, &start)?;
converged(&minimized.rows, "the batch")?;
let mode = minimized.point;
// 3. Stationarity, by the undamped decrement.
let bound = 10.0 * method.tolerance;
stationary(
&decrement(&linearizer, &schedule, &mode)?,
bound,
"the batch",
)?;Every row converges, in eight or nine iterations.
The two checks the code makes, converged and stationary, test different things, and the rest of this section says what.
What a step promises#
Write for the negative log-density of a row’s query, and for the row’s current point. Linearized there, in the chart at , it is a least-squares problem in the tangent step :
with the stacked whitened residuals of every term and their Jacobian, the matrix drawn above; the log-volumes of the terms on are folded into , so that agrees with to first order. Its gradient at is the gradient of in the chart, . A Levenberg–Marquardt step minimizes with a penalty on its length, , with Marquardt’s diagonal (2), so that , and the decrease of it promises is
which is Problem::promised.
It is measured in nats, like , and it does not depend on how the chart’s coordinates are scaled, where the norm of or of would.
When a row stops#
The step is taken if actually decreased, if the gain (4), the decrease obtained over , is positive, and is updated from the gain by Nielsen’s schedule (5).
The row stops, Status::Converged, at the first step that promises , with nats, whether that step was taken or not.
Near the mode a step promises little more than the rounding of , nats with here and the unit roundoff of double precision, and the gain of such a step is rounding of either sign: the last step of the first row promises nats, and its gain is .
Waiting for an acceptance would raise until the row was reported as failing when it had converged.
A row whose passes , or whose iterations pass a hundred, ends with another status, and converged fails the example on it.
Why the point is stationary#
A small promise bounds the distance to the mode only while is small: with large, is small because the damping shortened the step, not because there is nowhere to go. So stationarity is checked apart from the stop, at the final point and with no damping. With the step is Gauss–Newton’s, , and its promise, the decrement, is
with the largest eigenvalue of .
Every pose has a prior or a motion term and every landmark a prior, so has full rank, is invertible, and is zero exactly where is: where the point is stationary for , log-volumes included. decrement computes it for every row, and stationary fails the example unless every row’s is at most .
It is the decrease of a full Gauss–Newton step would still give, in nats, so the check says that no step left could gain more than nats.
Are the uncertainties honest?#
At the mode, the Laplace approximation gives every pose and landmark a normal marginal in its own chart.
The truth’s tangent at the estimate, from Layout::local, whitened by the marginal, is the normalized error; if the marginals are calibrated it follows the chi-squared law with as many degrees of freedom as the quantity has dimensions, and the 90% ellipsoid holds the truth nine times in ten, over datasets drawn from the model. The note on calibration says why, and how large a difference the approximation itself should make.
The example checks it, with a tolerance fixed before it runs, not tuned to its result:
crates/skoro/examples/pose_graph.rs lines 215–226// 4, checked: the scales are in the regime the tolerance was designed for.
check(variance <= SIGMA_PHI * SIGMA_PHI, || {
format!(
"the largest rotational standard deviation {:.4} exceeds {SIGMA_PHI}: the scales
left the regime the check's tolerance was designed for",
variance.sqrt()
)
})?;
// 5. The calibrations, each against its tolerance.
let kappa = variance;
calibrated("poses", &pose_calibration, SLOPE_6 * kappa)?;
calibrated("landmarks", &landmark_calibration, SLOPE_3 * kappa)?;Drawing it#
With SKORO_FIGURES naming a directory, the example also writes the data of these figures, and bin/figures draws them:
SKORO_FIGURES=/tmp/figures cargo run --release -p skoro --example pose_graph
bin/figures /tmp/figuresHow 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…
- The Mathematics section, read start to finish Done The Mathematics section was a collection of notes, one idea to a note, linked by what each builds on, while most of the mathematics the pages relied on sat in the archive's frozen documents, argued in…
- 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…
Built on by
- 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.