예제 #1
0
 def test_leabra_init_input_output(self):
     L = LeabraMechanism(input_size=3, output_size=3, name='L1')
     val = L.execute([[0, 0, 0], [0, 0, 0]])
     assert L.input_size == 3
     assert L.output_size == 3
     assert L.name == 'L1'
     assert np.sum(np.abs(val)) <= 0.001
예제 #2
0
 def test_leabra_init_empty(self):
     L = LeabraMechanism()
     val = L.execute([[10], [0]])
     assert len(val) == 1 and len(val[0]) == 1
     assert "LeabraMechanism" in L.name
     assert L.input_size == 1
     assert L.output_size == 1
     assert val[0][0] > 0.9
예제 #3
0
 def test_leabra_init_no_hidden_sizes(self):
     L = LeabraMechanism(input_size=4,
                         output_size=4,
                         hidden_layers=2,
                         training_flag=False)
     val = L.execute([[1, 2, 3, 4], [0, 0, 0, 0]])
     assert L.hidden_layers == 2
     assert L.hidden_sizes == 4
     assert len(val[0]) == 4
예제 #4
0
    def test_leabra_runtime_alone(self):
        n_input = 4
        n_output = 3
        n_hidden = 2
        hidden_sizes = None
        inputs = [[.1, .2, .3, .4], [.4, .5, .6, .7], [-.6, -.7, -.8, -.9]]
        train_input = [1, 0, -1]
        random.seed(10)
        L1 = LeabraMechanism(input_size=n_input,
                             output_size=n_output,
                             hidden_layers=n_hidden,
                             hidden_sizes=None,
                             training_flag=False)  # training flag is false
        random.seed(10)
        L2 = LeabraMechanism(input_size=n_input,
                             output_size=n_output,
                             hidden_layers=n_hidden,
                             hidden_sizes=None,
                             training_flag=True)  # training flag is true
        random.seed(10)
        net = build_leabra_network(n_input, n_output, n_hidden, hidden_sizes,
                                   False)

        pnl_output1_1 = L1.execute(input=[inputs[0], train_input],
                                   runtime_params={"training_flag": False})
        pnl_output2_1 = L2.execute(input=[inputs[0], train_input],
                                   runtime_params={"training_flag": False})
        net_output_1 = run_leabra_network(net, input_pattern=inputs[0])
        np.testing.assert_allclose(pnl_output1_1[0], net_output_1, atol=1e-08)
        np.testing.assert_allclose(pnl_output2_1[0], net_output_1, atol=1e-08)

        pnl_output1_2 = L1.execute(input=[inputs[1], train_input],
                                   runtime_params={"training_flag": True})
        pnl_output2_2 = L2.execute(input=[inputs[1], train_input],
                                   runtime_params={"training_flag": True})
        net_output_2 = train_leabra_network(net,
                                            input_pattern=inputs[1],
                                            output_pattern=train_input)
        np.testing.assert_allclose(pnl_output1_2[0], net_output_2, atol=1e-08)
        np.testing.assert_allclose(pnl_output2_2[0], net_output_2, atol=1e-08)

        pnl_output1_3 = L1.execute(input=[inputs[2], train_input],
                                   runtime_params={"training_flag": False})
        pnl_output2_3 = L2.execute(input=[inputs[2], train_input],
                                   runtime_params={"training_flag": False})
        net_output_3 = run_leabra_network(net, input_pattern=inputs[2])
        np.testing.assert_allclose(pnl_output1_3[0], net_output_3, atol=1e-08)
        np.testing.assert_allclose(pnl_output2_3[0], net_output_3, atol=1e-08)