def test_gate_error(self):
        gatedConnections = dict()

        # One target neuron.
        gatedConnections[self.targetNeuron] = [self.g1]
        error = functions.calculateGateError(self.derivative, gatedConnections)
        self.assertAlmostEqual(67.5, error)

        # Two target neuron.
        # Second neuron has multiple connections.
        gatedConnections[self.targetNeuron2] = [self.g2, self.g3]
        error = functions.calculateGateError(self.derivative, gatedConnections)
        self.assertAlmostEqual(67.5 + 80 + 240, error)
예제 #2
0
    def backpropagate(self, source):
        """
        Performs the backpropagation of error through this neuron.

        This method will collect all of the errors from its output neurons
        and gated neurons before calculating performing weight adjustments.
        """
        # Check off source.
        try: self.outputSet.remove(source)
        except KeyError: pass

        # Only continue if we have been notified by all output neurons.
        if len(self.outputSet) == 0:
            # Reset output set.
            self.resetOutputSet()

            ## Projected error.
            self.projectedError = \
                calculateProjectedError(self.derivative, self.projectedConnections)

            ## Gate error.
            gateError = calculateGateError(self.derivative, self.gatedConnections)

            # Calculate total error.
            self.error = gateError + self.projectedError

            # Backpropagate.
            for neuron in self.inputSet: neuron.backpropagate(self)