RNN Labs

Notebook with week 2 lab

Imports

import numpy as np

Hidden State Activation

w_hh = np.full((3, 2), 1); w_hh
array([[1, 1],
       [1, 1],
       [1, 1]])
w_hx = np.full((3, 3), 9); w_hx
array([[9, 9, 9],
       [9, 9, 9],
       [9, 9, 9]])
w_hh.shape, w_hx.shape
((3, 2), (3, 3))
np.concatenate((w_hh, w_hx), axis=1)
array([[1, 1, 9, 9, 9],
       [1, 1, 9, 9, 9],
       [1, 1, 9, 9, 9]])
np.hstack((w_hh, w_hx))
array([[1, 1, 9, 9, 9],
       [1, 1, 9, 9, 9],
       [1, 1, 9, 9, 9]])

Hidden State & Inputs

h_t_prev = np.full((2,1), 1); h_t_prev
array([[1],
       [1]])
x_t = np.full((3,1), 9); x_t
array([[9],
       [9],
       [9]])
np.concatenate((h_t_prev, x_t), axis=0)
array([[1],
       [1],
       [9],
       [9],
       [9]])
np.vstack((h_t_prev, x_t))
array([[1],
       [1],
       [9],
       [9],
       [9]])
w_hh = np.full((3,2), 1); w_hh
w_hx = np.full((3,3), 9); w_hx
h_t_prev = np.full((2,1), 1); h_t_prev
x_t = np.full((3,1), 9); x_t
stack_1 = np.hstack((w_hh, w_hx)); stack_1
stack_2 = np.vstack((h_t_prev, x_t)); stack_2
formula_1 = stack_1@stack_2; formula_1
formula_2 = w_hh@h_t_prev+ w_hx@x_t; formula_2
array([[245],
       [245],
       [245]])