Skip to content
Snippets Groups Projects
Commit d4c05a9a authored by Jeanette Lee's avatar Jeanette Lee
Browse files

new code

parent 5504216b
No related branches found
No related tags found
No related merge requests found
Pipeline #334066 passed
%% Cell type:code id:bd546fce-edaa-4c2b-9de2-2d4b290d7efe tags:
``` python
import numpy as np
from numpy.random import randn
# define the network
N, D_in, H, D_out = 64, 1000, 100, 10
x, y = randn(N, D_in), randn(N, D_out)
w1, w2 = randn(D_in, H), randn(H, D_out)
for t in range(2000):
# forward pass
h = 1 / (1 + np.exp(-x.dot(w1))) # sigmoid activation function
y_pred = h.dot(w2)
loss = np.square(y_pred - y).sum()
print(t, loss)
# calculate analytical gradients
grad_y_pred = 2.0 * (y_pred - y)
grad_w2 = h.T.dot(grad_y_pred)
grad_h = grad_y_pred.dot(w2.T)
grad_w1 = x.T.dot(grad_h * h * (1 - h))
# update parameters of gradient descent
w1 -= 1e-4 * grad_w1
w2 -= 1e-4 * grad_w2
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment