Skip to main content

Ckf

Struct Ckf 

Source
pub struct Ckf<T: FloatScalar, const N: usize, const M: usize> {
    pub x: ColumnVector<T, N>,
    pub p: Matrix<T, N, N>,
    /* private fields */
}
Expand description

Cubature Kalman Filter with third-degree spherical-radial cubature rule.

Uses 2N cubature points with equal weight 1/(2N). Unlike the UKF, the CKF has no tuning parameters — the cubature rule is uniquely determined by the state dimension.

N is the state dimension, M is the measurement dimension. Requires the alloc feature for temporary cubature point storage.

§Example

use numeris::estimate::Ckf;
use numeris::{ColumnVector, Matrix};

let x0 = ColumnVector::from_column([0.0_f64, 1.0]);
let p0 = Matrix::new([[1.0, 0.0], [0.0, 1.0]]);
let mut ckf = Ckf::<f64, 2, 1>::new(x0, p0);

let dt = 0.1;
let q = Matrix::new([[0.01, 0.0], [0.0, 0.01]]);
let r = Matrix::new([[0.5]]);

ckf.predict(
    |x| ColumnVector::from_column([x[(0, 0)] + dt * x[(1, 0)], x[(1, 0)]]),
    Some(&q),
).unwrap();

ckf.update(
    &ColumnVector::from_column([0.12]),
    |x| ColumnVector::from_column([x[(0, 0)]]),
    &r,
).unwrap();

Fields§

§x: ColumnVector<T, N>

State estimate.

§p: Matrix<T, N, N>

State covariance.

Implementations§

Source§

impl<T: FloatScalar, const N: usize, const M: usize> Ckf<T, N, M>

Source

pub fn new(x0: ColumnVector<T, N>, p0: Matrix<T, N, N>) -> Self

Create a new CKF with initial state x0 and covariance p0.

Source

pub fn with_min_variance(self, min_variance: T) -> Self

Set a minimum diagonal variance floor applied after every predict/update.

Source

pub fn with_fading_memory(self, gamma: T) -> Self

Set a fading-memory factor γ ≥ 1 applied to the propagated covariance.

The predicted covariance becomes γ · P_cubature + Q. Default is 1.0.

Source

pub fn state(&self) -> &ColumnVector<T, N>

Reference to the current state estimate.

Source

pub fn covariance(&self) -> &Matrix<T, N, N>

Reference to the current state covariance.

Source

pub fn predict( &mut self, f: impl Fn(&ColumnVector<T, N>) -> ColumnVector<T, N>, q: Option<&Matrix<T, N, N>>, ) -> Result<(), EstimateError>

Predict step.

  • f — state transition: x_{k+1} = f(x_k)
  • q — process noise covariance (pass None for zero process noise)

Generates 2N cubature points, propagates through f, and reconstructs the predicted mean and covariance as γ · P_cubature + Q.

Source

pub fn update( &mut self, z: &ColumnVector<T, M>, h: impl Fn(&ColumnVector<T, N>) -> ColumnVector<T, M>, r: &Matrix<T, M, M>, ) -> Result<T, EstimateError>

Update step.

  • z — measurement vector
  • h — measurement model: z = h(x)
  • r — measurement noise covariance

Covariance update uses the symmetric P - K S Kᵀ form.

Returns the Normalized Innovation Squared (NIS): yᵀ S⁻¹ y.

Source

pub fn update_gated( &mut self, z: &ColumnVector<T, M>, h: impl Fn(&ColumnVector<T, N>) -> ColumnVector<T, M>, r: &Matrix<T, M, M>, gate: T, ) -> Result<Option<T>, EstimateError>

Update with innovation gating — skips state update if NIS exceeds gate.

Returns Ok(None) when rejected, Ok(Some(nis)) when accepted.

Chi-squared thresholds: M=1 → 99%: 6.63 | M=2 → 9.21 | M=3 → 11.34

Auto Trait Implementations§

§

impl<T, const N: usize, const M: usize> Freeze for Ckf<T, N, M>
where T: Freeze,

§

impl<T, const N: usize, const M: usize> RefUnwindSafe for Ckf<T, N, M>
where T: RefUnwindSafe,

§

impl<T, const N: usize, const M: usize> Send for Ckf<T, N, M>
where T: Send,

§

impl<T, const N: usize, const M: usize> Sync for Ckf<T, N, M>
where T: Sync,

§

impl<T, const N: usize, const M: usize> Unpin for Ckf<T, N, M>
where T: Unpin,

§

impl<T, const N: usize, const M: usize> UnsafeUnpin for Ckf<T, N, M>
where T: UnsafeUnpin,

§

impl<T, const N: usize, const M: usize> UnwindSafe for Ckf<T, N, M>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.