Controlpp
Loading...
Searching...
No Matches
controlpp::ReccursiveLeastSquares< T, NParams, 1 > 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 >().setOnes(), const Eigen::Matrix< T, NParams, NParams > &cov_hint=(Eigen::Matrix< T, NParams, NParams >::Identity() *T(1000)), T memory=0.99, T cov_regularisation=1e-9)
 Creates a recursive least square object with start parameters/covariance and a memory factor.
 
void set_cov (const Eigen::Matrix< T, NParams, NParams > &cov)
 
void set_param (const Eigen::Vector< T, NParams > &param)
 
void set_memory (const T &memory)
 
void set_gain_clamp (const T &gain_clamp)
 
const T & gain_clamp () const
 
void input (const T &y, const Eigen::Vector< T, 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
 
const Eigen::Vector< T, NParams > & gain () const
 Returns the gain used for the updata.
 

Detailed Description

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

Calculates the recursive least square for online parameter estimation.

Solves the following system for \(\vec{p}\) online one interation after another

\[ y_k = \vec{s}_k^T \vec{p}_k \]

With the

  • measurement \(y\),
  • the data vector \(\vec{s}\) and
  • the parameter vector \(\vec{p}\)

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) \]

Constructor & Destructor Documentation

◆ ReccursiveLeastSquares()

template<class T , size_t NParams>
controlpp::ReccursiveLeastSquares< T, NParams, 1 >::ReccursiveLeastSquares ( const Eigen::Vector< T, NParams > &  param_hint = Eigen::Vector<T, NParams>().setOnes(),
const Eigen::Matrix< T, NParams, NParams > &  cov_hint = (Eigen::Matrix<T, NParams, NParams>::Identity() * T(1000)),
memory = 0.99,
cov_regularisation = 1e-9 
)
inline

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

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. 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.9and 0.995.
cov_regularisationA value that will be added to the diagonal of the covariance matrix before each update to prevent the covariance to be become too small, ill formed and unregular. This is mainly to increase numerical stability.

Member Function Documentation

◆ cov()

template<class T , size_t NParams>
const Eigen::Matrix< T, NParams, NParams > & controlpp::ReccursiveLeastSquares< T, NParams, 1 >::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

◆ estimate()

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

returns the current best estimate

Returns
the parameter vector

◆ gain()

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

Returns the gain used for the updata.

The gain can be seen as a measurement of uncertainty

Returns
The gain used in the parameter update

◆ gain_clamp()

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

◆ input()

template<class T , size_t NParams>
void controlpp::ReccursiveLeastSquares< T, NParams, 1 >::input ( const T &  y,
const Eigen::Vector< T, 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

◆ set_cov()

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

◆ set_gain_clamp()

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

◆ set_memory()

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

◆ set_param()

template<class T , size_t NParams>
void controlpp::ReccursiveLeastSquares< T, NParams, 1 >::set_param ( const Eigen::Vector< T, NParams > &  param)
inline

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