Skip to main content

Rls

Struct Rls 

Source
pub struct Rls<const N: usize, const D: usize> { /* private fields */ }
Expand description

Standard RLS maintaining the covariance matrix P directly.

Supports multi-dimensional observations (D > 1) via Cholesky decomposition of the D × D innovation matrix M = λI + A P Aᵀ.

§Model

y = A x    where  y ∈ ℝᵈ,  x ∈ ℝⁿ,  A ∈ ℝᵈˣⁿ

The regressor matrix is passed as Aᵀ ∈ ℝⁿˣᵈ (column-major, matching the indiflight C convention).

§Type parameters

  • N — number of parameters (regressor dimension)
  • D — observation dimension (number of outputs per sample)

§Example

use flight_solver::rls::{Rls, CovarianceGuards};
use nalgebra::SMatrix;

// 3 parameters, 2-dimensional observations
let mut rls = Rls::<3, 2>::new(1e2, 0.995, CovarianceGuards::default());

let a_t = SMatrix::<f32, 3, 2>::new(
    0.034, 0.227,
    0.135, -0.436,
    -0.169, -0.059,
);
let y = nalgebra::SVector::<f32, 2>::new(0.338, -0.165);

let stats = rls.update(&a_t, &y);

Implementations§

Source§

impl<const N: usize, const D: usize> Rls<N, D>
where Const<N>: DimName, Const<D>: DimName,

Source

pub fn new(gamma: f32, lambda: f32, guards: CovarianceGuards) -> Self

Create a new standard RLS with initial covariance P = γ I.

§Arguments
  • gamma — initial covariance diagonal (higher = more uncertain = faster learning)
  • lambda — forgetting factor in (0, 1] (lower = faster forgetting of old data)
  • guards — numerical guard configuration
Source

pub fn update( &mut self, a_t: &OMatrix<f32, Const<N>, Const<D>>, y: &OVector<f32, Const<D>>, ) -> UpdateStats

Process one observation and update parameter estimate.

§Arguments
  • a_t — regressor matrix transposed, Aᵀ ∈ ℝⁿˣᵈ (column-major). Each column is one regressor vector.
  • y — observation vector y ∈ ℝᵈ
§Algorithm
  1. Covariance explosion check (temporarily increase λ if P[i,i] > cov_max)
  2. Form M = λI + A P Aᵀ and Cholesky-solve for K = P Aᵀ M⁻¹
  3. Order decrement limiting on trace(K A P)
  4. Covariance update: P ← (KAPmult · P − P Aᵀ Kᵀ) / λ
  5. Parameter update: x ← x + K (y − A x)
Source

pub fn params(&self) -> &OVector<f32, Const<N>>

Current parameter estimate x ∈ ℝⁿ.

Source

pub fn params_mut(&mut self) -> &mut OVector<f32, Const<N>>

Mutable access to the parameter estimate.

Source

pub fn covariance(&self) -> &OMatrix<f32, Const<N>, Const<N>>

Current covariance matrix P ∈ ℝⁿˣⁿ.

Source

pub fn lambda(&self) -> f32

Forgetting factor λ.

Source

pub fn set_lambda(&mut self, lambda: f32)

Set the forgetting factor λ ∈ (0, 1].

Source

pub fn samples(&self) -> u32

Number of samples processed so far.

Trait Implementations§

Source§

impl<const N: usize, const D: usize> Clone for Rls<N, D>

Source§

fn clone(&self) -> Rls<N, D>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<const N: usize, const D: usize> Freeze for Rls<N, D>

§

impl<const N: usize, const D: usize> RefUnwindSafe for Rls<N, D>

§

impl<const N: usize, const D: usize> Send for Rls<N, D>

§

impl<const N: usize, const D: usize> Sync for Rls<N, D>

§

impl<const N: usize, const D: usize> Unpin for Rls<N, D>

§

impl<const N: usize, const D: usize> UnsafeUnpin for Rls<N, D>

§

impl<const N: usize, const D: usize> UnwindSafe for Rls<N, D>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.