Ejemplo n.º 1
0
    def testCorrectForwardWeightsUpdateNonVec(self):
        testRandom = TestConstRandom(1)
        testMLP = MultiLayerPerceptronNetwork(testRandom, [3, 3, 3],
                                              learningRate=0.5,
                                              momentum=0)

        outputVectors = MagicMock(spec=list)

        with patch(
                'mlpBp.mlp.MultiLayerPerceptronNetwork._calcDerivErrorWeightNonVec',
                lambda _, __: 1):
            testMLP._forwardWeightsUpdateNonVec(outputVectors)
            for layerId in range(len(testMLP.networkWeights)):
                self.assertTrue(
                    np.alltrue(testMLP.networkWeights[layerId] == 0.5))
                self.assertTrue(
                    np.alltrue(testMLP.tMinus1NetworkWeights[layerId] == 1))
Ejemplo n.º 2
0
    def testForwardWeightUpdateNonVecEqualsVecVersion(self, out1, out2, out3,
                                                      delta1, delta2):
        testRandom = TestSeqRandom()
        testVecMLP = MultiLayerPerceptronNetwork(testRandom, [3, 4, 3], 0.5,
                                                 0.6)
        testNonVecMLP = MultiLayerPerceptronNetwork(testRandom, [3, 4, 3], 0.5,
                                                    0.6)

        prevWeights = copy.deepcopy(testVecMLP.networkWeights)
        testVecMLP.networkDeltas = [delta1, delta2]
        testNonVecMLP.networkDeltas = [delta1, delta2]
        outputVectors = [out1, out2, out3]

        testNonVecMLP._forwardWeightsUpdateNonVec(outputVectors)
        testVecMLP._forwardWeightsUpdateVec(outputVectors)

        for i in range(len(testVecMLP.networkWeights)):
            assert_array_equal(testVecMLP.networkWeights[i],
                               testNonVecMLP.networkWeights[i])
            assert_raises(AssertionError, assert_array_equal,
                          testVecMLP.networkWeights[i], prevWeights[i])