MCPcopy
hub / github.com/nicodjimenez/lstm / bottom_data_is

Method bottom_data_is

lstm.py:83–100  ·  view source on GitHub ↗
(self, x, s_prev = None, h_prev = None)

Source from the content-addressed store, hash-verified

81 self.xc = None
82
83 def bottom_data_is(self, x, s_prev = None, h_prev = None):
84 # if this is the first lstm node in the network
85 if s_prev is None: s_prev = np.zeros_like(self.state.s)
86 if h_prev is None: h_prev = np.zeros_like(self.state.h)
87 # save data for use in backprop
88 self.s_prev = s_prev
89 self.h_prev = h_prev
90
91 # concatenate x(t) and h(t-1)
92 xc = np.hstack((x, h_prev))
93 self.state.g = np.tanh(np.dot(self.param.wg, xc) + self.param.bg)
94 self.state.i = sigmoid(np.dot(self.param.wi, xc) + self.param.bi)
95 self.state.f = sigmoid(np.dot(self.param.wf, xc) + self.param.bf)
96 self.state.o = sigmoid(np.dot(self.param.wo, xc) + self.param.bo)
97 self.state.s = self.state.g * self.state.i + s_prev * self.state.f
98 self.state.h = self.state.s * self.state.o
99
100 self.xc = xc
101
102 def top_diff_is(self, top_diff_h, top_diff_s):
103 # notice that top_diff_s is carried along the constant error carousel

Callers 1

x_list_addMethod · 0.80

Calls 1

sigmoidFunction · 0.85

Tested by

no test coverage detected