In [1]:
import numpy as np
import matplotlib.pyplot as  plt
%matplotlib inline

In [16]:
class RNN():
    def __init__(self, n, w):
        self.x = np.zeros(n)
        self.w = w
    
    def forward_step(self, eta):
        self.x = self.activation(w.dot(self.x) + eta)
    
    def activation(self, x):
        return 1 / (1 + np.exp(-x))

In [31]:
n = 5
T = 10
w = np.random.random((n, n))
my_rnn = RNN(n, w)


5

In [32]:
my_rnn.forward_step(0)

In [33]:
my_rnn.x


Out[33]:
array([ 0.5,  0.5,  0.5,  0.5,  0.5])

In [42]:
etas_1 = np.random.random((T, n))

In [45]:
etas_1[2, 0] = 1
etas_1


Out[45]:
array([[ 0.73168707,  0.29811327,  0.15251963,  0.12443958,  0.86752479],
       [ 0.2784107 ,  0.71006871,  0.15907507,  0.90292896,  0.70399645],
       [ 1.        ,  0.15558261,  0.26951526,  0.08989879,  0.34609678],
       [ 0.08780336,  0.38648613,  0.67574881,  0.04712877,  0.68043618],
       [ 0.96425569,  0.77285352,  0.28562756,  0.78767871,  0.74805415],
       [ 0.95486059,  0.78034882,  0.09297531,  0.38005866,  0.86808699],
       [ 0.32920558,  0.81899232,  0.00344677,  0.17019125,  0.82486194],
       [ 0.90523263,  0.16265911,  0.71908462,  0.54631748,  0.81484389],
       [ 0.39288271,  0.26715016,  0.37537058,  0.88509665,  0.67920804],
       [ 0.89690878,  0.94821432,  0.92333692,  0.06945506,  0.78065807]])

In [51]:
x_star = np.zeros((T, n))
x_star[6, 2:4] = [.1, .9]
x_star


Out[51]:
array([[ 0. ,  0. ,  0. ,  0. ,  0. ],
       [ 0. ,  0. ,  0. ,  0. ,  0. ],
       [ 0. ,  0. ,  0. ,  0. ,  0. ],
       [ 0. ,  0. ,  0. ,  0. ,  0. ],
       [ 0. ,  0. ,  0. ,  0. ,  0. ],
       [ 0. ,  0. ,  0. ,  0. ,  0. ],
       [ 0. ,  0. ,  0.1,  0.9,  0. ],
       [ 0. ,  0. ,  0. ,  0. ,  0. ],
       [ 0. ,  0. ,  0. ,  0. ,  0. ],
       [ 0. ,  0. ,  0. ,  0. ,  0. ]])

In [ ]:


In [ ]: