To derive the closed form solution for the least-square loss, we need to minimize the objective function with respect to W and b. Let's break it down step by step:
-
Rewrite the objective function:
(W, b)
⋆ = arg min
W,b
X
N
n=1
∥y(xn;W, b) − tn∥
2
-
Expand the equation for y(xn;W, b):
y(xn;W, b) = W⊤xn + b
-
Rewrite the objective function using the expanded equation:
(W, b)
⋆ = arg min
W,b
X
N
n=1
∥W⊤xn + b - tn∥
2
-
Square the expression inside the norm:
(W, b)
⋆ = arg min
W,b
X
N
n=1
(W⊤xn + b - tn)⊤(W⊤xn + b - tn)
-
Expand the squared expression:
(W, b)
⋆ = arg min
W,b
X
N
n=1
(xn⊤W⊤ + b - tn)⊤(W⊤xn + b - tn)
-
Distribute the transpose:
(W, b)
⋆ = arg min
W,b
X
N
n=1
(xn⊤W⊤ + b - tn)⊤(W⊤xn + b - tn)
= arg min
W,b
X
N
n=1
(W⊤xn⊤ + b - tn⊤)(W⊤xn + b - tn)
-
Apply the matrix transpose properties:
(W, b)
⋆ = arg min
W,b
X
N
n=1
(xn⊤W + b - tn⊤)(W⊤xn + b - tn)
-
Rearrange the terms:
(W, b)
⋆ = arg min
W,b
X
N
n=1
(xn⊤W⊤Wxn + bW⊤xn + bxn⊤W + bb - xn⊤W⊤tn - btn⊤ + tn⊤tn)
-
Simplify and remove the outer sum:
(W, b)
⋆ = arg min
W,b
(X⊤WX + X⊤bW + bX⊤W + bb - X⊤W⊤T - T⊤W⊤X + T⊤T)
-
Combine like terms:
(W, b)
⋆ = arg min
W,b
(X⊤WX + (X⊤bW)⊤ + (bX⊤W) + bb - X⊤W⊤T - T⊤W⊤X + T⊤T)
-
Simplify further:
(W, b)
⋆ = arg min
W,b
(X⊤WX + 2bX⊤W + bb - X⊤W⊤T - T⊤W⊤X + T⊤T)
-
Take the derivatives with respect to W and b and set them to zero:
∂/(∂W) = 2X⊤XW + 2X⊤b - 2X⊤T = 0
∂/(∂b) = 2bX⊤W - 2T⊤W⊤X + 2T⊤T = 0
-
Solve the system of equations to find W and b. Multiply the first equation by W⊤ from the left and rearrange it:
2W⊤X⊤XW + 2W⊤X⊤b - 2W⊤X⊤T = 0
W⊤X⊤XW + W⊤X⊤b = W⊤X⊤T
Use the second equation to express W⊤X⊤b in terms of T and substitute it back into the first equation:
W⊤X⊤XW + T⊤W⊤X⊤XW = W⊤X⊤T
(X⊤XW)⊤W + (X⊤XW)⊤T = X⊤T
-
Rearrange the equation:
(X⊤XW)⊤(W + T)(X⊤XW)⁻¹ = X⊤T(X⊤XW)⁻¹
-
Cancel out the (X⊤XW)⁻¹ terms:
(W + T)(X⊤XW)⁻¹ = X⊤T
-
Expand the terms:
WX⊤X⊤XW + TX⊤X⊤XW = X⊤TW
-
Rearrange the equation:
WX⊤X⊤XW - X⊤TW + TX⊤X⊤XW = 0
-
Factor out the common term:
(WX⊤X⊤X - X⊤T + TX⊤X⊤X)W = 0
-
Set the expression in the parentheses to zero since W ≠ 0:
WX⊤X⊤X - X⊤T + TX⊤X⊤X = 0
-
Solve the equation for W:
WX⊤X⊤X = X⊤T - TX⊤X⊤X
-
Multiply both sides by (X⊤X)⁻¹:
W = (X⊤X)⁻¹(X⊤T - TX⊤X⊤X)
-
Simplify the right side:
W = (X⊤X)⁻¹(X⊤T - T(X⊤X)⊤)
-
Solve the equation for b by setting the derivative with respect to b to zero:
2bX⊤W - 2T⊤W⊤X + 2T⊤T = 0