Esempio n. 1
0

class TestModel(SimulatorTestCase):

    def test_counters(self):
        params = dict(simulator=self.Simulator, seed=123, dt=0.001)

        # Old API
        net = nef.Network('test_counters', **params)
        simtime_probe = net._raw_probe(net.model.simtime, dt_sample=.001)
        steps_probe = net._raw_probe(net.model.steps, dt_sample=.001)
        net.run(0.003)
        simtime_data = simtime_probe.get_data()
        steps_data = steps_probe.get_data()
        self.assertTrue(np.allclose(simtime_data.flatten(), [.001, .002, .003]))
        self.assertTrue(np.allclose(steps_data.flatten(), [1, 2, 3]))

        # New API
        m = nengo.Model('test_counters', **params)
        m.probe(m.simtime)
        m.probe(m.steps)
        m.run(0.003)
        self.assertTrue(np.allclose(m.data[m.simtime].flatten(),
                                    [.001, .002, .003]))
        self.assertTrue(np.allclose(m.data[m.steps].flatten(), [1, 2, 3]))


if __name__ == "__main__":
    nengo.log_to_file('log.txt', debug=True)
    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()
class TestBasalGanglia(SimulatorTestCase):
    def test_basic(self):

        model = nengo.Model("test_basalganglia_basic")

        model.add(BasalGanglia("BG", dimensions=5))

        model.make_node("input", [0.8, 0.4, 0.4, 0.4, 0.4])

        model.connect("input", "BG.input")

        model.probe("BG.output")

        sim = model.simulator(sim_class=self.Simulator)

        sim.run(0.2)

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

        self.assertGreater(output[0], -0.1)
        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_to_file("log.txt", debug=True)
    unittest.main()