def output(self, X):
        S = ad.Sigmoid(ad.MatMul(X, self._W) + self._B)

        #print("S:",S())
        S1 = self.layer1.output_layer(S, X)
        S_list = []
        S_list.append(S1)
        for i in range(self.number_of_layers):
            S_list.append(self.layers[i].output_layer(S_list[i], X))

        S_final = S_list[-1]
        #print(S_final.shape)
        #print(self.Wf.shape)
        #print(self.Bf.shape)
        val = ad.MatMul(S_final, self._Wf) + self._Bf
        #print("The output:",val())
        return val
    def output_layer(self, S_Old, X):
        S = S_Old
        val_z = ad.MatMul(X, self._Uz) + ad.MatMul(S, self._Wz) + self._bz
        Z = ad.Sigmoid(val_z)
        #print("Z",Z())
        val_g = ad.MatMul(X, self._Ug) + ad.MatMul(S, self._Wg) + self._bg
        G = ad.Sigmoid(val_g)
        #print("G",G())
        val_r = ad.MatMul(X, self._Ur) + ad.MatMul(S, self._Wr) + self._br
        R = ad.Sigmoid(val_r)
        #print("R",R())
        val_h = ad.MatMul(X, self._Uh) + ad.MatMul(S * R, self._Wh) + self._bh

        H = ad.Sigmoid(val_h)
        #print("H",H())

        S_New = ((ad.Variable(np.ones_like(G.eval())) - G) * H) + (Z * S)
        #print("Snew",S_New())

        #val = (-G * ((ad.Variable(np.ones_like(G.eval()))- G ) * H) * (self._Ug+self._Wg*self._Wg*temp)) + (((ad.Variable(np.ones_like(G.eval()))- G ) * H*(ad.Variable(np.ones_like(H.eval()))- H ))*(self._Uz+self._Wh*self._Wg*R*temp)+ (self._Wg*S*(ad.Variable(np.ones_like(R.eval()))- R ) * R*(self._Ug+self._Wg*self._Wg*temp))) +(Z*self._Wg*temp) + (S*(self._Ug+self._Wg*self._Wg*temp))
        #print(val())

        return S_New
Пример #3
0
 def test_matmul(self):
     my_graph = ad.MatMul(self.my_w0, self.my_w1)
     tf_graph = tf.matmul(self.tf_w0, self.tf_w1)
     wrt_vars = [self.my_w0, self.my_w1]
     tf_vars = [self.tf_w0, self.tf_w1]
     utils.custom_test(self, my_graph, wrt_vars, tf_graph, tf_vars)