DEV Community

firefrog
firefrog

Posted on

Meet kalbee: State Estimation and Target Tracking, Minus the Pain

If you've ever tracked a car from jittery GPS, smoothed noisy YOLO boxes, or fused a handful of sensors, you know the drill. You either hand-roll filter equations and pray your covariance stays positive-definite, or you wrestle a heavyweight legacy toolkit built for a PhD thesis, not your project.

kalbee is the third option: a clean, modular, numerically stable Python library for modern state estimation and target tracking — one unified API across 10 filters, a smoother, and a full diagnostics suite.

What's inside

10 filters, one interface:

  • Kalman Filter — Joseph-form updates for a rock-solid baseline
  • Extended KF — analytical Jacobians for nonlinear systems
  • Unscented KF — sigma-point propagation, no Jacobians needed
  • Particle Filter — non-Gaussian / Monte Carlo estimation
  • Ensemble KF — built for high-dimensional states
  • Information Filter — the natural fit for multi-sensor fusion
  • Alpha-Beta-Gamma — lightweight fixed-gain tracking
  • Adaptive KF — estimates noise Q and R on the fly
  • Square-Root KF — Cholesky-based updates, roundoff-proof
  • Vectorized KF — batched multi-target tracking

Plus the IMM estimator (switching motion models), an RTS smoother for backward passes, and diagnostics — RMSE, NEES, NIS, log-likelihood — so you can actually prove your filter is consistent, not just eyeball it.

Stability you don't have to think about

Textbook Kalman filters die quietly. Roundoff error creeps in, P loses symmetry or positive-definiteness, and your estimate drifts or crashes. kalbee handles this for you:

  • Joseph-form updates keep P positive-semidefinite through aggressive measurement updates
  • Square-Root filtering propagates the Cholesky factor directly, sidestepping singularity
  • Singular-inversion fallbacks auto-regularize and fall back to pseudoinverses when things get numerically ugly

Showcase: tracking a car through YOLO boxes

Occlusions and sharp turns are where naive trackers fall apart. On a real video stream, tracking a vehicle against raw YOLO detections:

Filter                | Mean deviation (px) | Notes
----------------------|---------------------|---------------------------------
Standard Kalman       |        7.36         | Overshoots on turns
Square-Root Kalman    |        7.36         | Same accuracy, roundoff-robust
Particle Filter       |       57.84         | Drifts when YOLO loses confidence
IMM Blended           |        6.03         | Best — adapts to speed changes
Enter fullscreen mode Exit fullscreen mode

Why IMM wins: it runs Constant-Velocity and Constant-Acceleration models in parallel. Cruising straight? It leans on Constant Velocity. The instant the car brakes or turns, weight shifts to Constant Acceleration, cutting lag. During occlusions, it extrapolates smoothly from velocity history.

Three lines to your first comparison

#pip install kalbee

from kalbee import run_experiment

report = run_experiment(
    signal="sine",
    filters=["kf", "ekf", "ukf", "pf"],
    noise_std=0.5,
)
print(report.summary())

Enter fullscreen mode Exit fullscreen mode

One call, four filters, a ranked report. Swap signals, add filters, tune noise — iterate in seconds.

Try it

Building a robot, processing camera feeds, or researching sensor fusion — kalbee gives you the numerical stability of a serious toolkit with an interface you'll actually enjoy using.

Top comments (0)