import nengo
from nengo.tests.helpers import SimulatorTestCase, unittest


class TestBasalGanglia(SimulatorTestCase):
    def test_basic(self):
        model = nengo.Model('test_basalganglia_basic')

        with model:
            bg = nengo.networks.BasalGanglia(dimensions=5, label='BG')
            input = nengo.Node([0.8, 0.4, 0.4, 0.4, 0.4], label='input')
            nengo.Connection(input, bg.input)
            p = nengo.Probe(bg.output, 'output')

        sim = self.Simulator(model)
        sim.run(0.2)

        output = np.mean(sim.data(p)[50:], axis=0)

        self.assertGreater(output[0], -0.15)
        self.assertLess(output[1], -0.8)
        self.assertLess(output[2], -0.8)
        self.assertLess(output[3], -0.8)
        self.assertLess(output[4], -0.8)


if __name__ == "__main__":
    nengo.log(debug=True, path='log.txt')
    unittest.main()
Esempio n. 2
0
        ens_attrs = ('encoders', 'max_rates', 'intercepts')
        A = [mi.get('A') for mi in [m1, m2, m3]]
        B = [mi.get('B') for mi in [m1, m2, m3]]
        compare_objs(A[0], A[1], ens_attrs)
        compare_objs(B[0], B[1], ens_attrs)
        compare_objs(A[0], A[2], ens_attrs, equal=False)
        compare_objs(B[0], B[2], ens_attrs, equal=False)

        neur_attrs = ('gain', 'bias')
        compare_objs(A[0].neurons, A[1].neurons, neur_attrs)
        compare_objs(B[0].neurons, B[1].neurons, neur_attrs)
        compare_objs(A[0].neurons, A[2].neurons, neur_attrs, equal=False)
        compare_objs(B[0].neurons, B[2].neurons, neur_attrs, equal=False)


class TestModel(SimulatorTestCase):
    def test_counters(self):
        m = nengo.Model('test_counters', seed=123)
        m.probe(m.steps)
        sim = m.simulator(dt=0.001, sim_class=self.Simulator)
        sim.run(0.003)
        self.assertTrue(
            np.allclose(sim.data(m.t).flatten(), [0.00, .001, .002]))
        self.assertTrue(np.allclose(sim.data(m.steps).flatten(), [0, 1, 2]))


if __name__ == "__main__":
    nengo.log_to_file('log.txt', debug=True)
    unittest.main()