# -*- coding: utf-8 -*-
"""numpy_warmup.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1qvQxMvcvAFKye1s_EXVDJN1kNxkPrRRS
"""

import numpy as np

N, D_in, H, D_out =64, 1000, 100, 10

x=np.random.randn(N, D_in)
y=np.random.randn(N, D_out)

print(x.shape)
print(y.shape)

w1 = np.random.randn(D_in, H)
w2 = np.random.randn(H, D_out)
print(w1.shape)
print(w2.shape)

learning_rate = 1e-6

for t in range(500):
  h=x.dot(w1)
  h_relu=np.maximum(h, 0)
  y_pred=h_relu.dot(w2)
  loss=np.square(y_pred-y).sum()
  print(t, loss)
  grad_y_pred=2*(y_pred-y)
  grad_w2=h_relu.T.dot(grad_y_pred)
  grad_h_relu=grad_y_pred.dot(w2.T)
  grad_h = grad_h_relu.copy()
  grad_h[h < 0] = 0
  grad_w1 = x.T.dot(grad_h)
  w1 -= learning_rate * grad_w1
  w2 -= learning_rate * grad_w2
1f5986d5c458d20d36c8cb2d1adc4a311727fb84
<mask token>

<mask token>
print(x.shape)
print(y.shape)
<mask token>
print(w1.shape)
print(w2.shape)
<mask token>
for t in range(500):
    h = x.dot(w1)
    h_relu = np.maximum(h, 0)
    y_pred = h_relu.dot(w2)
    loss = np.square(y_pred - y).sum()
    print(t, loss)
    grad_y_pred = 2 * (y_pred - y)
    grad_w2 = h_relu.T.dot(grad_y_pred)
    grad_h_relu = grad_y_pred.dot(w2.T)
    grad_h = grad_h_relu.copy()
    grad_h[h < 0] = 0
    grad_w1 = x.T.dot(grad_h)
    w1 -= learning_rate * grad_w1
    w2 -= learning_rate * grad_w2

<mask token>
N, D_in, H, D_out = 64, 1000, 100, 10
x = np.random.randn(N, D_in)
y = np.random.randn(N, D_out)
print(x.shape)
print(y.shape)
w1 = np.random.randn(D_in, H)
w2 = np.random.randn(H, D_out)
print(w1.shape)
print(w2.shape)
learning_rate = 1e-06
for t in range(500):
    h = x.dot(w1)
    h_relu = np.maximum(h, 0)
    y_pred = h_relu.dot(w2)
    loss = np.square(y_pred - y).sum()
    print(t, loss)
    grad_y_pred = 2 * (y_pred - y)
    grad_w2 = h_relu.T.dot(grad_y_pred)
    grad_h_relu = grad_y_pred.dot(w2.T)
    grad_h = grad_h_relu.copy()
    grad_h[h < 0] = 0
    grad_w1 = x.T.dot(grad_h)
    w1 -= learning_rate * grad_w1
    w2 -= learning_rate * grad_w2

<mask token>
import numpy as np
N, D_in, H, D_out = 64, 1000, 100, 10
x = np.random.randn(N, D_in)
y = np.random.randn(N, D_out)
print(x.shape)
print(y.shape)
w1 = np.random.randn(D_in, H)
w2 = np.random.randn(H, D_out)
print(w1.shape)
print(w2.shape)
learning_rate = 1e-06
for t in range(500):
    h = x.dot(w1)
    h_relu = np.maximum(h, 0)
    y_pred = h_relu.dot(w2)
    loss = np.square(y_pred - y).sum()
    print(t, loss)
    grad_y_pred = 2 * (y_pred - y)
    grad_w2 = h_relu.T.dot(grad_y_pred)
    grad_h_relu = grad_y_pred.dot(w2.T)
    grad_h = grad_h_relu.copy()
    grad_h[h < 0] = 0
    grad_w1 = x.T.dot(grad_h)
    w1 -= learning_rate * grad_w1
    w2 -= learning_rate * grad_w2

# -*- coding: utf-8 -*-
"""numpy_warmup.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1qvQxMvcvAFKye1s_EXVDJN1kNxkPrRRS
"""

import numpy as np

N, D_in, H, D_out =64, 1000, 100, 10

x=np.random.randn(N, D_in)
y=np.random.randn(N, D_out)

print(x.shape)
print(y.shape)

w1 = np.random.randn(D_in, H)
w2 = np.random.randn(H, D_out)
print(w1.shape)
print(w2.shape)

learning_rate = 1e-6

for t in range(500):
  h=x.dot(w1)
  h_relu=np.maximum(h, 0)
  y_pred=h_relu.dot(w2)
  loss=np.square(y_pred-y).sum()
  print(t, loss)
  grad_y_pred=2*(y_pred-y)
  grad_w2=h_relu.T.dot(grad_y_pred)
  grad_h_relu=grad_y_pred.dot(w2.T)
  grad_h = grad_h_relu.copy()
  grad_h[h < 0] = 0
  grad_w1 = x.T.dot(grad_h)
  w1 -= learning_rate * grad_w1
  w2 -= learning_rate * grad_w2