Skip to content

Commit

Permalink
gradient descent exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
bob7783 committed Feb 4, 2019
1 parent f2438a1 commit 6472fd9
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions linear_regression_class/gd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import matplotlib.pyplot as plt

lr = 1e-2
x1 = 5
x2 = -5

def J(x1, x2):
return x1**2 + x2**4

def g1(x1):
return 2*x1

def g2(x2):
return 4*x2**3

values = []
for i in range(1000):
values.append(J(x1, x2))
x1 -= lr * g1(x1)
x2 -= lr * g2(x2)
values.append(J(x1, x2))

print(x1, x2)
plt.plot(values)
plt.show()

0 comments on commit 6472fd9

Please sign in to comment.