Salta al contenuto
Note per Studenti Least Squares Estimation - Linear and Weighted Least Squares Report

Least Squares Estimation - Linear and Weighted Least Squares

In questa pagina 6

Setting

"Real world": a function g:X→Yg:X\to Y with the assumption y=g(x)+ey=g(x)+e; we observe (x,y)(x,y). To make the problem tractable we choose a model class M(θ)\mathcal M(\theta) and select θ∈Rm\theta\in\mathbb R^m such that g^(x;θ)≈g(x)\hat g(x;\theta)\approx g(x) (see System Identification - Estimation Problem and Parametric Model ClassesEstimation means reconstructing an unknown function from noisy samples; the problem is ill posed, so one fixes a parametric model class, and the basic objects (statistic, estimator, estimate) are defined, with the gray-box and black-box versions for dynamical systems.System Identification - Estimation Problem and Parametric Model Classes →). To "fit" a dataset {(xi,yi)}i=1n\{(x_i,y_i)\}_{i=1}^n we need to interpolate it with some g^∈M(θ)\hat g\in\mathcal M(\theta).

Least squares (LS) estimator

Idea. Penalise the squared deviations between the observed values yy and the estimated g^(x;θ)\hat g(x;\theta), i.e. (y−g^(x;θ))2\big(y-\hat g(x;\theta)\big)^2: θ^LS(y)=arg⁡min⁡θ∈Θ∑i=1n(yi−g^(xi;θ))2=arg⁡min⁡θ∈Θ∑i=1n(yi−gi(θ))2,\hat\theta^{LS}(y)=\arg\min_{\theta\in\Theta}\sum_{i=1}^n\big(y_i-\hat g(x_i;\theta)\big)^2=\arg\min_{\theta\in\Theta}\sum_{i=1}^n\big(y_i-g_i(\theta)\big)^2, where gi(θ)=g^(xi;θ)g_i(\theta)=\hat g(x_i;\theta).

  • This is the problem of minimising the mismatch between observed data and estimated data: it does not address the "generalisation" problem.
  • In general g(θ)g(\theta) can be any function, requiring numerical optimisation.

Linear LS

Special case: g(θ)g(\theta) linear. g^(x;θ)=θTx\hat g(x;\theta)=\theta^Tx (equivalently xTθx^T\theta), with y∈Ry\in\mathbb R, and assume y=θTx+ey=\theta^Tx+e. Then ∑i=1n(yi−θTxi)2=∥y−Φθ∥2,y=(y1⋮yn),  Φ=(x1T⋮xnT),\sum_{i=1}^n\big(y_i-\theta^Tx_i\big)^2=\lVert y-\Phi\theta\rVert^2,\qquad y=\begin{pmatrix}y_1\\\vdots\\y_n\end{pmatrix},\ \ \Phi=\begin{pmatrix}x_1^T\\\vdots\\x_n^T\end{pmatrix}, where for a vector a∈Rna\in\mathbb R^n, ∥a∥2=∑iai2=aTa\lVert a\rVert^2=\sum_ia_i^2=a^Ta. This is linear regression, and Φ\Phi is the regression matrix: θ^LS(y)=arg⁡min⁡θ∈Θ∥y−Φθ∥2.\hat\theta^{LS}(y)=\arg\min_{\theta\in\Theta}\lVert y-\Phi\theta\rVert^2. A closed-form (analytical) solution is available (if Θ=Rm\Theta=\mathbb R^m).

