Commits

Anonymous committed 1e91566

add fptt_with_fb

  • Participants
  • Parent commits b430b9c

Comments (0)

Files changed (1)

File pyrnn/elmannet.py

         self.ns.make_grad_for(['uo','uc','woc','wcc','wci','bo','bc'])
         self.ns.make_update_for(['woc','wcc','wci','bo','bc'])
         self.ns.dUc0 = numpy.zeros((num_c,), dtype=numpy.float)
+
+        self.fb_rate  = 1
+        self.fb_delay = 1
         
         self.set_activation()
         self.momentum = 0
             uo[t] = dot(woc,xc[t])+bo
             xo[t] = avo(uo[t])
 
+    def fptt_with_fb(self):
+        xo = self.ns.xo
+        uo = self.ns.uo
+        xc = self.ns.xc
+        uc = self.ns.uc
+        xi = self.ns.xi
+
+        woc = self.ns.woc
+        wcc = self.ns.wcc
+        wci = self.ns.wci
+
+        bo = self.ns.bo
+        bc = self.ns.bc
+        ec = self.ns.ec
+
+        avo = self.avo
+        avc = self.avc
+        dot = numpy.dot
+
+        fbr = self.fb_rate
+        fbd = self.fb_delay
+
+        xc[fbd-1] = avc(uc[fbd-1])
+        for t in self.ns.time_step[fbd:]:
+            xi[t] = fbr * xo[t-fbd] + (1 - fbr) * to[t-fbd]
+            uc[t] = (1-ec)*uc[t-1] + ec*(dot(wci,xi[t])+dot(wcc,xc[t-1])+bc)
+            xc[t] = avc(uc[t])
+            uo[t] = dot(woc,xc[t])+bo
+            xo[t] = avo(uo[t])
+
     def set_dXdU(self):
         self.ns.dXodUo[:] = 1 - self.ns.xo**2
         self.ns.dXcdUc[:] = 1 - self.ns.xc**2