Пример #1
0
    def test_test(self):
        n = Neuron(S0 = 16, H = 4.0, G = 2.0, C = 1, D1 = 1, D2 = 1)

        wA = Word([(1,0), (6,0), (9,0), (14,0)])
        wB = Word([(3,0), (4,0), (9,0), (13,0)])
        train_wordset = WordSet(num_words = 2, word_length = 16,
                                num_delays = 1, num_active = 4)
        train_wordset.words = [wA, wB]

        alice = Alice()
        alice.train(n, train_wordset)

        wD = Word([(2,0), (6,0), (12,0), (14,0)])
        wE = Word([(3,0), (7,0), (9,0), (13,0)])
        wF = Word([(1,0), (4,0), (9,0), (14,0)]) # False alarm
        test_wordset = WordSet(num_words = 3, word_length = 16,
                               num_delays = 1, num_active = 4)
        test_wordset.words = [wD, wE, wF]

        bob = Bob()
        bob.test(n, train_wordset, test_wordset)

        eq_(bob.true_true, 2)
        eq_(bob.true_false, 0)
        eq_(bob.false_true, 1)
        eq_(bob.false_false, 2)
Пример #2
0
    def test_train(self):
        n = Neuron(S0 = 16, H = 4.0, G = 2.0, C = 1, D1 = 1, D2 = 1)

        wA = Word([(1,0), (6,0), (9,0), (14,0)])
        wB = Word([(3,0), (4,0), (9,0), (13,0)])
        wordset = WordSet(num_words = 2, word_length = 16, num_delays = 1,
                          num_active = 4)
        wordset.words = [wA, wB]

        alice = Alice()
        alice.train(n, wordset)

        # Test recognition
        wD = Word([(2,0), (6,0), (12,0), (14,0)])
        fired, delay, container = n.expose(wD)
        assert_false(fired)

        wE = Word([(3,0), (7,0), (9,0), (13,0)])
        fired, delay, container = n.expose(wE)
        assert_false(fired)

        wF = Word([(1,0), (4,0), (9,0), (14,0)])
        fired, delay, container = n.expose(wF)
        assert_true(fired) # False alarm