def gateOneToOne(self, sourceLayer, destLayer, gateLayer):
     """
     Gates a set of connections in a one-to-one fashion.
     |sourceLayer|, |destLayer|, and |gateLayer| must be of the same length.
     Each neuron in the |gateLayer| will gate the corresponding connections
         between source and destination neurons.
     
     d1  d2  d3  ... dn
     |   |   |   ... |
     g1  g2  g3  ... gn
     |   |   |   ... |
     s1  s2  s3  ... sn
     """
     if not (len(sourceLayer) == len(destLayer) == len(gateLayer)):
         raise ValueError("Cannot gate one-to-one layers of \
                             different lengths!")
     for (src,dest),gate in zip(zip(sourceLayer, destLayer), gateLayer):
         connection = \
             [c for c in dest.inputConnections if c.inputNeuron == src][0]
         gateConnection(connection, gate)
    def gateOutgoingConnections(self, layer, gateLayer, recurrent=False):
        """
        Gates a layer by its outgoing connections.
        |layer| and |gateLayer| must be the same length, or the gate layer
            must have only one neuron.  In the former case, each source
            node will have its outgoing connections gated by the corresponding
            gate node in the |gateLayer|.  In the latter case, that gate neuron
            will be used for all neurons in the target layer.
        If |recurrent|, the recurrent outgoing connections will be gated.
        """
        if len(layer) != len(gateLayer):
            raise ValueError("Cannot gate layers by incoming connection when \
                the gate layer and target layer are of different lengths!")
        elif len(gateLayer) == 1:
            gate = gateLayer[0]
            gateLayer = [gate for _ in xrange(len(layer))]

        for source,gate in zip(layer, gateLayer):
            if recurrent:
                connections = source.recurrentProjectedConnections
            else:
                connections = source.projectedConnections
            for connection in connections:
                gateConnection(connection, gate)