So I'm running a simple algorithm for gradient descent in python, trying to find the minimums of functions.
My code is reasonably straightforward, I feel it is intuitive. I've tried with the simple example of a second order polynomial.
def s(x):
return x**2
def t(x):
return 2*x
def steepd(a, alpha, epsilon):
b = a - alpha*t(a)
while abs(t(a)) > epsilon:
if t(b) ==0:
return b
else:
a = b
b = a - alpha*t(a)
return b
print(steepd(2,0.1,0.001))
x = np.arange(-10,10,0.01)
plt.plot(x,s(x))
plt.show()
I'm not getting anywhere near close to the minimum however, even by varying both alpha and epsilon significantly.
Can someone point out what the issue is?
Cheers.