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>
impl<const N: usize, const D: usize> Rls<N, D>
Sourcepub fn new(gamma: f32, lambda: f32, guards: CovarianceGuards) -> Self
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
Sourcepub fn update(
&mut self,
a_t: &OMatrix<f32, Const<N>, Const<D>>,
y: &OVector<f32, Const<D>>,
) -> UpdateStats
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 vectory ∈ ℝᵈ
§Algorithm
- Covariance explosion check (temporarily increase λ if
P[i,i] > cov_max) - Form
M = λI + A P Aᵀand Cholesky-solve forK = P Aᵀ M⁻¹ - Order decrement limiting on
trace(K A P) - Covariance update:
P ← (KAPmult · P − P Aᵀ Kᵀ) / λ - Parameter update:
x ← x + K (y − A x)
Sourcepub fn params_mut(&mut self) -> &mut OVector<f32, Const<N>>
pub fn params_mut(&mut self) -> &mut OVector<f32, Const<N>>
Mutable access to the parameter estimate.
Sourcepub fn covariance(&self) -> &OMatrix<f32, Const<N>, Const<N>>
pub fn covariance(&self) -> &OMatrix<f32, Const<N>, Const<N>>
Current covariance matrix P ∈ ℝⁿˣⁿ.
Sourcepub fn set_lambda(&mut self, lambda: f32)
pub fn set_lambda(&mut self, lambda: f32)
Set the forgetting factor λ ∈ (0, 1].
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.