def test_simple(self):
        # One connection.
        state = functions.calculateState([self.c1], None)
        self.assertAlmostEqual(4.5, state)

        # Two connections.
        state = functions.calculateState([self.c1, self.c2], None)
        self.assertAlmostEqual(12.5, state)
Ejemplo n.º 2
0
    def feedForward(self, source):
        """
        Performs Feed Forward activation of this neuron.
        |source| is the source neuron.

        This method will collect the inputs from all of this neuron's input
        neurons and input gate neurons before performing its own feedforward
        computation to all of its output neurons.
        """
        # Check off source.
        try: self.inputSet.remove(source)
        except KeyError: pass

        # Only continue if we have been notified by all input neurons.
        if len(self.inputSet) == 0:
            # Reset input set.
            self.resetInputSet()

            # Calculate state
            self.state = calculateState(
                self.getAllInputConnections(), self.recurrenceConnection)

            # Calculate output
            self.output = self.activationFunction.activate(self)

            # Calculate the derivative of the output with respect to the state.
            self.derivative = self.activationFunction.differentiate(self)

            # Feed forward to output and gated neurons.
            for neuron in self.outputSet: neuron.feedForward(self)
    def test_recurrence(self):
        # Zero connections plus recurrence.
        state = functions.calculateState([], self.r1)
        self.assertAlmostEqual(15, state)

        # One ungated plus recurrence.
        state = functions.calculateState([self.c1], self.r1)
        self.assertAlmostEqual(19.5, state)

        # Two ungated plus recurrence.
        state = functions.calculateState([self.c1, self.c2], self.r1)
        self.assertAlmostEqual(27.5, state)

        # One ungated, one gated, plus recurrence.
        state = functions.calculateState([self.c1, self.g1], self.r1)
        self.assertAlmostEqual(28.5, state)
    def test_gated(self):
        # One gated connection.
        state = functions.calculateState([self.g1], None)
        self.assertAlmostEqual(9.0, state)

        # Two gated connection.
        state = functions.calculateState([self.g1, self.g2], None)
        self.assertAlmostEqual(33.0, state)

        # One ungated and one gated.
        state = functions.calculateState([self.g1, self.c1], None)
        self.assertAlmostEqual(13.5, state)

        # Two ungated and two gated.
        state = functions.calculateState([self.c1, self.c2, self.g1, self.g2], None)
        self.assertAlmostEqual(45.5, state)