Controlpp
Loading...
Searching...
No Matches
controlpp::ReccursiveLeastSquares< T, NParams, NMeasurements > Class Template Reference

Calculates the recursive least square for online parameter estimation. More...

#include <controlpp/Estimators.hpp>

Public Member Functions

 ReccursiveLeastSquares (const Eigen::Vector< T, NParams > &param_hint=Eigen::Vector< T, NParams >().setOne(), T memory=0.99, T cov_regularisation=1e-9, T gain_clamp=10)
 Creates a recursive least square object with start parameters/covariance and a memory factor.
 
void input (const T &y, const Eigen::Matrix< T, NMeasurements, NParams > &s)
 Adds a new input output pair that updates the estimate.
 
const Eigen::Vector< T, NParams > & estimate () const
 returns the current best estimate
 
const Eigen::Matrix< T, NParams, NParams > & cov () const
 returns the current covariance
 
void set_cov (const Eigen::Matrix< T, NParams, NParams > &cov)
 
void set_cov_regularisation (const T &reg)
 Set the value for the covariant regularisation.
 
cov_regularisation () const
 
void set_memory (const T &memory)
 Sets the memory factor.
 
const T & memory () const
 Returns the memory factor.
 
void set_gain_clamp (const T &gain_clamp)
 Limits the update gain K.
 
const T & gain_clamp ()
 Returns the currect gain clamp factor.
 
const Eigen::Vector< T, NParams > & gain () const
 Returns the gain K used in the parameter update.
 

Detailed Description

template<class T, size_t NParams, size_t NMeasurements = 1>
class controlpp::ReccursiveLeastSquares< T, NParams, NMeasurements >

Calculates the recursive least square for online parameter estimation.

Uses the recursive least squares algorithm:

\[ k_j = \frac{P_{j-1} s_j}{q + s_{j}^{T} P_{j-1} s_j} \]

\[ P_j = \left( P_{j-1} - k_{j} s_{j}^{T} P_{j-1}\right) \frac{1}{q} \]

\[ p_j = p_{j-1} + k_{j} \left( y_j - s_{j}^{T} p_{j-1}\right) \]


For a number of outputs greater than one (NOutputs>1) the model uses the 'Multi-Output System with shared parameter vector'. This allows to use multiple sensors observing the same system states and parameters to increase the estimation result.

There is a default regularisation therm (default: 1e-9) added to the diagonal elements of the covariance updata

There is gain clamping (default: [-10, +10]) applied to the parameter update therem K.

Constructor & Destructor Documentation

◆ ReccursiveLeastSquares()

template<class T , size_t NParams, size_t NMeasurements = 1>
controlpp::ReccursiveLeastSquares< T, NParams, NMeasurements >::ReccursiveLeastSquares ( const Eigen::Vector< T, NParams > &  param_hint = Eigen::Vector<T, NParams>().setOne(),
memory = 0.99,
cov_regularisation = 1e-9,
gain_clamp = 10 
)
inline

Creates a recursive least square object with start parameters/covariance and a memory factor.

Implicitly sets the covariance matrix to a diagonal matrix where each diagonal element has a value of 1000. Large diagonal elements mean that the algorithm is very uncertain about the parameters.

Assertions/Assumptions:

  • 0 < memory <= 1
  • cov_regularisation >= 0
Parameters
param_hintThe start value of the parameter vector. If there is no prior knowledge of the values, 0 is often a good choice.
cov_hintThe start value of the covariance matrix. The covariance matrix is a measure of the uncertainty of the parameter vector. As a starting point use the square of the standard deviation of the noise if known. If there is no prior knowledge of the uncertainties setting it to a diagonal matrix with elements much greater than 1 is often a good choice
memoryThe value memory that determines how much the past determines the new estimate. (In literature often called the: forgetting factor) It has to be within the open-closed range: \((0, 1]\). Remembers more of the past with higher memory and forgets more with lower memory
  • memory = 1: no forgetting, converges to standard least squares
  • memory < 1: forgetting older values with an exponential decay
    Often used values are between 0.8 and 0.98
cov_regularisationAdds a small positive number to the diagonal of the covariance matrix P at every iteration for numerical stability:
  • it prevents the covariance matrix from collapsing to zero
  • reduces the risk of the matrix becoming ill conditioned
  • improves robustness of the gain computation when excitation is weak
    Typical values are between 1e-12 and 1e-6 depending on numerical precision and signal scaling
