Пример #1
0
 def testRandomizeDelays(self):
     # The probability of having two consecutive delays vector that are equal should be 0
     prj1 = neuron.Projection(self.source, self.target,
                              neuron.AllToAllConnector())
     prj2 = neuron.Projection(self.source, self.target,
                              neuron.AllToAllConnector())
     prj1.randomizeDelays(self.distrib_Numpy)
     prj2.randomizeDelays(self.distrib_Native)
     d1 = []
     d2 = []
     d3 = []
     d4 = []
     hoc_list1 = getattr(h, prj1.hoc_label)
     hoc_list2 = getattr(h, prj2.hoc_label)
     for connection_id in prj1.connections:
         #d1.append(HocToPy.get('%s.object(%d).delay' % (prj1.hoc_label, prj1.connections.index(connection_id))))
         #d2.append(HocToPy.get('%s.object(%d).delay' % (prj2.hoc_label, prj1.connections.index(connection_id))))
         d1.append(
             hoc_list1.object(prj1.connections.index(connection_id)).delay)
         d2.append(
             hoc_list2.object(prj2.connections.index(connection_id)).delay)
     prj1.randomizeDelays(self.distrib_Numpy)
     prj2.randomizeDelays(self.distrib_Native)
     for connection_id in prj1.connections:
         #d3.append(HocToPy.get('%s.object(%d).delay' % (prj1.hoc_label, prj1.connections.index(connection_id))))
         #d4.append(HocToPy.get('%s.object(%d).delay' % (prj2.hoc_label, prj1.connections.index(connection_id))))
         d3.append(
             hoc_list1.object(prj1.connections.index(connection_id)).delay)
         d4.append(
             hoc_list2.object(prj2.connections.index(connection_id)).delay)
     self.assertNotEqual(d1, d3) and self.assertNotEqual(d2, d4)
Пример #2
0
 def testRandomizeWeights(self):
     # The probability of having two consecutive weights vector that are equal should be 0
     prj1 = neuron.Projection(self.source, self.target,
                              neuron.AllToAllConnector())
     prj2 = neuron.Projection(self.source, self.target,
                              neuron.AllToAllConnector())
     prj1.randomizeWeights(self.distrib_Numpy)
     prj2.randomizeWeights(self.distrib_Native)
     w1 = []
     w2 = []
     w3 = []
     w4 = []
     hoc_list1 = getattr(h, prj1.hoc_label)
     hoc_list2 = getattr(h, prj2.hoc_label)
     for connection_id in prj1.connections:
         #w1.append(HocToPy.get('%s.object(%d).weight' % (prj1.hoc_label, prj1.connections.index(connection_id))))
         #w2.append(HocToPy.get('%s.object(%d).weight' % (prj2.hoc_label, prj1.connections.index(connection_id))))
         w1.append(
             hoc_list1.object(
                 prj1.connections.index(connection_id)).weight[0])
         w2.append(
             hoc_list2.object(
                 prj2.connections.index(connection_id)).weight[0])
     prj1.randomizeWeights(self.distrib_Numpy)
     prj2.randomizeWeights(self.distrib_Native)
     for connection_id in prj1.connections:
         #w3.append(HocToPy.get('%s.object(%d).weight' % (prj1.hoc_label, prj1.connections.index(connection_id))))
         #w4.append(HocToPy.get('%s.object(%d).weight' % (prj2.hoc_label, prj1.connections.index(connection_id))))
         w3.append(
             hoc_list1.object(
                 prj1.connections.index(connection_id)).weight[0])
         w4.append(
             hoc_list2.object(
                 prj2.connections.index(connection_id)).weight[0])
     self.assertNotEqual(w1, w3) and self.assertNotEqual(w2, w4)
Пример #3
0
 def testFixedNumberPost(self):
     c1 = neuron.FixedNumberPostConnector(10)
     c2 = neuron.FixedNumberPostConnector(3)
     c3 = neuron.FixedNumberPostConnector(
         random.RandomDistribution('poisson', [5]))
     for srcP in [self.source5, self.source22]:
         for tgtP in [self.target6, self.target33]:
             for c in c1, c2:
                 prj1 = neuron.Projection(srcP, tgtP, c)
                 self.assertEqual(len(prj1.connections), c.n * len(srcP))
             prj2 = neuron.Projection(
                 srcP, tgtP,
                 c3)  # just a test that no Exceptions are raised
Пример #4
0
 def testFixedProbability(self):
     """For all connections created with "fixedProbability"..."""
     for srcP in [self.source5, self.source22]:
         for tgtP in [self.target6, self.target33]:
             prj2 = neuron.Projection(srcP,
                                      tgtP,
                                      FixedProbabilityConnector(0.5),
                                      rng=NativeRNG(12345))
             prj3 = neuron.Projection(srcP,
                                      tgtP,
                                      FixedProbabilityConnector(0.5),
                                      rng=NumpyRNG(12345))
             assert (0 < len(prj2) < len(srcP)*len(tgtP)) \
                    and (0 < len(prj3) < len(srcP)*len(tgtP))
