Exemplo n.º 1
0
class TestNnLayer(TestCase):
    def setUp(self):
        self.hiddenL = NnLayer(sigmoid, 3, 1, 3)
        self.hiddenL[:-1] = array((0.1, 0.2, 0.3))
        self.hiddenL.updateForwardWeight(matrix(((0.4, 0.5, 0.6, 0.7), (0.8, 0.9, 1, 1.1), (1.2, 1.3, 1.4, 1.5))))

    def test_recvAndActvByOneInput(self):
        result = self.hiddenL.recvAndActvByOneInput(array((1, 1, 1)))
        self.assertAlmostEqual(result[0], 1.0 / (1 + npe ** (-npsum(array((0.4, 0.5, 0.6, 0.7)) * array((1, 1, 1, 1))))))
        self.assertAlmostEqual(result[1], 1.0 / (1 + npe ** (-npsum(array((0.8, 0.9 , 1, 1.1)) * array((1, 1, 1, 1))))))
        self.assertAlmostEqual(result[2], 1.0 / (1 + npe ** (-npsum(array((1.2, 1.3, 1.4, 1.5)) * array((1, 1, 1, 1))))))
        self.assertTrue(npall(self.hiddenL == array((1, 1, 1, 1))))

    def test_actvByAllInput(self):
        inputArr2D = array(((0.41, 0.51, 0.61), (0.73, 0.63, 0.53)))
        result = asarray(self.hiddenL.actvByAllInput(inputArr2D))
        assert_array_almost_equal(result[0], ravel(sigmoid(array((0.41, 0.51, 0.61, 1)) * matrix(((0.4, 0.5, 0.6, 0.7), (0.8, 0.9, 1, 1.1), (1.2, 1.3, 1.4, 1.5))).T)))
        assert_array_almost_equal(result[1], ravel(sigmoid(array((0.73, 0.63, 0.53, 1)) * matrix(((0.4, 0.5, 0.6, 0.7), (0.8, 0.9, 1, 1.1), (1.2, 1.3, 1.4, 1.5))).T)))
Exemplo n.º 2
0
 def setUp(self):
     self.hiddenL = NnLayer(sigmoid, 3, 1, 3)
     self.hiddenL[:-1] = array((0.1, 0.2, 0.3))
     self.hiddenL.updateForwardWeight(matrix(((0.4, 0.5, 0.6, 0.7), (0.8, 0.9, 1, 1.1), (1.2, 1.3, 1.4, 1.5))))