I am writing a program to perform a linear regression. The actual function I am trying to estimate (for testing purposes) is as follows:
f(x) = 3x + 100
The function I am using to estimate is as follows:
r(x) = wx + b
Where w and b are the parameters being adjusted using stochastic gradient descent. I use the mean squared error function as my loss function:
l = (f(x) - r(x))^2
So, the derivative of l w.r.t. w:
-2x(f(x)-xw-b)
and the derivative of l w.r.t. b:
-2(f(x)-xw-b)
So, to modify the parameters w and b I apply the following operations for every prediction:
w -= -2x(f(x)-xw-b) * 0.000001
b -= -2(f(x)-xw-b) * 0.000001
The value of w eventually converges on 3 (the value found in f(x)) but b seems to just hang around the number it starts on. Am I doing the math wrong?