Recursive least squares (RLS) updates the parameters of a linear model as samples arrive. It avoids refitting the entire dataset at every step. With exponential forgetting, older samples are down-weighted, not abruptly replaced.
The objective
For scalar readings \(y_i=h_i^\mathsf T\theta+\epsilon_i\), minimize \(\sum_{i=1}^{k}\lambda^{k-i}(y_i-h_i^\mathsf T\theta)^2\), with \(0<\lambda\le1\), plus an optional discounted term from the initialization. With \(\lambda=1\), data are not forgotten.
A sample-by-sample recursion
Set a prior estimate \(\hat\theta_0\) and positive definite inverse-information matrix \(P_0\), such as \(\alpha I_m\) for \(m\) coefficients and \(\alpha>0\). Alternatively, initialize from a full-rank batch. For each sample:
\[ \begin{aligned} e_k &= y_k-h_k^\mathsf T\hat\theta_{k-1},\\ g_k &= \frac{P_{k-1}h_k}{\lambda+h_k^\mathsf T P_{k-1}h_k},\\ \hat\theta_k &= \hat\theta_{k-1}+g_ke_k,\\ P_k &= \frac{(I_m-g_kh_k^\mathsf T)P_{k-1}}{\lambda}. \end{aligned} \]The estimated model must be linear in the parameters, though its features may be nonlinear in the inputs. RLS is useful for adaptive filtering and online system identification. A smaller forgetting factor tracks changing parameters faster but can increase variability. Adequate excitation is essential; squared loss is not inherently robust to outliers. For large or ill-conditioned models, consider numerically stable square-root variants.

