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

        # Set container assignment manually to remove randomness
        n.synapses['container'][ 0:10] = 0
        n.synapses['container'][10:14] = 1
        n.synapses['container'][14:16] = 2

        w = Word([(1,0), (2,0), (6,0)])
        fired, delay, container = n.expose(w)
        assert_false(fired)
        assert_is_none(delay)
        assert_is_none(container)

        w = Word([(1,0), (2,0), (3,0), (4,0), (5,0), (6,0)])
        fired, delay, container = n.expose(w)
        assert_true(fired)
        eq_(delay, 0)
        eq_(container, 0)

        w = Word([(10,0), (11,0), (12,0), (13,0)])
        fired, delay, container = n.expose(w)
        assert_true(fired)
        eq_(delay, 0)
        eq_(container, 1)

        w = Word([(14,0), (15,0)])
        fired, delay, container = n.expose(w)
        assert_false(fired)
        assert_is_none(delay)
        assert_is_none(container)
Пример #2
0
    def test_expose_not_training(self):
        n = Neuron(S0 = 16, H = 4.0, G = 2.0, C = 1, D1 = 1, D2 = 1)

        w = Word([(1,0), (6,0), (9,0)])
        fired, delay, container = n.expose(w)
        assert_false(fired)
        assert_is_none(delay)
        assert_is_none(container)

        w = Word([(1,0), (3,0), (4,0), (5,0), (6,0), (8,0), (9,0), (14,0)])
        fired, delay, container = n.expose(w)
        assert_true(fired)
        eq_(delay, 0)
        eq_(container, 0)
Пример #3
0
    def test_expose_with_delays(self):
        n = Neuron(S0 = 16, H = 2.0, G = 2.0, C = 1, D1 = 2, D2 = 3)

        # Set delay assignment manually to remove randomness
        n.synapses['delay'][ 0:10] = 0
        n.synapses['delay'][10:14] = 1
        n.synapses['delay'][14:16] = 2

        w = Word([(1,0), (2,0), (6,0)])
        fired, delay, container = n.expose(w)
        assert_false(fired)
        assert_is_none(delay)
        assert_is_none(container)

        w = Word([(1,0), (2,0), (3,0), (4,0), (5,0), (6,0)])
        fired, delay, container = n.expose(w)
        assert_true(fired)
        eq_(delay, 0)
        eq_(container, 0)

        w = Word([(1,1), (2,1), (3,1), (4,1), (5,0), (6,0)])
        fired, delay, container = n.expose(w)
        assert_true(fired)
        eq_(delay, 1)
        eq_(container, 0)

        w = Word([(1,0), (2,0), (3,0), (4,1), (5,1), (6,1)])
        fired, delay, container = n.expose(w)
        assert_false(fired)
        assert_is_none(delay)
        assert_is_none(container)

        w = Word([(10,1), (11,1), (12,1), (13,1)])
        fired, delay, container = n.expose(w)
        assert_true(fired)
        eq_(delay, 2)
        eq_(container, 0)

        w = Word([(12,0), (13,0), (14,0), (15,0)])
        fired, delay, container = n.expose(w)
        assert_false(fired)
        assert_is_none(delay)
        assert_is_none(container)
Пример #4
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
Пример #5
0
    def test_train(self):
        n = Neuron(S0 = 16, H = 4.0, G = 2.0, C = 1, D1 = 1, D2 = 1)

        # Train neuron with 2 patterns
        wA = Word([(1,0), (6,0), (9,0), (14,0)])
        wB = Word([(3,0), (4,0), (9,0), (13,0)])

        n.start_training()
        assert_true(n.train(wA))
        assert_true(n.train(wB))
        n.finish_training()

        # 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
Пример #6
0
    def test_train_with_delays(self):
        n = Neuron(S0 = 16, H = 4.0, G = 2.0, C = 1, D1 = 2, D2 = 2)

        # Fix neuron delays manually for the test 
        n.synapses['delay'] = 1
        n.synapses['delay'][1] = 0
        n.synapses['delay'][14] = 0

        # Train neuron with 2 patterns
        wA = Word([(1,1), (6,0), (9,0), (14,1)])
        wB = Word([(3,0), (4,0), (9,0), (13,0)])

        n.start_training()
        assert_true(n.train(wA))
        assert_true(n.train(wB))
        n.finish_training()

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

        wE = Word([(1,1), (3,0), (9,0), (13,0)])
        fired, delay, container = n.expose(wE)
        assert_true(fired) # False alarm

        wF = Word([(1,0), (4,1), (7,0), (9,0), (11,0), (14,0)])
        fired, delay, container = n.expose(wF)
        assert_false(fired)
Пример #7
0
 def test_train_not_training(self):
     n = Neuron()
     w = Word()
     assert_false(n.train(w))
Пример #8
0
 def test_expose_index_error(self):
     n = Neuron(S0 = 16)
     w = Word([(16,0)])
     n.expose(w)