Exemplo n.º 1
0
    def bp(self, iE, X, f):
        Dach = actfn.der_activation_function(self.Ach, f)
        Dact = actfn.der_activation_function(self.Act, f)
        self.E = iE * Dac

        self.compute_gradients(X)
        self.compute_prelayererror()
Exemplo n.º 2
0
    def compute_errorsignal(self, iE, f):

        Dac = actfn.der_activation_function(self.Ac, f)
        Dac = Dac.T
        iE = iE.T

        s = Dac.shape
        dh = self.num_units
        sl = s[1]

        self.E = np.zeros((sl, dh))
        en = np.zeros((dh, 1))

        self.params[1] = self.params[1].T

        for i in range(sl - 1, -1, -1):

            enu = (Dac[:, i] * (np.dot(self.params[1], en).T + iE[:, i])).T

            self.E[i, :] = enu.T
            en = enu

        self.params[1] = self.params[1].T
Exemplo n.º 3
0
    def compute_errorsignal(self, iE, f):

        iE = iE.T

        s = self.Ac.shape
        dh = self.num_units
        sl = s[0]

        self.Ze = np.zeros((sl, dh))
        self.Ie = np.zeros((sl, dh))
        self.Fe = np.zeros((sl, dh))
        self.Ce = np.zeros((sl, dh))
        self.Oe = np.zeros((sl, dh))
        self.He = np.zeros((sl, dh))

        enz = np.zeros((dh, 1))
        eni = np.zeros((dh, 1))
        enf = np.zeros((dh, 1))
        eno = np.zeros((dh, 1))
        enc = np.zeros((dh, 1))

        self.params[4] = self.params[4].T
        self.params[5] = self.params[5].T
        self.params[6] = self.params[6].T
        self.params[7] = self.params[7].T

        self.Za = self.Za.T
        self.Ia = self.Ia.T
        self.Fa = self.Fa.T
        self.Ca = self.Ca.T
        self.Oa = self.Oa.T
        self.Ha = self.Ha.T

        Dza = actfn.der_activation_function(self.Za, 'tanh')
        Dia = actfn.der_activation_function(self.Ia, 'sigm')
        Dfa = actfn.der_activation_function(self.Fa, 'sigm')
        Doa = actfn.der_activation_function(self.Oa, 'sigm')
        Dha = actfn.der_activation_function(self.Ha, 'tanh')


        Fn = np.concatenate((self.Fa[:, 1:], np.zeros((dh, 1))), axis=1)
        Cp = np.concatenate((np.zeros((dh, 1)), self.Ca[:, 0:-1]), axis=1)

        for i in range(sl-1,-1,-1):

            enuh = (iE[:, i] + np.dot(self.params[4], enz).T + np.dot(self.params[5], eni).T + np.dot(self.params[6], enf).T + np.dot(self.params[7], eno).T).T
            enuo = (enuh*self.Ha[:, i].reshape(dh,1)*Doa[:, i].reshape(dh,1))
            enuc = (enuh*self.Oa[:, i].reshape(dh,1)*Dha[:, i].reshape(dh,1)) + (self.po*enuo) + self.pi*eni + self.pf*enf + (enc*Fn[:, i].reshape(dh,1))

            enuf = (enuc.T*Cp[:, i]*Dfa[:, i]).T
            enui = (enuc.T*self.Za[:, i]*Dia[:, i]).T
            enuz = (enuc.T*self.Ia[:, i]*Dza[:, i]).T

            self.He[i, :] = enuh.T
            self.Oe[i, :] = enuo.T
            self.Ce[i, :] = enuc.T
            self.Fe[i, :] = enuf.T
            self.Ie[i, :] = enui.T
            self.Ze[i, :] = enuz.T

            enz = enuz
            eni = enui
            enf = enuf
            enc = enuc
            eno = enuo

        self.params[4] = self.params[4].T
        self.params[5] = self.params[5].T
        self.params[6] = self.params[6].T
        self.params[7] = self.params[7].T

        self.Za = self.Za.T
        self.Ia = self.Ia.T
        self.Fa = self.Fa.T
        self.Ca = self.Ca.T
        self.Oa = self.Oa.T
        self.Ha = self.Ha.T