Beispiel #1
0
 def test_first_and_last_id(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(6, sim.IF_cond_exp())
     p3 = sim.Population(3, sim.EIF_cond_exp_isfa_ista())
     a = sim.Assembly(p3, p1, p2)
     self.assertEqual(a.first_id, p1[0])
     self.assertEqual(a.last_id, p3[-1])
Beispiel #2
0
 def test_positions_property(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(11, sim.IF_cond_exp())
     a = sim.Assembly(p1, p2, label="test")
     assert_array_equal(
         a.positions, numpy.concatenate((p1.positions, p2.positions),
                                        axis=1))
 def test___add__two(self):
     # adding two population views should give an Assembly
     pv1 = sim.Population(6, sim.IF_cond_exp())[2, 3, 5]
     pv2 = sim.Population(17, sim.IF_cond_exp())[4, 2, 16]
     assembly = pv1 + pv2
     self.assertIsInstance(assembly, sim.Assembly)
     self.assertEqual(assembly.populations, [pv1, pv2])
Beispiel #4
0
 def test_initialize(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(11, sim.IF_cond_exp())
     a = sim.Assembly(p1, p2)
     v_init = -54.3
     a.initialize(v=v_init)
     assert_array_equal(p2.initial_values['v'].evaluate(simplify=True), v_init)
Beispiel #5
0
 def test__add__population(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(11, sim.IF_cond_exp())
     a1 = sim.Assembly(p1)
     self.assertEqual(a1.populations, [p1])
     a2 = a1 + p2
     self.assertEqual(a1.populations, [p1])
     self.assertEqual(a2.populations, [p1, p2])
Beispiel #6
0
 def test_add_inplace_assembly(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(11, sim.IF_cond_exp())
     p3 = sim.Population(11, sim.IF_cond_exp())
     a1 = sim.Assembly(p1, p2)
     a2 = sim.Assembly(p2, p3)
     a1 += a2
     self.assertEqual(a1.populations, [p1, p2, p3])
Beispiel #7
0
 def test__add__assembly(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(11, sim.IF_cond_exp())
     p3 = sim.Population(11, sim.IF_cond_exp())
     a1 = sim.Assembly(p1, p2)
     a2 = sim.Assembly(p2, p3)
     a3 = a1 + a2
     self.assertEqual(a3.populations, [p1, p2, p3])  # or do we want [p1, p2, p3]?
Beispiel #8
0
 def test_all_iterator(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(6, sim.IF_cond_exp())
     p3 = sim.Population(3, sim.EIF_cond_exp_isfa_ista())
     a = sim.Assembly(p1, p2, p3)
     assert hasattr(a.all(), "next")
     ids = list(a.all())
     self.assertEqual(ids, p1.all_cells.tolist() + p2.all_cells.tolist() + p3.all_cells.tolist())
 def test___add__three(self):
     # adding three population views should give an Assembly
     pv1 = sim.Population(6, sim.IF_cond_exp())[0:3]
     pv2 = sim.Population(17, sim.IF_cond_exp())[1, 5, 14]
     pv3 = sim.Population(9, sim.EIF_cond_exp_isfa_ista())[3:8]
     assembly = pv1 + pv2 + pv3
     self.assertIsInstance(assembly, sim.Assembly)
     self.assertEqual(assembly.populations, [pv1, pv2, pv3])
Beispiel #10
0
 def test_conductance_based(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(6, sim.IF_cond_exp())
     p3 = sim.Population(3, sim.EIF_cond_exp_isfa_ista())
     a1 = sim.Assembly(p1, p2)
     a2 = sim.Assembly(p1, p3)
     self.assertTrue(a1.conductance_based)
     self.assertFalse(a2.conductance_based)
Beispiel #11
0
 def test__homogeneous_synapses(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(6, sim.IF_cond_exp())
     p3 = sim.Population(3, sim.EIF_cond_exp_isfa_ista())
     a1 = sim.Assembly(p1, p2)
     a2 = sim.Assembly(p1, p3)
     self.assertTrue(a1._homogeneous_synapses)
     self.assertFalse(a2._homogeneous_synapses)
Beispiel #12
0
 def test_getitem_int(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(6, sim.IF_cond_exp())
     p3 = sim.Population(3, sim.EIF_cond_exp_isfa_ista())
     a = sim.Assembly(p3, p1, p2)
     self.assertEqual(a[0], p3[0])
     self.assertEqual(a[3], p1[0])
     self.assertEqual(a[14], p2[0])
Beispiel #13
0
 def test_print_v(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(11, sim.IF_cond_exp())
     a = sim.Assembly(p1, p2, label="test")
     a.record_v()
     sim.run(10.0)
     a.write_data = Mock()
     a.print_v("foo.txt")
     a.write_data.assert_called_with('foo.txt', 'v', True)
Beispiel #14
0
 def test_getSpikes(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(11, sim.IF_cond_exp())
     a = sim.Assembly(p1, p2, label="test")
     a.record('spikes')
     sim.run(10.0)
     a.get_data = Mock()
     a.getSpikes()
     a.get_data.assert_called_with('spikes', True)
Beispiel #15
0
 def test_get_population(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p1.label = "pop1"
     p2 = sim.Population(11, sim.IF_cond_exp())
     p2.label = "pop2"
     a = sim.Assembly(p1, p2)
     self.assertEqual(a.get_population("pop1"), p1)
     self.assertEqual(a.get_population("pop2"), p2)
     self.assertRaises(KeyError, a.get_population, "foo")
Beispiel #16
0
 def test_id_to_index(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(6, sim.IF_cond_exp())
     p3 = sim.Population(3, sim.EIF_cond_exp_isfa_ista())
     a = sim.Assembly(p3, p1, p2)
     self.assertEqual(a.id_to_index(p3[0]), 0)
     self.assertEqual(a.id_to_index(p1[0]), 3)
     self.assertEqual(a.id_to_index(p2[0]), 14)
     assert_array_equal(a.id_to_index([p1[0], p2[0], p3[0]]), [3, 14, 0])
Beispiel #17
0
 def test_get_gsyn(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(11, sim.IF_cond_exp())
     a = sim.Assembly(p1, p2, label="test")
     a.record_gsyn()
     sim.run(10.0)
     a.get_data = Mock()
     a.get_gsyn()
     a.get_data.assert_called_with(['gsyn_exc', 'gsyn_inh'], True)
Beispiel #18
0
 def test_printSpikes(self):
     # TODO: implement assert_deprecated
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(11, sim.IF_cond_exp())
     a = sim.Assembly(p1, p2, label="test")
     a.record('spikes')
     sim.run(10.0)
     a.write_data = Mock()
     a.printSpikes("foo.txt")
     a.write_data.assert_called_with('foo.txt', 'spikes', True)
Beispiel #19
0
 def test_local_cells(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(11, sim.IF_cond_exp())
     p3 = sim.Population(11, sim.IF_cond_exp())
     a = sim.Assembly(p1, p2, p3)
     self.assertEqual(a.local_cells.size,
                  p1.local_cells.size + p2.local_cells.size + p3.local_cells.size)
     self.assertEqual(a.local_cells[0], p1.local_cells[0])
     self.assertEqual(a.local_cells[-1], p3.local_cells[-1])
     assert_array_equal(a.local_cells, numpy.append(p1.local_cells, (p2.local_cells, p3.local_cells)))
Beispiel #20
0
 def test_sample(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(6, sim.IF_cond_exp())
     p3 = sim.Population(3, sim.EIF_cond_exp_isfa_ista())
     a = sim.Assembly(p3, p1, p2)
     a1 = a.sample(10, rng=MockRNG())
     # MockRNG.permutation reverses the order
     self.assertEqual(len(a1.populations), 2)
     assert_array_equal(a1.populations[0].all_cells, p1[11:6:-1])
     assert_array_equal(a1.populations[1].all_cells, p2[6::-1])
Beispiel #21
0
 def test_mask_local(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(11, sim.IF_cond_exp())
     p3 = sim.Population(11, sim.IF_cond_exp())
     a = sim.Assembly(p1, p2, p3)
     self.assertEqual(a._mask_local.size,
                  p1._mask_local.size + p2._mask_local.size + p3._mask_local.size)
     self.assertEqual(a._mask_local[0], p1._mask_local[0])
     self.assertEqual(a._mask_local[-1], p3._mask_local[-1])
     assert_array_equal(a._mask_local, numpy.append(p1._mask_local, (p2._mask_local, p3._mask_local)))
     assert_array_equal(a.local_cells, a.all_cells[a._mask_local])
Beispiel #22
0
 def test_getitem_slice(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(6, sim.IF_cond_exp())
     p3 = sim.Population(3, sim.EIF_cond_exp_isfa_ista())
     a = sim.Assembly(p3, p1, p2)
     a1 = a[0:3]
     self.assertIsInstance(a1, sim.Assembly)
     self.assertEqual(len(a1.populations), 1)
     assert_array_equal(a1.populations[0].all_cells, p3[:].all_cells)
     a2 = a[2:8]
     self.assertEqual(len(a2.populations), 2)
     assert_array_equal(a2.populations[0].all_cells, p3[2:].all_cells)
     assert_array_equal(a2.populations[1].all_cells, p1[:5].all_cells)
Beispiel #23
0
 def test_getitem_array(self):
     p1 = sim.Population(11, sim.IF_cond_exp())
     p2 = sim.Population(6, sim.IF_cond_exp())
     p3 = sim.Population(3, sim.EIF_cond_exp_isfa_ista())
     a = sim.Assembly(p3, p1, p2)
     a1 = a[3, 5, 6, 10]
     self.assertIsInstance(a1, sim.Assembly)
     self.assertEqual(len(a1.populations), 1)
     assert_array_equal(a1.populations[0].all_cells, [p1[0], p1[2], p1[3], p1[7]])
     a2 = a[17, 2, 10, 11, 19]
     self.assertEqual(len(a2.populations), 3)
     assert_array_equal(a2.populations[0].all_cells, p3[2:].all_cells)
     assert_array_equal(a2.populations[1].all_cells, p1[7:9].all_cells)
     assert_array_equal(a2.populations[2].all_cells, p2[3, 5].all_cells)
Beispiel #24
0
 def test_save_positions(self):
     import os
     p1 = sim.Population(2, sim.IF_cond_exp())
     p2 = sim.Population(2, sim.IF_cond_exp())
     p1.positions = numpy.arange(0, 6).reshape((2, 3)).T
     p2.positions = numpy.arange(6, 12).reshape((2, 3)).T
     a = sim.Assembly(p1, p2, label="test")
     output_file = Mock()
     a.save_positions(output_file)
     assert_array_equal(
         output_file.write.call_args[0][0],
         numpy.array([[int(p1[0]), 0, 1, 2], [int(p1[1]), 3, 4, 5],
                      [int(p2[0]), 6, 7, 8], [int(p2[1]), 9, 10, 11]]))
     self.assertEqual(output_file.write.call_args[0][1],
                      {'assembly': a.label})
 def test_get_positions(self):
     p = sim.Population(11, sim.IF_cond_exp())
     ppos = numpy.random.uniform(size=(3, 11))
     p._positions = ppos
     pv = sim.PopulationView(parent=p, selector=slice(3, 9, 2))
     assert_array_equal(pv.positions,
                        numpy.array([ppos[:, 3], ppos[:, 5], ppos[:, 7]]).T)
 def test_create_with_boolean_array_selector(self):
     p = sim.Population(11, sim.IF_cond_exp())
     mask = numpy.array([0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0], dtype=bool)
     pv = sim.PopulationView(parent=p, selector=mask)
     assert_array_equal(
         pv.all_cells,
         numpy.array([p.all_cells[3], p.all_cells[5], p.all_cells[7]]))
 def test_set_invalid_type(self):
     p = sim.Population(9, sim.IF_cond_exp())
     pv = p[::3]
     self.assertRaises(errors.InvalidParameterValueError, pv.set, tau_m={})
     self.assertRaises(errors.InvalidParameterValueError,
                       pv.set,
                       v_reset='bar')
Beispiel #28
0
 def test_set_structure(self):
     p = sim.Population(11, sim.IF_cond_exp(), structure=space.Grid2D())
     pv = p[2, 5, 7, 8]
     new_struct = space.Line()
     def set_struct(struct):
         pv.structure = struct
     self.assertRaises(AttributeError, set_struct, new_struct)
    def test_sample(self):
        p = sim.Population(13, sim.IF_cond_exp())
        pv1 = p[0, 3, 7, 10, 12]

        rng = Mock()
        rng.permutation = Mock(return_value=numpy.array([3, 1, 0, 2, 4]))
        pv2 = pv1.sample(3, rng=rng)
        assert_array_equal(pv2.all_cells, p.all_cells[[10, 3, 0]])
 def test_nearest(self):
     p = sim.Population(13, sim.IF_cond_exp())
     p.positions = numpy.arange(39).reshape((13, 3)).T
     pv = p[0, 2, 5, 11]
     self.assertEqual(pv.nearest((0.0, 1.0, 2.0)), pv[0])
     self.assertEqual(pv.nearest((3.0, 4.0, 5.0)), pv[0])
     self.assertEqual(pv.nearest((36.0, 37.0, 38.0)), pv[3])
     self.assertEqual(pv.nearest((1.49, 2.49, 3.49)), pv[0])
     self.assertEqual(pv.nearest((1.51, 2.51, 3.51)), pv[0])