Пример #5
0
 def testRandomizeDelaysWithSTDP(self):
     stdp_model = neuron.STDPMechanism(
         timing_dependence=neuron.SpikePairRule(tau_plus=20.0,
                                                tau_minus=20.0),
         weight_dependence=neuron.AdditiveWeightDependence(w_min=0,
                                                           w_max=2.0,
                                                           A_plus=0.1,
                                                           A_minus=0.0),
         dendritic_delay_fraction=0.0)
     connector = neuron.AllToAllConnector(weights=1.0, delays=2.0)
     prj1 = neuron.Projection(
         self.source,
         self.target,
         connector,
         synapse_dynamics=neuron.SynapseDynamics(slow=stdp_model))
     pre2wa = getattr(h, '%s_pre2wa' % prj1.hoc_label)
     post2wa = getattr(h, '%s_post2wa' % prj1.hoc_label)
     nc_list = getattr(h, prj1.hoc_label)
     assert pre2wa[0].delay == 2.0
     assert post2wa[0].delay == 0.0
     prj1.randomizeDelays(self.distrib_Native)
     assert pre2wa[
         0].delay != 2.0  # check it is equal to the actual synaptic delay
     assert post2wa[0].delay == 0.0
     delay0 = nc_list.object(0).delay
     assert pre2wa[0].delay == delay0
     prj1.randomizeDelays(self.distrib_Numpy)
     assert pre2wa[
         0].delay != delay0  # check it is equal to the actual synaptic delay
     assert post2wa[0].delay == 0.0
     assert pre2wa[0].delay == nc_list.object(0).delay
Пример #6
0
 def testSettingDelays(self):
     """Delays should be set correctly when using a Connector object."""
     for srcP in [self.source5, self.source22]:
         for tgtP in [self.target6, self.target33]:
             prj1 = neuron.Projection(
                 srcP, tgtP, neuron.AllToAllConnector(delays=0.321))
             hoc_list = getattr(neuron.h, prj1.hoc_label)
             assert hoc_list.object(
                 0
             ).delay == 0.321, "Delay should be 0.321, actually %g" % hoc_list.object(
                 0).delay
Пример #7
0
 def testAllToAll(self):
     """For all connections created with "allToAll" it should be possible to
     obtain the weight using the top-level HocObject"""
     for srcP in [self.source5, self.source22]:
         for tgtP in [self.target6, self.target33]:
             prj1 = neuron.Projection(srcP, tgtP,
                                      neuron.AllToAllConnector())
             prj2 = neuron.Projection(srcP, tgtP,
                                      neuron.AllToAllConnector())
             prj1.setWeights(1.234)
             prj2.setWeights(1.234)
             for prj in prj1, prj2:
                 hoc_list = getattr(h, prj.hoc_label)
                 weights = []
                 for connection_id in prj.connections:
                     weights.append(
                         hoc_list.object(
                             prj.connections.index(
                                 connection_id)).weight[0])
                 assert weights == [1.234] * len(prj)
Пример #8
0
 def testSaveAndLoad(self):
     prj1 = neuron.Projection(self.source33, self.target33,
                              neuron.OneToOneConnector())
     prj1.setDelays(1)
     prj1.setWeights(1.234)
     prj1.saveConnections("connections.tmp", gather=False)
     #prj2 = neuron.Projection(self.source33, self.target33, 'fromFile',"connections.tmp")
     if neuron.num_processes() > 1:
         distributed = True
     else:
         distributed = False
     prj3 = neuron.Projection(
         self.source33, self.target33,
         neuron.FromFileConnector("connections.tmp",
                                  distributed=distributed))
     w1 = []
     w2 = []
     w3 = []
     d1 = []
     d2 = []
     d3 = []
     # For a connections scheme saved and reloaded, we test if the connections, their weights and their delays
     # are equal.
     hoc_list1 = getattr(h, prj1.hoc_label)
     #hoc_list2 = getattr(h, prj2.hoc_label)
     hoc_list3 = getattr(h, prj3.hoc_label)
     for connection_id in prj1.connections:
         w1.append(
             hoc_list1.object(
                 prj1.connections.index(connection_id)).weight[0])
         #w2.append(hoc_list2.object(prj2.connections.index(connection_id)).weight[0])
         w3.append(
             hoc_list3.object(
                 prj3.connections.index(connection_id)).weight[0])
         d1.append(
             hoc_list1.object(prj1.connections.index(connection_id)).delay)
         #d2.append(hoc_list2.object(prj2.connections.index(connection_id)).delay)
         d3.append(
             hoc_list3.object(prj3.connections.index(connection_id)).delay)
     #assert (w1 == w2 == w3) and (d1 == d2 == d3)
     assert (w1 == w3) and (d1 == d3)
