Tutorials › Statistical Learning (Graduate) › Least-Squares Fitting Of Simplex Weights

Finite-Class Aggregation · Tutorial 307 of 989

Least-Squares Fitting Of Simplex Weights

Learn how to fit nonnegative weights summing to one by least squares and compare the fitted predictor’s population risk with the best simplex-weighted predictor.

Intermediate 12 min read

What You'll Learn

  • Define empirical and population squared risk for a simplex-weighted dictionary predictor
  • Express the least-squares objective as a convex quadratic program
  • Interpret the Karush–Kuhn–Tucker conditions through residual correlations
  • Identify when empirical weights are nonunique
  • Prove a population-risk comparison under boundedness and independent sampling
  • Recognize why an empirical minimizer can still have high population risk on a small sample

From a Dictionary to a Fitted Mixture

Suppose a finite dictionary supplies \(M\) predictors \(g_1,\ldots,g_M\), each mapping an input \(x\) to a real-valued prediction. Instead of selecting one predictor, we can form a weighted prediction. Requiring the weights to be nonnegative and sum to one makes the prediction a convex combination of the dictionary outputs. Least-squares fitting chooses the weights that minimize squared error on the observed sample.

This is a convex optimization problem, but the weights are not generally obtained by minimizing each predictor’s error separately. The predictors interact: a candidate that is imperfect on its own may help when combined with another candidate. The simplex constraint also matters, since it rules out negative weights and weights whose sum differs from one.

Definition: Let \(\Delta_M=\{\lambda\in\mathbb R^M:\lambda_j\geq 0\text{ for every }j,\ \sum_{j=1}^M\lambda_j=1\}\) be the probability simplex. For \(\lambda\in\Delta_M\), define the weighted predictor \(g_\lambda(x)=\sum_{j=1}^M\lambda_jg_j(x)\). Given observations \((X_i,Y_i)\), \(i=1,\ldots,n\), its empirical squared risk is \(\hat R_n(\lambda)=n^{-1}\sum_{i=1}^n(Y_i-g_\lambda(X_i))^2\). For a fresh observation \((X,Y)\) from the target distribution, its population risk is \(R(\lambda)=E[(Y-g_\lambda(X))^2]\), when this expectation is finite.

The empirical least-squares weights are any minimizer \(\hat\lambda\in\arg\min_{\lambda\in\Delta_M}\hat R_n(\lambda)\). Since the simplex is compact and the empirical objective is continuous, a minimizer exists. It need not be unique: different weights can give identical fitted values on the observed inputs.

The Quadratic Program and Its Optimality Conditions

Write \(g_{ij}=g_j(X_i)\). Expanding the squared residuals gives a convenient matrix form. Define \(A\) as the \(M\times M\) matrix with entries \(A_{jk}=n^{-1}\sum_{i=1}^n g_{ij}g_{ik}\), define \(b_j=n^{-1}\sum_{i=1}^nY_i g_{ij}\), and let \(c=n^{-1}\sum_{i=1}^nY_i^2\). Then

$$ \hat R_n(\lambda)=c-2b^\mathsf{T}\lambda+\lambda^\mathsf{T}A\lambda,\qquad \lambda\in\Delta_M. $$

The matrix \(A\) is positive semidefinite: for every \(v\in\mathbb R^M\), \(v^\mathsf{T}Av=n^{-1}\sum_i(\sum_jv_jg_{ij})^2\geq 0\). Thus the objective is convex. It may be strictly convex if \(A\) is positive definite, in which case the minimizer over the convex simplex is unique. Positive definiteness is sufficient, not necessary, for uniqueness.

The gradient coordinate for weight \(j\) has a direct residual interpretation:

$$ \frac{\partial\hat R_n(\lambda)}{\partial\lambda_j} =2\left(\frac{1}{n}\sum_{i=1}^n g_j(X_i)g_\lambda(X_i)-b_j\right) =-\frac{2}{n}\sum_{i=1}^n\bigl(Y_i-g_\lambda(X_i)\bigr)g_j(X_i). $$

At an optimum, gradients for predictors receiving positive weight must agree. A predictor receiving zero weight cannot have a smaller gradient, since shifting a little weight to it would then decrease the objective.

Theorem: A point \(\hat\lambda\in\Delta_M\) minimizes \(\hat R_n\) if and only if there is a number \(\kappa\) such that \(\nabla_j\hat R_n(\hat\lambda)=\kappa\) whenever \(\hat\lambda_j>0\), and \(\nabla_j\hat R_n(\hat\lambda)\geq\kappa\) whenever \(\hat\lambda_j=0\). Equivalently, the empirical residual correlation \(n^{-1}\sum_i(Y_i-g_{\hat\lambda}(X_i))g_j(X_i)\) is the same for all positively weighted predictors and is no larger for any zero-weight predictor.

Proof. For a differentiable convex function \(q\) on a convex set \(C\), a point \(\lambda\in C\) minimizes \(q\) if and only if \(\nabla q(\lambda)^\mathsf{T}(u-\lambda)\geq 0\) for every \(u\in C\). Necessity follows by considering the right derivative at zero of \(q(\lambda+t(u-\lambda))\) for \(0\leq t\leq1\). For sufficiency, convexity gives \(q(u)\geq q(\lambda)+\nabla q(\lambda)^\mathsf{T}(u-\lambda)\geq q(\lambda)\).

Apply this criterion to the simplex. Taking \(u\) to be the vertex with all its weight on coordinate \(j\) shows that the criterion is \(\nabla_j q(\lambda)\geq\sum_k\lambda_k\nabla_k q(\lambda)\) for every \(j\). The weighted average on the right is therefore the minimum gradient coordinate. Every coordinate with positive weight must attain that minimum: otherwise the weighted average would exceed the minimum, contradicting the inequality for a minimum-gradient coordinate. Conversely, if all positive-weight coordinates have gradient \(\kappa\) and all other coordinates have gradient at least \(\kappa\), then \(\sum_k\lambda_k\nabla_k q(\lambda)=\kappa\), so the criterion holds. The residual-correlation statement follows from the displayed gradient formula. \(\square\)

Worked Example: An Interior Least-Squares Fit

There are three observations with responses \(0,1,2\), and two dictionary predictors: \(g_1\) predicts \(0\) at every input, while \(g_2\) predicts \(2\) at every input. Write \(\lambda\) for the weight on \(g_2\), so the weight on \(g_1\) is \(1-\lambda\) and the fitted prediction is \(2\lambda\).

The empirical risk is

$$ \hat R_3(\lambda)=\frac{(0-2\lambda)^2+(1-2\lambda)^2+(2-2\lambda)^2}{3} =\frac{12\lambda^2-12\lambda+5}{3} =4\lambda^2-4\lambda+\frac{5}{3}. $$

Differentiating gives \(\hat R_3'(\lambda)=8\lambda-4\), so the unique unconstrained minimum is \(\lambda=1/2\), which is feasible. Its empirical risk is \(4(1/4)-4(1/2)+5/3=2/3\). Each endpoint, corresponding to selecting one predictor alone, has risk \(5/3\). Here combining the two predictors reduces empirical squared error.

Worked Example: A Boundary Solution and the KKT Check

Suppose every observed response is \(-1\), and the two predictors are the constants \(g_1=0\) and \(g_2=1\). Let \(t\) be the weight on \(g_2\), with \(0\leq t\leq1\). The mixture predicts \(t\), so \(\hat R_n(t)=(-1-t)^2=(1+t)^2\). Its derivative is \(2(1+t)>0\) throughout the feasible interval, and its minimum is at \(t=0\).

At this solution the weight on \(g_1\) is positive and the weight on \(g_2\) is zero. The gradient with respect to the weight on \(g_1\) is zero, because \(g_1=0\); the gradient with respect to the weight on \(g_2\) is \(2\). Thus the active gradient is \(\kappa=0\), and the inactive gradient is at least \(\kappa\), as required. The residual is \(-1\): its correlation with \(g_1\) is \(0\), while its correlation with \(g_2\) is \(-1\), no larger than the active correlation.

Comparing Empirical Fit with the Population Oracle

The best simplex-weighted predictor for the target distribution is a population oracle \(\lambda^*\in\arg\min_{\lambda\in\Delta_M}R(\lambda)\). An empirical minimizer need not equal this oracle. A useful comparison follows directly from empirical optimality: if \(D_n=\sup_{\lambda\in\Delta_M}|\hat R_n(\lambda)-R(\lambda)|\), then

$$ R(\hat\lambda)\leq \hat R_n(\hat\lambda)+D_n \leq \hat R_n(\lambda^*)+D_n \leq R(\lambda^*)+2D_n. $$

The middle inequality is the definition of empirical minimization; the other two follow from the definition of \(D_n\). This deterministic inequality separates fitting from generalization: the empirical optimizer compares well with the population oracle whenever the empirical and population risks are uniformly close over the simplex.

Theorem: Suppose \((X_i,Y_i)\) are independent and identically distributed, the dictionary \(g_1,\ldots,g_M\) is fixed, and \(|Y|\leq B\) and \(|g_j(X)|\leq B\) almost surely for every \(j\), for some finite \(B>0\). Then \(D_n\xrightarrow{p}0\). Consequently, for any empirical minimizer \(\hat\lambda\) and any population minimizer \(\lambda^*\), \(R(\hat\lambda)\leq R(\lambda^*)+o_p(1)\) when \(M\) is fixed.

Proof. For any \(\lambda,\mu\in\Delta_M\), the bounds on the responses and predictors give \(|g_\lambda(X)|\leq B\) and \(|g_\lambda(X)-g_\mu(X)|\leq B\|\lambda-\mu\|_1\). Factoring a difference of squares therefore yields

$$ \left|(Y-g_\lambda(X))^2-(Y-g_\mu(X))^2\right| \leq 4B^2\|\lambda-\mu\|_1. $$

The same bound holds for the difference of population risks and for the difference of empirical risks. Hence the change in \(\hat R_n-R\) between \(\lambda\) and \(\mu\) is at most \(8B^2\|\lambda-\mu\|_1\).

For \(0<\delta<1\), the simplex has a finite \(\delta\)-net in the \(\ell_1\) norm with at most \((1+2/\delta)^M\) points. To see this, take a maximal set of points in the simplex separated by more than \(\delta\). The radius-\(\delta/2\) \(\ell_1\) balls around them are disjoint and lie within the radius-\(1+\delta/2\) ball centered at zero, since every simplex point has \(\ell_1\) norm one. Comparing volumes bounds the number of points by \((1+2/\delta)^M\); maximality makes the set a \(\delta\)-net.

At each fixed net point, the squared loss lies in \([0,4B^2]\). Hoeffding’s inequality and a union bound show that the probability that any net-point deviation exceeds \(t>0\) is at most \(2(1+2/\delta)^M\exp(-nt^2/(8B^4))\). If no such deviation occurs, the Lipschitz bound extends the deviation from the net to the entire simplex, giving

$$ P\left(D_n>t+8B^2\delta\right) \leq 2(1+2/\delta)^M\exp\left(-\frac{nt^2}{8B^4}\right). $$

For fixed \(\delta\) and \(t\), the right side tends to zero as \(n\) grows. Given any target deviation \(\varepsilon>0\), first choose \(\delta\) so that \(8B^2\delta<\varepsilon/2\), then choose \(t<\varepsilon/2\). The bound proves \(D_n\xrightarrow{p}0\). Substitution into the deterministic oracle inequality proves the population-risk comparison. \(\square\)

Worked Example: A Small Sample Can Miss the Population Oracle

Let \(Y\) be Bernoulli with success probability \(1/2\), let the two fixed predictors be the constants \(0\) and \(1\), and use one observation. If \(\lambda\) is the weight on the predictor \(1\), the mixture predicts \(\lambda\). Its population risk is

$$ R(\lambda)=\tfrac12(0-\lambda)^2+\tfrac12(1-\lambda)^2 =\left(\lambda-\tfrac12\right)^2+\tfrac14. $$

The population oracle is \(\lambda^*=1/2\), with risk \(1/4\). But if the single observed response is \(Y_1=1\), the empirical risk \((1-\lambda)^2\) is minimized at \(\hat\lambda=1\); if \(Y_1=0\), the empirical risk \(\lambda^2\) is minimized at \(\hat\lambda=0\). In either case the fitted predictor has population risk \(1/2\), exceeding the oracle risk by \(1/4\), even though its empirical risk is zero. This is not a contradiction: with one observation, empirical risk is not uniformly close to population risk.

Interpretation and a Common Pitfall

Simplex-constrained least squares offers a principled way to use several predictors at once while keeping the resulting prediction within their convex hull. The KKT conditions describe which candidates can receive weight at an optimum, and the population comparison explains what additional ingredient supports a generalization claim: control of the risk difference over all allowed weights.

  • Pitfall: treating the smallest training error as a population guarantee. The one-observation example has zero empirical error but population risk above the oracle’s. Empirical optimality alone gives only the comparison in empirical risk; a population claim also needs control of \(D_n\), or another valid generalization argument.
  • Pitfall: assuming the fitted weights are always unique. Convexity guarantees that the set of minimizers is convex, not that it contains only one point. Predictors that agree on the observed inputs can make different weights empirically indistinguishable.
  • Pitfall: ignoring the simplex constraint when interpreting weights. The KKT conditions include boundary cases. A zero-weight predictor need not have the same residual correlation as predictors with positive weight; its correlation must be no larger.
Key takeaway: Least-squares aggregation minimizes a convex quadratic over the simplex. Its empirical minimizer compares with the best simplex-weighted predictor in population risk when empirical risk is uniformly close to population risk; bounded losses and a fixed finite dictionary ensure this closeness in probability as the sample grows.

Check Your Understanding

Use the definitions and results above to answer these questions.

  1. Why is the least-squares objective convex in the simplex weights, even when the dictionary predictors are correlated?
  2. At an optimum, what condition must hold for predictors with positive weights, and how does it differ for a zero-weight predictor?
  3. State the deterministic inequality comparing the population risk of an empirical minimizer with that of a population oracle.
  4. Which assumptions in the population-risk theorem ensure that the loss class is uniformly controlled?
  5. In the Bernoulli example, why can empirical risk be zero while the fitted predictor’s population risk exceeds the oracle risk?
Clinical Biostats