Idea: compute the gradient and set it equal to zero. ∇θ∥y−Φθ∥2=∇θ(y−Φθ)T(y−Φθ) ∝ (y−Φθ)TΦ=!0\nabla_\theta\lVert y-\Phi\theta\rVert^2=\nabla_\theta(y-\Phi\theta)^T(y-\Phi\theta)\ \propto\ (y-\Phi\theta)^T\Phi\overset!=0 (the board writes the gradient as 2(y−Φθ)TΦ2(y-\Phi\theta)^T\Phi and then drops the factor 2; the exact gradient is −2(y−Φθ)TΦ-2(y-\Phi\theta)^T\Phi, a nonzero constant factor that does not change the equation). Then yTΦ=θTΦTΦ ⟹ ΦTy=ΦTΦ θ(normal equation).y^T\Phi=\theta^T\Phi^T\Phi\ \Longrightarrow\ \boxed{\Phi^Ty=\Phi^T\Phi\,\theta}\qquad\text{(normal equation).} If ΦTΦ\Phi^T\Phi is invertible we can compute θ=(ΦTΦ)−1ΦTy,\theta=(\Phi^T\Phi)^{-1}\Phi^Ty, which is possible if and only if the columns of Φ\Phi are independent. (When ΦTΦ\Phi^T\Phi is not invertible see Pseudoinverse and SVD for Rank-Deficient Least SquaresWhen the matrix of the normal equation is not invertible the least squares problem has infinitely many solutions; using the singular value decomposition and the pseudoinverse one picks the solution of minimal norm, derived here step by step.Pseudoinverse and SVD for Rank-Deficient Least Squares →.)

Weighted LS

Some data points may be "more important" than others: they provide more accurate or reliable information about gg. Then θ^LS(y)=arg⁡min⁡θ∑i=1nwi(yi−gi(θ))2,wi>0.\hat\theta^{LS}(y)=\arg\min_\theta\sum_{i=1}^nw_i\big(y_i-g_i(\theta)\big)^2,\qquad w_i>0. If wiw_i is large, the data point (xi,yi)(x_i,y_i) is more "important": LS estimation tries to minimise (yi−gi(θ))2\big(y_i-g_i(\theta)\big)^2 "more" than the others.

Example. If yi=gi(θ)+eiy_i=g_i(\theta)+e_i and ei∼(μ,σi2)e_i\sim(\mu,\sigma_i^2), then one rule of thumb is wi=1σi2w_i=\dfrac1{\sigma_i^2}.

Weighted linear LS

With W=diag⁡(w1,…,wn)W=\operatorname{diag}(w_1,\dots,w_n): θ^LS(y)=arg⁡min⁡θ∥y−Φθ∥W2=arg⁡min⁡θ(y−Φθ)TW(y−Φθ),\hat\theta^{LS}(y)=\arg\min_\theta\lVert y-\Phi\theta\rVert_W^2=\arg\min_\theta(y-\Phi\theta)^TW(y-\Phi\theta), whose solution is θ^LS(y)=(ΦTWΦ)−1ΦTWy(if ΦTWΦ is invertible).\hat\theta^{LS}(y)=(\Phi^TW\Phi)^{-1}\Phi^TWy\qquad(\text{if }\Phi^TW\Phi\text{ is invertible}). How good this estimator is, for W=P−1W=P^{-1} with PP the noise covariance, is the subject of Performance of the Linear Least Squares EstimatorWith zero-mean noise of covariance P, the weighted least squares estimator with weight P inverse is unbiased and has the smallest variance among all unbiased estimators that are linear in the data; the proof compares it with an arbitrary linear unbiased estimator.Performance of the Linear Least Squares Estimator →.

Example - coefficients of a DC motor

A DC motor: a voltage source v(t)v(t) drives a resistor-inductor circuit with current i(t)i(t); the rotor has inertia JJ, angle θ(t)\theta(t) and a disturbance torque τd\tau_d. The mechanical equation is kmi(t)=Jθ¨(t)+qvθ˙(t)+τd,τm(t)=kmi(t),τd=τsfsign⁡(θ˙(t)),k_mi(t)=J\ddot\theta(t)+q_v\dot\theta(t)+\tau_d,\qquad\tau_m(t)=k_mi(t),\qquad\tau_d=\tau_{sf}\operatorname{sign}\big(\dot\theta(t)\big), where the viscous friction coefficient qvq_v and the dry friction torque τsf\tau_{sf} (circled on the board) are the coefficients to be estimated.