Пример #9
0
 def testSetDelays(self):
     prj1 = neuron.Projection(self.source, self.target,
                              neuron.AllToAllConnector())
     prj1.setDelays(2.345)
     delays = []
     hoc_list = getattr(h, prj1.hoc_label)
     for connection_id in prj1.connections:
         #delays.append(HocToPy.get('%s.object(%d).delay' % (prj1.hoc_label, prj1.connections.index(connection_id))))
         delays.append(
             hoc_list.object(prj1.connections.index(connection_id)).delay)
     result = 2.345 * numpy.ones(len(prj1.connections))
     assert (delays == result.tolist())
Пример #10
0
 def testDistanceDependentProbability(self):
     """For all connections created with "distanceDependentProbability"..."""
     # Test should be improved..."
     for rngclass in (NumpyRNG, NativeRNG):
         for expr in ('exp(-d)', 'd < 0.5'):
             prj = neuron.Projection(
                 self.source33,
                 self.target33,
                 neuron.DistanceDependentProbabilityConnector(
                     d_expression=expr),
                 rng=rngclass(12345))
             assert (0 < len(prj) < len(self.source33) * len(self.target33))
Пример #11
0
 def testSetTopographicDelay(self):
     # We fix arbitrarily the positions of 2 cells in 2 populations and check
     # the topographical delay between them is linked to the distance
     self.source[0, 0].position = (0, 0, 0)
     self.target[2, 2].position = (0, 10, 0)
     prj1 = neuron.Projection(self.source, self.target,
                              neuron.AllToAllConnector())
     rule = "5.432*d"
     prj1.setTopographicDelays(rule)
     hoc_list = getattr(h, prj1.hoc_label)
     for connection_id in range(len(prj1.connections)):
         src = prj1.connections[connection_id][0]
         tgt = prj1.connections[connection_id][1]
         if (src == self.source[0, 0]) and (tgt == self.target[2, 2]):
             delay = hoc_list.object(
                 prj1.connections.index(
                     prj1.connections[connection_id])).delay
             assert (delay == 54.32), delay
Пример #12
0
 def testSTDP(self):
     self.target.record()
     self.source.record()
     self.target.record_v()
     stdp_model = neuron.STDPMechanism(
         timing_dependence=neuron.SpikePairRule(tau_plus=20.0,
                                                tau_minus=20.0),
         weight_dependence=neuron.AdditiveWeightDependence(w_min=0,
                                                           w_max=2.0,
                                                           A_plus=0.1,
                                                           A_minus=0.0),
         dendritic_delay_fraction=0.0)
     connector = neuron.AllToAllConnector(weights=1.0, delays=2.0)
     prj1 = neuron.Projection(
         self.source,
         self.target,
         connector,
         synapse_dynamics=neuron.SynapseDynamics(slow=stdp_model))
     #prj1.setDelays(2)
     #prj1.setWeights(1.0)
     mean_weight_before = 0
     hoc_list = getattr(h, prj1.hoc_label)
     for connection_id in prj1.connections:
         mean_weight_before += hoc_list.object(
             prj1.connections.index(connection_id)).weight[0]
     mean_weight_before = float(mean_weight_before / len(prj1.connections))
     simtime = 100
     neuron.running = False
     run(simtime)
     mean_weight_after = 0
     self.target.print_v("tmp.v")
     source_spikes = self.source.meanSpikeCount()
     target_spikes = self.target.meanSpikeCount()
     if neuron.myid == 0:
         assert source_spikes > 0
         assert target_spikes > 0
     for connection_id in prj1.connections:
         mean_weight_after += hoc_list.object(
             prj1.connections.index(connection_id)).weight[0]
     mean_weight_after = float(mean_weight_after / len(prj1.connections))
     assert (mean_weight_before < mean_weight_after
             ), "%g !< %g" % (mean_weight_before, mean_weight_after)
Пример #13
0
 def testSetDelaysWithSTDP(self):
     stdp_model = neuron.STDPMechanism(
         timing_dependence=neuron.SpikePairRule(tau_plus=20.0,
                                                tau_minus=20.0),
         weight_dependence=neuron.AdditiveWeightDependence(w_min=0,
                                                           w_max=2.0,
                                                           A_plus=0.1,
                                                           A_minus=0.0),
         dendritic_delay_fraction=0.0)
     connector = neuron.AllToAllConnector(weights=1.0, delays=2.0)
     prj1 = neuron.Projection(
         self.source,
         self.target,
         connector,
         synapse_dynamics=neuron.SynapseDynamics(slow=stdp_model))
     pre2wa = getattr(h, '%s_pre2wa' % prj1.hoc_label)
     post2wa = getattr(h, '%s_post2wa' % prj1.hoc_label)
     assert pre2wa[0].delay == 2.0
     assert post2wa[0].delay == 0.0
     prj1.setDelays(3.0)
     assert pre2wa[0].delay == 3.0
     assert post2wa[0].delay == 0.0
Пример #14
0
 def testOneToOne(self):
     """For all connections created with "OneToOne" ..."""
     prj = neuron.Projection(self.source33, self.target33,
                             neuron.OneToOneConnector())
     assert len(prj.connections) == len(
         self.target33.gidlist), prj.connections