A high-performance Rust library for robotic state estimation, featuring a Differentiable Extended Kalman Filter (DEKF) with neural-network-driven adaptive noise estimation. This project also includes a classical MATLAB simulation for visualization and benchmarking.
This library implements a Differentiable Extended Kalman Filter (DEKF) that:
-
Standard EKF: Uses
nalgebrafor efficient linear algebra operations in the prediction ($x = Fx + Bu$ ) and update steps. -
Adaptive Q-Network: Employs
dfdxto create a small neural network that predicts the diagonal elements of the Process Noise matrix$Q$ from innovation residuals. -
Learning: Provides a
train_stepfunction that minimizes Mean Squared Error (MSE) between predicted states and high-resolution LiDAR ground truth.
graph TD
Root[Extended Kalman Filter Sensor Fusion] --> Src[src/]
Root --> Examples[examples/]
Root --> Tests[tests/]
Root --> Matlab[matlab/]
Root --> Docs[docs/]
Root --> Data[data/]
Root --> Scripts[scripts/]
Root --> Github[.github/]
Src --> DEKF[dekf.rs]
Src --> EKF[ekf.rs]
Src --> QNet[q_network.rs]
Src --> Lib[lib.rs]
Examples --> FusionEx[radar_lidar_fusion.rs]
Tests --> Integration[integration_test.rs]
Matlab --> MRS[RadarLidarFusion.m]
Github --> CI[workflows/rust-ci.yml]
┌─────────────────────────────────────────────────────────┐
│ DEKF Pipeline │
├─────────────────────────────────────────────────────────┤
│ │
│ Innovation Residual (y = z - Hx) │
│ │ │
│ ├──────────────────────┐ │
│ │ │ │
│ ▼ ▼ │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ Q-Network │ │ Standard EKF │ │
│ │ (dfdx MLP) │ │ (nalgebra) │ │
│ │ │ │ │ │
│ │ Input: y (4D) │ │ x = Fx + Bu │ │
│ │ Output: Q_diag │ │ P = FPF^T + Q │ │
│ └──────────────────┘ └──────────────────┘ │
│ │ │ │
│ └──────────┬───────────┘ │
│ ▼ │
│ Adaptive State Prediction │
│ │ │
│ ▼ │
│ MSE Loss vs Ground Truth │
│ │ │
│ ▼ │
│ Backprop & Update Q-Network │
└─────────────────────────────────────────────────────────┘
The EKF handles state transitions and measurements. In the provided example, we use a Constant Velocity (CV) model:
State Vector:
Prediction Step:
- State Prediction: $\hat{x}{k|k-1} = F_k \hat{x}{k-1|k-1} + B_k u_k$
- Covariance Prediction:
$P_{k|k-1} = F_k P_{k-1|k-1} F_k^T + Q_k$
Update Step:
- Innovation: $\tilde{y}k = z_k - H_k \hat{x}{k|k-1}$
- Innovation Covariance:
$S_k = H_k P_{k|k-1} H_k^T + R_k$ - Kalman Gain:
$K_k = P_{k|k-1} H_k^T S_k^{-1}$ - State Update: $\hat{x}{k|k} = \hat{x}{k|k-1} + K_k \tilde{y}_k$
- Covariance Update:
$P_{k|k} = (I - K_k H_k) P_{k|k-1}$
Instead of using a fixed Process Noise matrix
Where
use ekf_sensor_fusion::DifferentiableEKF;
use nalgebra::{DMatrix, DVector};
// Create DEKF for 4D state (x, y, vx, vy), 2D measurement, 1D control
let mut dekf = DifferentiableEKF::new(4, 2, 1);
// ... set up matrices and run prediction/update ...To run the provided radar-lidar fusion example:
cargo run --example radar_lidar_fusionFor consistent build and execution environments, you can use the provided Dockerfile.
-
Build the Image:
docker build -t ekf-sensor-fusion . -
Run the Fusion Example:
docker run ekf-sensor-fusion
Located in /matlab, this script provides a high-fidelity visualization of the fusion process.
- Real-time Tracking: Visualizes ground truth vs. sensor detections vs. fused path.
- Error Analysis: Quantifies performance with RMSE plots.
Please see CONTRIBUTING.md for guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.