def ff(self, x): data = oh.hcol(x, self.x_len) self.x = data i_arg = np.dot(self.w_x_i, data) + np.dot(self.w_h_i, self.hidden) i_arg += np.dot(self.w_c_i, self.cell) + self.w_i self.gate_i = sig(i_arg) f_arg = np.dot(self.w_x_f, data) + np.dot(self.w_h_f, self.hidden) f_arg += np.dot(self.w_c_f, self.cell) + self.w_f self.gate_f = sig(f_arg) c_arg = np.dot(self.w_x_c, data) + np.dot(self.w_h_c, self.hidden) self.c_tan = np.tanh(c_arg + self.w_c) self.cell = self.gate_f * self.cell + self.gate_i * self.c_tan o_arg = np.dot(self.w_x_o, data) + np.dot(self.w_h_o, self.hidden) o_arg += np.dot(self.w_c_o, self.cell) + self.w_o self.gate_o = sig(o_arg) self.hidden = self.gate_o * np.tanh(self.cell) self.p = softmax(self.hidden) return np.argmax(self.p)
def ff(self, x): data = oh.hcol(x, self.x_len) self.x = data i_arg = np.dot(self.w_x_i, data) # print i_arg.shape, self.hidden.shape i_arg += np.dot(self.w_h_i, self.hidden) i_arg += np.dot(self.w_c_i, self.cell) + self.w_i self.gate_i = sig(i_arg) f_arg = np.dot(self.w_x_f, data) + np.dot(self.w_h_f, self.hidden) f_arg += np.dot(self.w_c_f, self.cell) + self.w_f self.gate_f = sig(f_arg) c_arg = np.dot(self.w_x_c, data) + np.dot(self.w_h_c, self.hidden) self.c_tan = np.tanh(c_arg + self.w_c) self.cell = self.gate_f * self.cell + self.gate_i * self.c_tan o_arg = np.dot(self.w_x_o, data) + np.dot(self.w_h_o, self.hidden) o_arg += np.dot(self.w_c_o, self.cell) + self.w_o self.gate_o = sig(o_arg) self.hidden = self.gate_o * np.tanh(self.cell) # print self.hidden.shape y_map = np.dot(self.w_y, self.hidden) self.prob = softmax(y_map) # print 'ff' return np.argmax(self.prob)
def ff(self, data): # OK self.x = oh.hcol(data, self.x_len) res = self.h[0].ff(self.x) for i in xrange(1, self.h_num): if self.peek: res = self.h[i].ff(res, self.x) else: res = self.h[i].ff(res) self.y = np.dot(self.wi, res) + self.wb p_common = np.exp(self.y) self.p = p_common / np.sum(p_common) return np.argmax(self.p)
def ff_fast(self, data): self.x = oh.hcol(data, self.x_len) res = self.h[0].ff_fast(self.x) if self.peek: for i in xrange(1, self.h_num): res = self.h[i].ff_fast(res, self.x) else: for i in xrange(1, self.h_num): res = self.h[i].ff_fast(res) for i in xrange(self.x_len): self.y[i,0] = np.vdot(self.wi[i,:], data) + self.wb[i,0] p_common = np.exp(self.y) self.p = p_common/ np.sum(p_common) return np.argmax(self.p)