12 template<u
int32_t dim>
26 constexpr RLS(
float delta_,
float lambda_)
32 defaultParamsVector(
Matrixf<dim, 1>::zeros()) {
38 defaultParamsVector = initParam;
39 paramsVector = initParam;
49 paramsVector = defaultParamsVector;
62 const float previousOutput = (sampleVector.
trans() * paramsVector)[0][0];
63 gainVector = (transMatrix * sampleVector) /
64 (1.0f + (sampleVector.
trans() * transMatrix * sampleVector)[0][0] / lambda) /
67 gainVector * (actualOutput - previousOutput);
69 (transMatrix - gainVector * sampleVector.
trans() * transMatrix) / lambda;
70 output = (sampleVector.
trans() * paramsVector)[0][0];
73 lastUpdate = std::clock();
83 paramsVector = updatedParams;
84 defaultParamsVector = updatedParams;
114 void validate()
const {
116 if (!(lambda > 0.0f && lambda <= 1.0f))
117 throw std::invalid_argument(
"RLS lambda must be in (0, 1]");
120 throw std::invalid_argument(
"RLS delta must be positive");
131 Matrixf<dim, dim> transMatrix;
132 Matrixf<dim, 1> gainVector;
133 Matrixf<dim, 1> paramsVector;
134 Matrixf<dim, 1> defaultParamsVector;
constexpr Matrix< _cols, _rows, T > trans() const
Get the transpose of the matrix
static constexpr Matrix eye()
Returns a _rows * columns matrix
static constexpr Matrix zeros()
Returns a _rows x _cols zero matrix
RLS()=delete
Delete the default constructor
void reset()
Reset the RLS module
constexpr RLS(float delta_, float lambda_)
The constructor
constexpr Matrixf< dim, 1 > & getParamsVector()
The getter function of the params vector
const Matrixf< dim, 1 > & update(const Matrixf< dim, 1 > &sampleVector, float actualOutput)
Proccess a cycle of RLS update
const float & getOutput() const
The getter function of the output vector
void setParamVector(const Matrixf< dim, 1 > &updatedParams)
Set the default regression parameters