Estimation filters and analysis¶
Standalone attitude filters (recurrence blocks, siblings of each other) and the observability / consistency analysis tools.
Attitude filters¶
manta.Madgwick ¶
Bases: RecurrenceBlock
Madgwick gyro+accel AHRS filter as a recurrence block.
Args: beta — filter gain (rad/s): the accelerometer correction rate. Higher trusts the accelerometer more (faster convergence, more noise); lower trusts the gyro. ~0.1 is a typical start. name — codegen basename / default C++ class stem.
Source code in manta/estimation/madgwick.py
manta.Mahony ¶
Bases: RecurrenceBlock
Mahony gyro+accel AHRS filter (with bias estimation) as a recurrence
block.
Args:
kp — proportional gain on the accelerometer error (how hard the
accel pulls the attitude).
ki — integral gain; the rate at which the gyro-bias estimate
learns. 0 disables bias estimation (pure complementary).
name — codegen basename / default C++ class stem.
Source code in manta/estimation/mahony.py
manta.IMUIntegrator ¶
IMUIntegrator(*, gravity=(0.0, 0.0, -9.81), p0=(0.0, 0.0, 0.0), v0=(0.0, 0.0, 0.0), q0=(1.0, 0.0, 0.0, 0.0), name='imu_integrator')
Bases: RecurrenceBlock
Strapdown INS dead-reckoner as a recurrence block.
Args:
gravity — world-frame gravity vector (default (0, 0, -9.81)).
p0, v0 — initial position / velocity (world). Default zero.
q0 — initial orientation quaternion (w, x, y, z), body→world.
Default identity.
name — codegen basename / default C++ class stem.
Source code in manta/estimation/imu_integrator.py
Observability and consistency¶
manta.estimation.observability ¶
Observability analysis — does your sensor set actually constrain your state?
A faithful EKF (correct f, correct Jacobians) is still only as good as
the observability of the model it filters: whether the measurements,
through the dynamics, pin down every state direction. Observability is a
property of (dynamics + sensor set + operating point) — not of the
model alone — so "make the model correct and the EKF follows" silently
fails on unobservable modes. They don't error; they drift, and the filter
reports tight covariance while doing it. (The canonical example: heading
is unobservable from GPS + DVL + gyro — only its rate is measured — so a
submarine's yaw estimate wanders until a compass is added. Caveat: that
holds on a non-rotating model. On a spinning planet the Earth rate makes
heading weakly observable through the dynamics — gyrocompassing — at
singular values far below this rank test's threshold; sigma_horizon
below is the tool that resolves such slow channels.)
manta is well placed to catch this automatically, because the symbolic
state-transition F and per-sensor measurement Jacobians H already
exist on the EKF IR (via the shared Linearization). This module builds
the discrete observability matrix at an operating point
O = [H; H·F; H·F²; …; H·F^(n-1)] (n = tangent dimension)
and reports its rank. A rank deficiency means an unobservable subspace;
its null space, projected onto the state slots, tells you which states
(e.g. sub.orientation) you can't see — turning a silent drift into a
setup-time warning.
Usage::
from manta.estimation import observability
rep = observability(EKF(world))
print(rep.summary())
if not rep.observable:
... # add a sensor, or accept the drift on those states
This is local observability at the supplied operating point (the
standard linear test, evaluated along the dynamics for n steps). Check
a few representative points if your system is strongly nonlinear.
The rank test is binary and short-horizon (n steps ≈ a fraction of a
second), so it cannot grade weak observability — information that
arrives through slow dynamics over many seconds. For that, use
:func:sigma_horizon: it runs the filter's own covariance recursion
(no data needed — F, H, Q, R are already baked) along the nominal
trajectory and reports how tight each state can get after horizon
seconds. A slot this rank test calls unobservable but whose σ shrinks
there is weakly observable, with the convergence time read off directly.
ObservabilityReport
dataclass
¶
ObservabilityReport(tangent_dim, rank, sensors, unobservable=list(), singular_values=None, basis=None)
Result of :func:observability.
Attributes:
tangent_dim — total tangent (error-state) dimension n.
rank — rank of the observability matrix (≤ n).
observable — True iff rank == tangent_dim.
sensors — sensor output names folded into the analysis.
unobservable — list of (slot_name, strength) for slots with a
component in the unobservable subspace; strength
is the Frobenius norm of the null-space basis
restricted to that slot (0 ⇒ fully observable).
singular_values — singular values of the observability matrix.
basis — orthonormal basis of the observable subspace,
shape (tangent_dim, rank). Feed to nees(...,
observable_basis=...) to check consistency only
where the state is actually observable.
SigmaHorizonReport
dataclass
¶
Result of :func:sigma_horizon.
Attributes:
horizon, dt — the analyzed window and step.
sensors — sensor output names folded into the recursion.
times — recorded sample times, shape (k,).
sigmas — {slot_name: (k,) array} of the slot's
worst-direction σ (√ of the largest eigenvalue of its
tangent covariance block) at each recorded time.
P_final — full tangent covariance at horizon.
resolve_sensor_set ¶
The chosen sensor full-names. sensors=None keeps every registered
sensor; otherwise each entry resolves like everywhere else (full name or
unique .<suffix>) — an unknown or ambiguous name raises instead of
silently dropping a typo. Shared by observability and nees.
Source code in manta/estimation/observability.py
observability ¶
Local observability of an EKF at an operating point.
Args:
ekf — the EKF transform (EKF(world, ...)).
state — operating-point state (nested {owner: {slot: v}} or
flat), merged over the world's initial state. Defaults
to the world's initial state.
inputs — operating-point control inputs {name: value}.
sensors — restrict the analysis to these sensor outputs (full
names or unambiguous suffixes); None ⇒ all registered.
Use this to ask "what would I lose without the compass?"
dt, t — the step / clock the Jacobians are evaluated at.
rtol — relative singular-value threshold for the rank test.
Returns:
:class:ObservabilityReport.
Source code in manta/estimation/observability.py
observability_trajectory ¶
Observability accumulated over a trajectory, not at one point.
Local observability() is evaluated at a single operating point, where
a state can look unobservable that a maneuver would reveal (absolute
heading from GPS+DVL is the classic case: unobservable at rest,
observable while turning). This rolls out the deterministic nominal
trajectory under control, evaluates the local observability matrix at
~samples points along it, and reports the rank / unobservable slots /
observable basis of their union — i.e. a direction counts as
observable if it is locally observable at any configuration the
trajectory visits. (Union of bounded local matrices, so it stays well
conditioned — unlike propagating one matrix through the whole run,
where the integrators blow the conditioning up.)
Args mirror nees/observability: control is {name: value} or a
t -> {name: value} callable; sensors restricts the suite; samples
caps how many trajectory points are linearized.
Source code in manta/estimation/observability.py
sigma_horizon ¶
sigma_horizon(ekf, *, horizon, dt=0.02, state=None, control=None, sensors=None, P0=None, Q=None, t0=0.0, samples=60, record=200)
Per-slot σ attainable after horizon seconds — the covariance
recursion run open-loop (no data), i.e. the linear-Gaussian CRLB along
the nominal trajectory.
Where :func:observability asks the binary "is this direction in the
observable subspace?" over an n-step window, this asks the graded
question the rank test cannot: how tight does each state get, and how
fast? It propagates the nominal state with the filter's own predict,
evaluates F, Q, H, R along it (all already baked on the EKF), and runs
P ← F P Fᵀ + Q; per due sensor: P ← Joseph(P, H, R)
recording each slot's worst-direction σ. Slow channels the rank test misses — heading from the Earth rate (gyrocompassing), drag-coupled biases — show up as σ trajectories with their convergence time readable directly.
Args:
ekf — the EKF transform (EKF(world, ...)).
horizon — analysis window (s).
dt — filter step (s).
state — starting operating point (nested or flat), merged over
the world's initial state.
control — {name: value} or t -> {name: value} nominal inputs.
sensors — restrict to these outputs (full names / suffixes);
None ⇒ all registered on the EKF.
P0 — initial tangent covariance: full matrix, diagonal
vector, or scalar·I. Default 0.1·I (as nees). Use a
generous prior on the states in question — σ can only
show convergence the prior leaves room for.
Q — process-noise override (else the model's auto L Σ Lᵀ).
t0 — start time (matters on a time-dependent world, e.g. a
rotating planet).
samples — how many points along the trajectory F/Q/H/R are
re-evaluated at (held constant in between).
record — max number of recorded σ samples.
Returns:
:class:SigmaHorizonReport.
Source code in manta/estimation/observability.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | |
manta.estimation.observability_trajectory ¶
Observability accumulated over a trajectory, not at one point.
Local observability() is evaluated at a single operating point, where
a state can look unobservable that a maneuver would reveal (absolute
heading from GPS+DVL is the classic case: unobservable at rest,
observable while turning). This rolls out the deterministic nominal
trajectory under control, evaluates the local observability matrix at
~samples points along it, and reports the rank / unobservable slots /
observable basis of their union — i.e. a direction counts as
observable if it is locally observable at any configuration the
trajectory visits. (Union of bounded local matrices, so it stays well
conditioned — unlike propagating one matrix through the whole run,
where the integrators blow the conditioning up.)
Args mirror nees/observability: control is {name: value} or a
t -> {name: value} callable; sensors restricts the suite; samples
caps how many trajectory points are linearized.
Source code in manta/estimation/observability.py
manta.estimation.sigma_horizon ¶
sigma_horizon(ekf, *, horizon, dt=0.02, state=None, control=None, sensors=None, P0=None, Q=None, t0=0.0, samples=60, record=200)
Per-slot σ attainable after horizon seconds — the covariance
recursion run open-loop (no data), i.e. the linear-Gaussian CRLB along
the nominal trajectory.
Where :func:observability asks the binary "is this direction in the
observable subspace?" over an n-step window, this asks the graded
question the rank test cannot: how tight does each state get, and how
fast? It propagates the nominal state with the filter's own predict,
evaluates F, Q, H, R along it (all already baked on the EKF), and runs
P ← F P Fᵀ + Q; per due sensor: P ← Joseph(P, H, R)
recording each slot's worst-direction σ. Slow channels the rank test misses — heading from the Earth rate (gyrocompassing), drag-coupled biases — show up as σ trajectories with their convergence time readable directly.
Args:
ekf — the EKF transform (EKF(world, ...)).
horizon — analysis window (s).
dt — filter step (s).
state — starting operating point (nested or flat), merged over
the world's initial state.
control — {name: value} or t -> {name: value} nominal inputs.
sensors — restrict to these outputs (full names / suffixes);
None ⇒ all registered on the EKF.
P0 — initial tangent covariance: full matrix, diagonal
vector, or scalar·I. Default 0.1·I (as nees). Use a
generous prior on the states in question — σ can only
show convergence the prior leaves room for.
Q — process-noise override (else the model's auto L Σ Lᵀ).
t0 — start time (matters on a time-dependent world, e.g. a
rotating planet).
samples — how many points along the trajectory F/Q/H/R are
re-evaluated at (held constant in between).
record — max number of recorded σ samples.
Returns:
:class:SigmaHorizonReport.
Source code in manta/estimation/observability.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | |
manta.estimation.nees ¶
nees(world, *, dt, steps, control=None, sensors=None, P0=None, Q=None, observable_basis=None, runs=20, seed=0, warmup=None, alpha=0.05)
Monte-Carlo NEES consistency check for EKF(world).
Each run jitters the truth with the model's process noise (a
NoiseDriver) and the measurements with their R, draws the initial
estimate from P0, runs sim↔ekf over steps, and records NEES at
each post-warmup step. Returns an :class:NEESReport.
Args:
world — the model.
dt, steps — filter step and run length.
control — per-tick inputs: {name: value} (constant) or a
t -> {name: value} callable. Excite the trajectory so
the observable states are actually exercised.
sensors — restrict to these sensor outputs (full names / suffixes);
None ⇒ all registered. They must declare noise (nonzero
R), else the update is singular.
P0 — initial estimate covariance (tangent). Default 0.1·I.
Q — process-noise override for the predict (else the model's
auto-assembled Q). Useful to probe consistency vs. an
assumed Q, or to validate the check responds to scaling.
observable_basis — (n, r) orthonormal basis of the observable
subspace (from observability(...).basis or
observability_trajectory). When given, NEES is measured
only in that subspace (dof = r) — isolating "is my noise
modeling right where I can estimate?" from overconfidence
on unobservable directions.
runs, seed — ensemble size and base RNG seed.
warmup — steps to skip before recording (default steps // 5).
alpha — significance for the band (default 0.05 ⇒ 95%).
Source code in manta/estimation/consistency.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |