Skip to main content

RlsParallel

Struct RlsParallel 

Source
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>
where Const<N>: DimName, Const<P>: DimName,

Source

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

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

§Arguments
  • gamma — initial covariance diagonal
  • lambda — forgetting factor in (0, 1]
  • guards — numerical guard configuration
Source

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 diagonal
  • ts — sampling period in seconds (e.g. 1.0 / 8000.0)
  • t_char — characteristic forgetting time in seconds
  • guards — numerical guard configuration
Source

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 vector a ∈ ℝⁿ
  • y — observation vector y ∈ ℝᵖ (one scalar per output)
§Algorithm
  1. Covariance explosion check
  2. Compute P aᵀ and scalar a P aᵀ
  3. Gain vector: k = P aᵀ / (λ + a P aᵀ)
  4. Per-diagonal order decrement limiting
  5. Covariance update: P ← (KAPmult · P − k (P aᵀ)ᵀ) / λ
  6. Parameter update: X ← X + k eᵀ
Source

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

Current parameter matrix X ∈ ℝⁿˣᵖ.

Source

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

Mutable access to the parameter matrix.

Source

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

Current shared 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 P: usize> Clone for RlsParallel<N, P>

Source§

fn clone(&self) -> RlsParallel<N, P>

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 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> 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.