pub struct RlsParallel<const N: usize, const P: usize> { /* private fields */ }Expand description
Parallel multi-output RLS with shared covariance.
Runs P independent scalar-output RLS instances that share the same
regressor vector a ∈ ℝⁿ and covariance matrix P ∈ ℝⁿˣⁿ. Since
each observation is scalar, the denominator λ + a P aᵀ is a scalar—no
Cholesky decomposition required.
§Model
yᵀ = a X where yᵀ ∈ ℝᵖ, X ∈ ℝⁿˣᵖ, a ∈ ℝⁿEach column xⱼ of X is an independent parameter vector. All P
outputs share the covariance update but have independent parameter
updates weighted by their individual prediction errors.
§Type parameters
N— number of parameters per output (regressor dimension)P— number of parallel outputs
§Example
use flight_solver::rls::{RlsParallel, CovarianceGuards};
// 4 parameters, 3 parallel outputs (e.g. G1 learning for roll/pitch/yaw)
let mut rls = RlsParallel::<4, 3>::new(1e2, 0.995, CovarianceGuards::default());
let a = nalgebra::SVector::<f32, 4>::new(0.1, -0.2, 0.3, 0.05);
let y = nalgebra::SVector::<f32, 3>::new(0.5, -0.3, 0.1);
let stats = rls.update(&a, &y);Implementations§
Source§impl<const N: usize, const P: usize> RlsParallel<N, P>
impl<const N: usize, const P: usize> RlsParallel<N, P>
Sourcepub fn new(gamma: f32, lambda: f32, guards: CovarianceGuards) -> Self
pub fn new(gamma: f32, lambda: f32, guards: CovarianceGuards) -> Self
Create a new parallel RLS with initial covariance P = γ I.
§Arguments
gamma— initial covariance diagonallambda— forgetting factor in(0, 1]guards— numerical guard configuration
Sourcepub fn from_time_constant(
gamma: f32,
ts: f32,
t_char: f32,
guards: CovarianceGuards,
) -> Self
pub fn from_time_constant( gamma: f32, ts: f32, t_char: f32, guards: CovarianceGuards, ) -> Self
Create from a time-constant–based forgetting factor, matching
indiflight’s rlsParallelInit.
λ = (1 − ln 2)^(Ts / Tchar)At time Tchar, the weight of the oldest sample has decayed to 50%.
§Arguments
gamma— initial covariance diagonalts— sampling period in seconds (e.g.1.0 / 8000.0)t_char— characteristic forgetting time in secondsguards— numerical guard configuration
Sourcepub fn update(
&mut self,
a: &OVector<f32, Const<N>>,
y: &OVector<f32, Const<P>>,
) -> UpdateStats
pub fn update( &mut self, a: &OVector<f32, Const<N>>, y: &OVector<f32, Const<P>>, ) -> UpdateStats
Process one observation and update parameter estimates.
§Arguments
a— shared regressor vectora ∈ ℝⁿy— observation vectory ∈ ℝᵖ(one scalar per output)
§Algorithm
- Covariance explosion check
- Compute
P aᵀand scalara P aᵀ - Gain vector:
k = P aᵀ / (λ + a P aᵀ) - Per-diagonal order decrement limiting
- Covariance update:
P ← (KAPmult · P − k (P aᵀ)ᵀ) / λ - Parameter update:
X ← X + k eᵀ
Sourcepub fn params_mut(&mut self) -> &mut OMatrix<f32, Const<N>, Const<P>>
pub fn params_mut(&mut self) -> &mut OMatrix<f32, Const<N>, Const<P>>
Mutable access to the parameter matrix.
Sourcepub fn covariance(&self) -> &OMatrix<f32, Const<N>, Const<N>>
pub fn covariance(&self) -> &OMatrix<f32, Const<N>, Const<N>>
Current shared 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§
Source§impl<const N: usize, const P: usize> Clone for RlsParallel<N, P>
impl<const N: usize, const P: usize> Clone for RlsParallel<N, P>
Source§fn clone(&self) -> RlsParallel<N, P>
fn clone(&self) -> RlsParallel<N, P>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<const N: usize, const P: usize> Freeze for RlsParallel<N, P>
impl<const N: usize, const P: usize> RefUnwindSafe for RlsParallel<N, P>
impl<const N: usize, const P: usize> Send for RlsParallel<N, P>
impl<const N: usize, const P: usize> Sync for RlsParallel<N, P>
impl<const N: usize, const P: usize> Unpin for RlsParallel<N, P>
impl<const N: usize, const P: usize> UnsafeUnpin for RlsParallel<N, P>
impl<const N: usize, const P: usize> UnwindSafe for RlsParallel<N, P>
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
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>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
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
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.