Generalized least squares: quadratic form , GLS estimator, estimator covariance, Moore–Penrose inverse (Eqs. (B.1)–(B.2))
DefinitionLocalDistanceNetwork_GLSBasic objects of the generalized least-squares (GLS) problem of Appendix B.2. Throughout, is the data vector (one entry per equation of the Distance Network), is the vector of optimization parameters, and is the coefficient matrix, so that the theory prediction of the data is .
- Weighted quadratic form (Eq. (B.2)). For a weight matrix ,
With , where is the covariance matrix of the data, this is the of Eq. (B.1).
- GLS estimator matrix and estimate.
-
Covariance of a linear estimator. For and a data covariance matrix , the matrix , which is the covariance matrix of when has covariance .
-
Moore–Penrose inverse (Penrose 1956). A matrix is a Moore–Penrose inverse of when the four Penrose equations hold:
These definitions are shared by every statement of the mission.
Formalization Note Index sets are arbitrary finite types. The inverse is Mathlib's matrix inverse, which returns for a singular matrix; every theorem that uses carries hypotheses (positive-definite , injective ) under which is invertible. The Moore–Penrose inverse is introduced as a predicate (the four Penrose equations) rather than as a function; its existence and uniqueness is a separate milestone.
import Mathlib
open Matrix
namespace LocalDistanceNetwork
/-- The generalized least-squares quadratic form of Eq. (B.2),
`Q(X) = (Y - A X)ᵀ W (Y - A X)`, for a coefficient matrix `A`, weight matrix `W`,
data vector `Y` and parameter vector `X`. With `W = C⁻¹` this is the `χ²` of Eq. (B.1). -/
def glsObjective {m n : Type*} [Fintype m] [Fintype n]
(A : Matrix m n ℝ) (W : Matrix m m ℝ) (Y : m → ℝ) (X : n → ℝ) : ℝ :=
(Y - A *ᵥ X) ⬝ᵥ (W *ᵥ (Y - A *ᵥ X))
/-- The generalized least-squares estimator matrix `(Aᵀ W A)⁻¹ Aᵀ W`. -/
noncomputable def glsEstimatorMatrix {m n : Type*} [Fintype m] [Fintype n] [DecidableEq n]
(A : Matrix m n ℝ) (W : Matrix m m ℝ) : Matrix n m ℝ :=
(Aᵀ * W * A)⁻¹ * Aᵀ * W
/-- The generalized least-squares estimate `X̂ = (Aᵀ W A)⁻¹ Aᵀ W Y`. -/
noncomputable def glsEstimate {m n : Type*} [Fintype m] [Fintype n] [DecidableEq n]
(A : Matrix m n ℝ) (W : Matrix m m ℝ) (Y : m → ℝ) : n → ℝ :=
glsEstimatorMatrix A W *ᵥ Y
/-- The covariance matrix `L C Lᵀ` of the linear estimator `L Y` when the data `Y`
have covariance matrix `C`. -/
def linearEstimatorCov {m n : Type*} [Fintype m]
(L : Matrix n m ℝ) (C : Matrix m m ℝ) : Matrix n n ℝ :=
L * C * Lᵀ
/-- `P` is a Moore–Penrose (pseudo)inverse of `M` (Penrose 1956): the four Penrose equations
`M P M = M`, `P M P = P`, `(M P)ᵀ = M P`, `(P M)ᵀ = P M` hold. -/
def IsMoorePenroseInverse {m k : Type*} [Fintype m] [Fintype k]
(M : Matrix m k ℝ) (P : Matrix k m ℝ) : Prop :=
M * P * M = M ∧ P * M * P = P ∧ (M * P)ᵀ = M * P ∧ (P * M)ᵀ = P * M
end LocalDistanceNetwork
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.