At constant speed θ¨(t)=0\ddot\theta(t)=0, so τm(t)=qvθ˙(t)+τsfsign⁡(θ˙(t)).\tau_m(t)=q_v\dot\theta(t)+\tau_{sf}\operatorname{sign}\big(\dot\theta(t)\big). Data points (x(t),y(t))(x(t),y(t)) (always assume y=g(x)+ey=g(x)+e): x(t)=(θ˙(t),sign⁡(θ˙(t)))x(t)=\big(\dot\theta(t),\operatorname{sign}(\dot\theta(t))\big) and y(t)=τm(t)y(t)=\tau_m(t). To be estimated: θ=(qvτsf)\theta=\begin{pmatrix}q_v\\\tau_{sf}\end{pmatrix}. Writing y=Φθy=\Phi\theta: (y(t1)⋮y(tn))=(θ˙(t1)sign⁡(θ˙(t1))⋮⋮θ˙(tn)sign⁡(θ˙(tn)))(qvτsf),θ^LS=(q^vτ^sf)=(ΦTΦ)−1ΦTy.\begin{pmatrix}y(t_1)\\\vdots\\y(t_n)\end{pmatrix}=\begin{pmatrix}\dot\theta(t_1)&\operatorname{sign}(\dot\theta(t_1))\\\vdots&\vdots\\\dot\theta(t_n)&\operatorname{sign}(\dot\theta(t_n))\end{pmatrix}\begin{pmatrix}q_v\\\tau_{sf}\end{pmatrix},\qquad\hat\theta^{LS}=\begin{pmatrix}\hat q_v\\\hat\tau_{sf}\end{pmatrix}=(\Phi^T\Phi)^{-1}\Phi^Ty.

Example - fitting a straight line (recap)

y=g(x;θ)+ey=g(x;\theta)+e: the model structure gg is the unknown ("?") and ee is the noise. In the recap picture, the true gg (a curve) is evaluated at points x1,x2,x3,…x_1,x_2,x_3,\dots; the measured yy values are the true values plus an error; the LS cost sums the squared vertical distances between the measured yy and the model g(xi;θ)g(x_i;\theta) (weighted by wiw_i).

Here the true function is g(x)=2+4xg(x)=2+4x (unknown, including its structure). The observations are {(xi,yi)}i=16\{(x_i,y_i)\}_{i=1}^6 with xi=i6x_i=\frac i6 and y=(y1⋮y6)=(2.262.65.84.445.5)y=\begin{pmatrix}y_1\\\vdots\\y_6\end{pmatrix}=\begin{pmatrix}2.26\\2.6\\5.8\\4.4\\4\\5.5\end{pmatrix} (the first entry is hard to read in the strip). Choose the linear model g^(x;θ)=θ1+θ2x\hat g(x;\theta)=\theta_1+\theta_2x; the unknown ground truth is θ0=(24)\theta_0=\begin{pmatrix}2\\4\end{pmatrix}. Linear LS: θ^LS(y)=arg⁡min⁡θ∥y−Φθ∥2\hat\theta^{LS}(y)=\arg\min_\theta\lVert y-\Phi\theta\rVert^2 with Φ=(116126⋮⋮11)∈R6×2,the columns are independent,\Phi=\begin{pmatrix}1&\frac16\\1&\frac26\\\vdots&\vdots\\1&1\end{pmatrix}\in\mathbb R^{6\times2},\qquad\text{the columns are independent,} (ΦTΦ)−1ΦTy=(2.23.2).(\Phi^T\Phi)^{-1}\Phi^Ty=\begin{pmatrix}2.2\\3.2\end{pmatrix}. The fitted line lies close to the true line 2+4x2+4x although the data are scattered around it.

Versione ripasso

Teoria collegata