Inner-Product Spaces, Orthogonality and Least SquaresIntroductionMany problems in artificial intelligence and machine learning require an answer even when an exact solution does not exist. A system of equations may contain more observations than unknown parameters, measurements may be noisy, or a vector may not lie exactly in a desired subspace. Inner-product spaces provide the geometry needed to measure length, angle, similarity, and error. Orthogonality then gives a principled way to decompose vectors and identify the closest possible approximation. These ideas support feature representation, linear regression, dimensionality reduction, signal processing, numerical optimization, and QR-based algorithms. The central principle is that an approximation is often made optimal by requiring its residual error to be orthogonal to the space of allowable approximations. Learning ObjectivesBy the end of this chapter, you should be able to: 1. Define inner products, norms, distances, angles, and orthogonality. 2. Test whether a function satisfies the inner-product axioms. 3. Explain orthogonal and orthonormal sets and bases. 4. Apply orthogonal projections and derive projection formulas. 5. Use Gram–Schmidt orthogonalization to construct an orthonormal basis. 6. Formulate and solve least-squares problems. 7. Explain the normal equations and their assumptions. 8. Use QR factorization for numerically stable least-squares computation. 9. Interpret least-squares regression in an AI/ML context. 10. Recognize limitations involving conditioning, collinearity, noise, and model specification. 1. Inner Products as Generalized Dot ProductsIn the Euclidean space \(\mathbb{R}^n\), the standard inner product of vectors \(x=(x_1,\ldots,x_n)^T\) and \(y=(y_1,\ldots,y_n)^T\) is \[ \langle x,y\rangle=x^Ty=\sum_{i=1}^n x_i y_i. \] More generally, an inner product on a real vector space is a function \(\langle\cdot,\cdot\rangle\) satisfying, for all vectors \(x,y,z\) and real scalars \(\alpha,\beta\): - symmetry: \(\langle x,y\rangle=\langle y,x\rangle\);
- linearity: \(\langle \alpha x+\beta y,z\rangle=\alpha\langle x,z\rangle+\beta\langle y,z\rangle\);
- positive definiteness: \(\langle x,x\rangle\geq 0\), with equality only when \(x=0\).
A vector space equipped with an inner product is called an inner-product space. In complex spaces, symmetry is replaced by conjugate symmetry, and the first argument is usually conjugate-linear. A weighted inner product on \(\mathbb{R}^n\) can be written as \[ \langle x,y\rangle_W=x^TWy, \] where \(W\) is symmetric positive definite. Positive definiteness is essential: it guarantees that \(x^TWx>0\) for every nonzero \(x\). Such inner products are useful when different coordinates have different importance or when a covariance-based geometry is desired. Norm, distance, and angleThe norm induced by an inner product is \[ \|x\|=\sqrt{\langle x,x\rangle}. \] The distance between \(x\) and \(y\) is \(\|x-y\|\). For nonzero vectors, the angle \(\theta\) is defined by \[ \cos\theta=\frac{\langle x,y\rangle}{\|x\|\|y\|}. \] The Cauchy–Schwarz inequality, \[ |\langle x,y\rangle|\leq \|x\|\|y\|, \] ensures that the right-hand side lies between \(-1\) and \(1\). The triangle inequality, \(\|x+y\|\leq \|x\|+\|y\|\), follows from the inner-product axioms. Vectors are orthogonal when \(\langle x,y\rangle=0\). For the standard inner product this means their dot product is zero. Orthogonality generalizes the familiar notion of perpendicularity. 2. Orthogonal and Orthonormal SetsA set \(\{u_1,\ldots,u_k\}\) is orthogonal if every distinct pair is orthogonal. It is orthonormal if it is orthogonal and every vector has unit norm: \[ \langle u_i,u_j\rangle=\begin{cases}1&i=j,\\0&i\ne j.\end{cases} \] Any orthogonal set of nonzero vectors is linearly independent. To see this, suppose \(\sum_i c_i u_i=0\). Taking the inner product with \(u_j\) gives \(c_j\|u_j\|^2=0\), so \(c_j=0\). Thus orthogonal bases are especially convenient for coordinates. If \(\{q_1,\ldots,q_k\}\) is an orthonormal basis for a subspace \(S\), then every \(x\in S\) has the expansion \[ x=\sum_{i=1}^k\langle x,q_i\rangle q_i. \] The coefficients are obtained directly by inner products; no system of simultaneous equations is required. 3. Orthogonal ProjectionLet \(S\) be a subspace with orthonormal basis \(q_1,\ldots,q_k\). The orthogonal projection of a vector \(b\) onto \(S\) is \[ \operatorname{proj}_S(b)=\sum_{i=1}^k\langle b,q_i\rangle q_i. \] The residual is \[ r=b-\operatorname{proj}_S(b). \] It satisfies \(r\perp S\), because for each basis vector \(q_j\), \[ \langle r,q_j\rangle=\langle b,q_j\rangle-\sum_i\langle b,q_i\rangle\langle q_i,q_j\rangle=0. \] Consequently, the projection is the unique vector in \(S\) closest to \(b\). For any \(s\in S\), the Pythagorean relationship gives \[ \|b-s\|^2=\|b-\operatorname{proj}_S(b)\|^2+\|\operatorname{proj}_S(b)-s\|^2. \] The second term is nonnegative, so the minimum occurs when \(s=\operatorname{proj}_S(b)\). If the columns of a matrix \(A\in\mathbb{R}^{m\times n}\) form a basis for its column space and \(A\) has full column rank, the projection matrix onto \(\operatorname{col}(A)\) is \[ P=A(A^TA)^{-1}A^T. \] This formula requires full column rank. If the columns are not independent, \(A^TA\) is singular and the inverse does not exist; the Moore–Penrose pseudoinverse provides the more general expression \(P=AA^+\). 4. Gram–Schmidt OrthogonalizationGram–Schmidt converts a linearly independent set into an orthonormal set spanning the same subspace. Given independent vectors \(a_1,\ldots,a_n\), define \[ v_1=a_1,\qquad q_1=\frac{v_1}{\|v_1\|}, \] and, for \(j>1\), \[ v_j=a_j-\sum_{i=1}^{j-1}\langle a_j,q_i\rangle q_i, \qquad q_j=\frac{v_j}{\|v_j\|}. \] The vector \(v_j\) is obtained by subtracting from \(a_j\) its projection onto the previously constructed subspace. Therefore it is orthogonal to every earlier \(q_i\). Worked example: Gram–SchmidtLet \[ a_1=(1,1,0)^T,\qquad a_2=(1,0,1)^T. \] First, \[ \|a_1\|=\sqrt{2},\qquad q_1=\frac{1}{\sqrt{2}}(1,1,0)^T. \] Next, \[ \langle a_2,q_1\rangle=\frac{1}{\sqrt{2}}, \] so \[ v_2=a_2-\frac{1}{\sqrt{2}}q_1 =(1,0,1)^T-\frac12(1,1,0)^T =\left(\frac12,-\frac12,1\right)^T. \] Its norm is \(\sqrt{3/2}\), giving \[ q_2=\frac{1}{\sqrt{6}}(1,-1,2)^T. \] Thus \(q_1,q_2\) are orthonormal and span the same plane as \(a_1,a_2\). In exact arithmetic, classical Gram–Schmidt is correct. In floating-point computation, nearly dependent vectors can cause loss of orthogonality. Modified Gram–Schmidt, Householder transformations, and Givens rotations are generally preferred in numerical software. 5. Least-Squares ApproximationConsider the system \[ Ax=b, \] where \(A\in\mathbb{R}^{m\times n}\), \(x\in\mathbb{R}^n\), and \(b\in\mathbb{R}^m\). When \(m>n\), the system is overdetermined and usually has no exact solution. The least-squares problem seeks \[ \hat{x}=\arg\min_x\|Ax-b\|_2^2. \] The vector \(A\hat{x}\) is the point in \(\operatorname{col}(A)\) closest to \(b\). The residual \(r=b-A\hat{x}\) must therefore be orthogonal to every column of \(A\): \[ A^Tr=0. \] Substituting the residual gives the normal equations: \[ A^T A\hat{x}=A^Tb. \] If the columns of \(A\) are linearly independent, \(A^TA\) is invertible and \[ \hat{x}=(A^TA)^{-1}A^Tb. \] This expression is mathematically valid under full column rank, but directly forming \(A^TA\) can worsen numerical conditioning. QR factorization is usually safer. Derivation by differentiationDefine \[ f(x)=\|Ax-b\|_2^2=(Ax-b)^T(Ax-b). \] Expanding, \[ f(x)=x^TA^TAx-2b^TAx+b^Tb. \] Because \(A^TA\) is symmetric, \[ \nabla f(x)=2A^TAx-2A^Tb. \] At a differentiable minimum, the gradient is zero, yielding the normal equations. Since \(f\) is a convex quadratic, every solution of the normal equations is a global minimizer; with full column rank, the minimizer is unique. Worked example: a small least-squares systemLet \[ A=\begin{bmatrix}1\\1\\1\end{bmatrix},\qquad b=\begin{bmatrix}2\\3\\4\end{bmatrix}. \] We seek the constant that best represents the three observations. The normal equation is \[ A^TA\hat{x}=A^Tb. \] Since \(A^TA=3\) and \(A^Tb=9\), \[ \hat{x}=3. \] The fitted vector is \(A\hat{x}=(3,3,3)^T\), and the residual is \[ r=b-A\hat{x}=(-1,0,1)^T. \] Indeed, \(A^Tr=-1+0+1=0\). The residual is orthogonal to the model space, and the fitted constant is the sample mean. 6. QR Factorization and Least SquaresIf \(A\) has full column rank, its thin QR factorization is \[ A=QR, \] where \(Q\in\mathbb{R}^{m\times n}\) has orthonormal columns and \(R\in\mathbb{R}^{n\times n}\) is upper triangular and nonsingular. The least-squares objective becomes \[ \|Ax-b\|^2=\|QRx-b\|^2. \] Decompose \(b=QQ^Tb+(I-QQ^T)b\). The second component is orthogonal to the column space of \(Q\), so minimizing the objective reduces to \[ Rx=Q^Tb. \] This triangular system is solved by back substitution. QR avoids explicitly forming \(A^TA\), and generally gives more reliable results when columns are correlated. For square orthogonal matrices, \(Q^TQ=I\). For a rectangular thin-Q matrix, the same identity holds for its columns, although \(QQ^T\) is a projection rather than the full identity. 7. Linear Regression and Model FittingSuppose observations are \((t_i,y_i)\), and a linear model is proposed: \[ y_i\approx \beta_0+\beta_1t_i. \] The design matrix is \[ X=\begin{bmatrix} 1&t_1\\ 1&t_2\\ \vdots&\vdots\\ 1&t_m \end{bmatrix}, \qquad \beta=\begin{bmatrix}\beta_0\\\beta_1\end{bmatrix}. \] Least squares minimizes \(\|X\beta-y\|^2\). The intercept column and predictor column must be linearly independent, which requires that the predictor values are not all identical. The residuals are orthogonal to both columns of \(X\). Hence their sum is zero when an intercept is included, and their predictor-weighted sum is also zero. These are geometric properties, not merely computational coincidences. For polynomial regression, columns such as \(1,t,t^2\) are used. Although the model is linear in its coefficients, these columns can be strongly correlated, especially at large degrees. Centering and scaling predictors, using orthogonal polynomial bases, and solving by QR can improve stability. Least squares minimizes squared error, so large errors receive disproportionately large weight. It is therefore sensitive to outliers. Robust losses, data validation, transformations, or domain-specific error models may be preferable when extreme observations are plausible or costly. 8. Statistical Interpretation and AI/ML RelevanceUnder the model \[ y=X\beta+\varepsilon, \] ordinary least squares estimates \(\beta\) by minimizing residual sum of squares. If the errors have zero conditional mean, \(E[\varepsilon\mid X]=0\), the estimator is unbiased under the usual fixed-design interpretation. If errors are independent with common variance and additional standard assumptions hold, least squares also has classical efficiency properties. These statistical assumptions are distinct from the geometric fact that least squares projects \(y\) onto \(\operatorname{col}(X)\). In machine learning, the design matrix may contain engineered features, embeddings, sensor measurements, or outputs of earlier models. The fitted coefficients are useful only relative to the chosen feature space. A low training residual does not guarantee good generalization. Validation data, regularization, feature selection, and monitoring for distribution shift remain necessary. Ridge regression modifies the objective to \[ \min_\beta \left(\|X\beta-y\|_2^2+\lambda\|\beta\|_2^2\right), \qquad \lambda>0. \] Its stationary equation is \[ (X^TX+\lambda I)\hat\beta=X^Ty. \] The penalty can reduce variance and stabilize estimates under multicollinearity, but it introduces shrinkage and therefore bias. The intercept is often excluded from the penalty, depending on the modeling convention. 9. Applied Case: Predictive Maintenance from Sensor DataBackgroundConsider an illustrative manufacturing case in which a plant records machine vibration, temperature, and operating hours. Engineers want to predict energy consumption for scheduling and anomaly detection. ProblemMeasurements are noisy, and the number of recorded operating conditions exceeds the number of coefficients in a proposed linear model. Exact interpolation is neither expected nor desirable. The team must fit a model while avoiding unstable calculations caused by correlated sensors. AnalysisLet the design matrix contain a column of ones, standardized vibration, standardized temperature, and standardized operating hours. The response vector contains measured energy consumption. Because vibration and temperature are correlated, the columns may be nearly linearly dependent. A normal-equation implementation may amplify round-off error through \(X^TX\). ApproachThe team uses the following workflow: 1. inspect units, missing values, and sensor calibration; 2. standardize predictors using training-set statistics only; 3. split data into training and validation sets; 4. compute a QR factorization of the training design matrix; 5. solve \(R\hat\beta=Q^Ty\) by back substitution; 6. compare validation error with a ridge model; 7. examine residuals by machine, time, and operating regime. If the residuals show systematic patterns, the linear feature space is inadequate. If a few observations dominate the fit, robust regression or investigation of sensor faults is warranted. OutcomeThe QR solution produces a stable least-squares estimate. Ridge regression may perform better on validation data when sensor collinearity is strong. The final model is deployed only with monitoring for missing sensors, changed operating conditions, and prediction errors. Learning pointsThe case demonstrates that least squares is both geometric and operational. Correct matrix dimensions are necessary but insufficient: preprocessing, numerical stability, validation, interpretability, and monitoring determine whether a fitted model is trustworthy. 10. Limitations, Numerical Issues, and Best PracticesRank deficiency and multicollinearityIf columns of \(A\) are dependent, coefficients may not be unique even though the fitted vector is unique. The pseudoinverse gives a minimum-norm solution, while regularization can improve stability. Coefficient interpretation becomes difficult when predictors carry overlapping information. ConditioningA problem can be theoretically solvable yet numerically sensitive. The condition number measures how strongly relative input errors can affect the output. Forming \(A^TA\) approximately squares the condition number, which explains the preference for QR or singular value decomposition (SVD). Scaling and unitsFeatures with very different scales can affect numerical behavior and regularization. Scaling should be performed using training data and documented so that production data receive the identical transformation. Units must remain interpretable when coefficients are reported. Data leakage and fairnessUsing future information, test-set statistics, or post-outcome variables during fitting produces leakage and invalid evaluation. Least-squares systems can also reproduce historical bias. A technically accurate projection may still support unfair decisions if the features or labels encode discriminatory practices. Privacy, access control, auditability, and human review are relevant governance measures. Choice of solverUse QR for a reliable full-rank least-squares solution, SVD when rank deficiency or singular values must be diagnosed, and normal equations mainly when conditioning is acceptable and computational simplicity is important. Never invert a matrix unnecessarily; solve linear systems directly. Contemporary DevelopmentsModern numerical libraries often use blocked Householder QR, randomized least-squares methods for very large matrices, and iterative solvers such as LSQR for sparse systems. Automatic differentiation makes optimization-based fitting convenient, but it does not remove the need to understand rank, conditioning, and objective functions. In deep learning, least-squares subproblems appear in linear output layers, feature compression, system identification, and hybrid models combining neural and physical components. Chapter SummaryInner products generalize dot products and define length, distance, angle, and orthogonality. Orthogonal and orthonormal bases simplify coordinate representation and enable direct projection formulas. Gram–Schmidt constructs an orthonormal basis by repeatedly removing projections onto previously constructed directions. Least squares approximates an inconsistent system by projecting the target vector onto the column space of the design matrix. Its residual is orthogonal to that space, producing the normal equations. QR factorization solves the problem through an orthonormal basis and triangular back substitution, usually with better numerical stability than explicitly forming normal equations. Regression is a major application, but reliable model fitting also requires appropriate features, scaling, validation, awareness of outliers, rank, conditioning, leakage, and fairness. Regularization and SVD extend the basic framework when data are correlated or rank-deficient. Key TermsInner product: A function defining generalized multiplication, geometry, and similarity on a vector space. Inner-product space: A vector space equipped with an inner product. Norm: The length induced by an inner product. Distance: The norm of the difference between two vectors. Orthogonality: A relationship in which the inner product of two vectors is zero. Orthonormal set: A set of mutually orthogonal unit vectors. Projection: The closest vector in a specified subspace to a given vector. Residual: The difference between an observed vector and its fitted approximation. Column space: The subspace spanned by the columns of a matrix. Gram–Schmidt process: An algorithm for constructing orthogonal or orthonormal vectors. Least squares: An optimization method minimizing the squared residual norm. Normal equations: The equations \(A^TA\hat{x}=A^Tb\) characterizing least-squares solutions. QR factorization: A decomposition \(A=QR\) with orthonormal \(Q\) and upper-triangular \(R\). Design matrix: A matrix containing model features or predictors. Rank: The dimension of a matrix’s column space. Conditioning: Sensitivity of a computational problem to perturbations in data. Multicollinearity: Strong linear dependence among predictor variables. Pseudoinverse: A generalized inverse producing least-squares and minimum-norm solutions. Regularization: A penalty or constraint used to improve stability or generalization. Ridge regression: Least squares with an \(\ell_2\)-norm coefficient penalty. Review QuestionsShort Answer Questions1. State the three defining properties of a real inner product. 2. What does it mean for two vectors to be orthogonal? 3. Why are nonzero mutually orthogonal vectors linearly independent? 4. State the geometric condition satisfied by a least-squares residual. 5. What is the purpose of QR factorization in least-squares computation? Long Answer Questions1. Derive the orthogonal projection formula onto a subspace with an orthonormal basis. 2. Explain the Gram–Schmidt process and discuss its numerical limitations. 3. Derive the normal equations both geometrically and using differentiation. 4. Compare normal-equation and QR-based solutions for least-squares problems. 5. Explain how rank deficiency, multicollinearity, and regularization affect regression. Analytical / Application Questions1. Given \(A=\begin{bmatrix}1&0\\1&1\\1&2\end{bmatrix}\) and \(b=(1,2,2)^T\), formulate the normal equations and determine the least-squares coefficient vector. 2. Design a numerically reliable workflow for fitting a predictive-maintenance model with correlated sensor features and missing observations. 3. A fitted regression model has low training error but large validation error and residuals concentrated in one demographic group. Analyze possible statistical, numerical, and governance causes and propose corrective actions. Multiple Choice Questions with AnswersQuestion 1Which condition defines orthogonality under an inner product? A. The vectors have equal norms B. Their inner product is zero C. Their angle is always 45 degrees D. Their coordinate sums are equal Correct Answer: B. Their inner product is zero Question 2For an orthonormal basis q1,...,qk of a subspace S, what is the projection of b onto S? A. The sum of b and all qi B. The product of the qi vectors C. The sum of <b,qi>qi D. The vector b divided by k Correct Answer: C. The sum of <b,qi>qi Question 3What is the residual condition in a full-column-rank least-squares problem? A. A^T(b-Axhat)=0 B. A(b-Axhat)=0 for every A C. A^TA=0 D. b-Axhat is parallel to every column of A Correct Answer: A. A^T(b-Axhat)=0 Question 4If A=QR is a thin QR factorization, how is the least-squares problem solved? A. Solve Qx=R^Tb B. Solve Rx=Q^Tb C. Solve QRx=0 D. Solve R^Tx=Qb Correct Answer: B. Solve Rx=Q^Tb Question 5What is the first normalized vector in Gram–Schmidt when the first input is a1? A. a1^2 B. a1/||a1|| C. ||a1||a1 D. 0 Correct Answer: B. a1/||a1|| Question 6For A with full column rank, which matrix projects onto col(A)? A. A^TA B. (A^TA)^-1 C. A(A^TA)^-1A^T D. A+A Correct Answer: C. A(A^TA)^-1A^T Question 7Why can directly forming A^TA be numerically undesirable? A. It always changes the column space B. It can worsen conditioning C. It makes A rectangular D. It removes all residuals Correct Answer: B. It can worsen conditioning Question 8In ordinary least squares with an intercept, the residuals are orthogonal to which design-matrix column? A. The all-ones column B. Only the response column C. The residual column itself only D. No column Correct Answer: A. The all-ones column Question 9What does ridge regression add to the least-squares objective? A. An l2 coefficient penalty B. An equality constraint that residuals vanish C. A determinant penalty only D. A random orthogonal rotation Correct Answer: A. An l2 coefficient penalty Question 10In the example fitting a constant to 2, 3, and 4, what is the least-squares constant? A. 2 B. 2.5 C. 3 D. 4 Correct Answer: C. 3
|