Example #1
0
    def __init__(self,
                 size,
                 initialHistory=gpu.zeros((0, 0)),
                 baseLayerClass=SigmoidLayer,
                 connectionClass=FullConnection):
        """
      A recurrent layer extends the activation layer by adding a full recurrent
      connection from the output of the layer to its input, delayed by a 
      timestep.
      """

        # Properly inherit the AbstractLayer
        AbstractLayer.__init__(self)

        # Extract the layerSize from the provided activation layer
        self.baseLayer = baseLayerClass(size)
        self.layerSize = size
        self.historyLayer = HistoryLayer(self.layerSize, initialHistory)

        # A recurrent layer has an input port, history port and output port
        self.input = self.baseLayer.input
        self.output = self.baseLayer.output

        # Make two connections - the recurrent connection to the history and a connection from
        # the history to the activationLayer
        self.recurrentConnection = connectionClass(self.output,
                                                   self.historyLayer.input)
        self.historyConnection = IdentityConnection(self.historyLayer.output,
                                                    self.input)

        # Keep track of how many timesteps there were, and the initial history incase of reset
        self.timestep = 0