gain_clampLimits/clamps the elements of the recursive gain vector K = P s / (λ + sᵀ P s) to the range [-gain_clamp, +gain_clamp]. Prevents sudden large scale parameter updates caused by:
  • poor excitation
  • nearly singulare covariance matrices
  • Very small gain denominators
    Important notes: clamping the gain breaks strict optimality and introduces a bias. Typical values are between 5 and 50.

Member Function Documentation

◆ cov()

template<class T , size_t NParams, size_t NMeasurements = 1>
const Eigen::Matrix< T, NParams, NParams > & controlpp::ReccursiveLeastSquares< T, NParams, NMeasurements >::cov ( ) const
inline

returns the current covariance

acts as a measure of the uncertainty of the estimate (higher values signal higher uncertainty)

Returns
the current covariance matrix

◆ cov_regularisation()

template<class T , size_t NParams, size_t NMeasurements = 1>
T controlpp::ReccursiveLeastSquares< T, NParams, NMeasurements >::cov_regularisation ( ) const
inline

◆ estimate()

template<class T , size_t NParams, size_t NMeasurements = 1>
const Eigen::Vector< T, NParams > & controlpp::ReccursiveLeastSquares< T, NParams, NMeasurements >::estimate ( ) const
inline

returns the current best estimate

Returns
the parameter vector

◆ gain()

template<class T , size_t NParams, size_t NMeasurements = 1>
const Eigen::Vector< T, NParams > & controlpp::ReccursiveLeastSquares< T, NParams, NMeasurements >::gain ( ) const
inline

Returns the gain K used in the parameter update.

The gain K can be seen as a measure of uncertainty

Returns
The gain vector;

◆ gain_clamp()

template<class T , size_t NParams, size_t NMeasurements = 1>
const T & controlpp::ReccursiveLeastSquares< T, NParams, NMeasurements >::gain_clamp ( )
inline

Returns the currect gain clamp factor.

Returns
The currect gain clamp factor

◆ input()

template<class T , size_t NParams, size_t NMeasurements = 1>
void controlpp::ReccursiveLeastSquares< T, NParams, NMeasurements >::input ( const T &  y,
const Eigen::Matrix< T, NMeasurements, NParams > &  s 
)
inline

Adds a new input output pair that updates the estimate.

Parameters
yThe new system measurements/outputs
sThe known system inputs
Returns
The new parameter state estimate

◆ memory()

template<class T , size_t NParams, size_t NMeasurements = 1>
const T & controlpp::ReccursiveLeastSquares< T, NParams, NMeasurements >::memory ( ) const
inline

Returns the memory factor.

The memory factor [0, 1], where:

  • larger values: Old parameters and inputs are remembered for longer (slower changes, more robust to noise).
  • smaller values: Old parameters are forgotten more quickly (faster changes)
Returns
The current memory factor

◆ set_cov()

template<class T , size_t NParams, size_t NMeasurements = 1>
void controlpp::ReccursiveLeastSquares< T, NParams, NMeasurements >::set_cov ( const Eigen::Matrix< T, NParams, NParams > &  cov)
inline

◆ set_cov_regularisation()

template<class T , size_t NParams, size_t NMeasurements = 1>
void controlpp::ReccursiveLeastSquares< T, NParams, NMeasurements >::set_cov_regularisation ( const T &  reg)
inline

Set the value for the covariant regularisation.

Often used values: 1e-6 or 1e-9

Parameters
regThe regularisation coefficient that will be added to the diagonal of the covariance matrix

◆ set_gain_clamp()

template<class T , size_t NParams, size_t NMeasurements = 1>
void controlpp::ReccursiveLeastSquares< T, NParams, NMeasurements >::set_gain_clamp ( const T &  gain_clamp)
inline

Limits the update gain K.

Limits the update gain K from -gain_clamp to +gain_clamp. Prevents too fast updates and ill conditioned updates. For example from a lack of excitation variety

default is 10

Parameters
gain_clampThe new gain clamp

◆ set_memory()

template<class T , size_t NParams, size_t NMeasurements = 1>
void controlpp::ReccursiveLeastSquares< T, NParams, NMeasurements >::set_memory ( const T &  memory)
inline

Sets the memory factor.

The memory factor [0, 1], where:

  • larger values: Old parameters and inputs are remembered for longer (slower changes, more robust to noise).
  • smaller values: Old parameters are forgotten more quickly (faster changes)
Parameters
memoryThe new memory factor

The documentation for this class was generated from the following file: