# Lagrange for quadratic programming with linear constraint

First of all, thanks for the help in previous post. The problem I'm facing is some legacy codes used Lagrange multipliers to solve a weighted regression problem. New requirements changed and I'm trying to understand how the old one worked.

More specifically, the problem is

\begin{align}\min_f&\quad\| W(Xf-r)\|^2\\\text{s.t.}&\quad A^\top f=0.\end{align}

I'm trying to reproduce the derivation using Lagrange multiplier but I'm far off. The numerical results from legacy calculation are reasonable. So, I guess there must be something I derived wrong.

My derivation is shown below. Part of the derivation was kindly corrected by Joni in my previous post here Translate standard weighted least square regression to quadratic programming

However, the legacy technical notes has the Lagrange as

Unfortunately like all technical notes, only results are given.

I am not sure where my derivation is wrong.

• Please try to avoid using images to showcase your work (instead, use MathJax) as it helps improve readability and searchability. Good post though. Jan 28 at 20:40
• Sorry, didn't know that. Will do it next time. Thanks for the encouragement.
– inf
Jan 28 at 20:52

The issue is in the objective function and is caused by two conventions. First, the weights need to be for the squared error. Second. typically an optional $$1/2$$ is added to avoid the resulting $$2$$'s in the gradient. So, you are dealing with the following problem:

\begin{align*} \min_f \quad& \frac{1}{2} {(Xf - r)}^T W (Xf - r) \\ \text{s.t.} \quad& A^T f = 0. \end{align*}

[Note: I would rather define the constraint as $$Af = b$$ but followed your original problem.]

The Lagrangian and its gradient w.r.t $$f$$ are

\begin{align*} L(f,\lambda) &= \frac{1}{2} {(Xf - r)}^T W (Xf - r) + \lambda^T A^T f, \\ \nabla_f L(f,\lambda) &= X^T W (X f - r) + A \lambda \\ &= X^T W X f + A \lambda - X^T W r . \end{align*}

where $$\lambda$$ is the dual variable for the constraint. Resulting stationarity and primal feasibility conditions you derive are found as

$$\begin{bmatrix} X^T W X & A \\ A^T & 0 \end{bmatrix} \begin{bmatrix} f \\ \lambda \end{bmatrix} = \begin{bmatrix} X^T W r \\ 0 \end{bmatrix}.$$

While the scalar $$1/2$$ is optional and only affects the dual variable, the other convention comes from how the weighted least squares is defined. The standard linear model assumes that the errors have constant variance. In weighted least squares the underlying model has errors with nonconstant variance. Indeed, the weight of an observation is proportional to the reciprocal of the error variance for that observation, $$w_i = 1/\sigma_i^2$$, thereby cancelling out the nonconstant variance. Therefore, $$W$$ is defined as $$W = \begin{bmatrix} w_1 & 0 & \ldots & 0 \\ 0 & w_2 & \ldots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \ldots & w_n \end{bmatrix}$$

Finally, it is equivalent to transforming the particular linear model by multiplying it with $$W^{1/2}$$. So if you defined $$\mathcal{W}=W^{1/2}$$ you'd be fine, too.

• Thank you very much for the detailed awesome explanation. The notes started with $min_{f} ||W(XF-r)||^2$ and got the results shown above. Sigh... Hope you don't mind one follow-up question. For the Lagrange, why did you have $+\lambda^T$ instead of $-\lambda^T$? Thanks a lot again!
– inf
Jan 29 at 14:38
• You are welcome :) I am, again, just following the convention. It can be written with a minus sign as well. As this is an equality constraint, the dual variable is unrestricted in sign. It it were a "$\leq$" constraint, you would most likely write it with a plus sign to keep your dual variables nonnegative (by convention). More so than the signs, one should focus what a positive or negative value for the constraint implies regarding the value of the associated dual variable. Jan 29 at 18:08
• Thank you very much again! This solved my last puzzle. Nice.
– inf
Jan 30 at 0:42