def testRSetNumpy(self): """Population.rset(): with numpy rng.""" rd1 = random.RandomDistribution(rng=random.NumpyRNG(seed=98765), distribution='uniform', parameters=[0.9, 1.1]) rd2 = random.RandomDistribution(rng=random.NumpyRNG(seed=98765), distribution='uniform', parameters=[0.9, 1.1]) self.net.rset('cm', rd1) output_values = numpy.zeros((3, 3), numpy.float) hoc_net = getattr(h, self.net.label) for i in 0, 1, 2: for j in 0, 1, 2: id = 3 * i + j if id in self.net.gidlist: list_index = self.net.gidlist.index(id) output_values[i, j] = hoc_net.object(list_index).cell(0.5).cm input_values = rd2.next(9) output_values = output_values.reshape((9, )) for i in range(9): if i in self.net.gidlist: self.assertAlmostEqual(input_values[i], output_values[i], places=5)
def test_permutation(self): # only works for NumpyRNG at the moment. pygsl has a permutation module, but I can't find documentation for it. random.get_mpi_config = lambda: (0, 2) rng0 = random.NumpyRNG(seed=1000, parallel_safe=True) random.get_mpi_config = lambda: (1, 2) rng1 = random.NumpyRNG(seed=1000, parallel_safe=True) A = range(10) perm0 = rng0.permutation(A) perm1 = rng1.permutation(A) assert_arrays_almost_equal(perm0, perm1, 1e-99)
def testRSetNumpy(self): """Population.rset(): with numpy rng.""" rd1 = random.RandomDistribution(rng=random.NumpyRNG(seed=98765), distribution='uniform', parameters=[0.9,1.1]) rd2 = random.RandomDistribution(rng=random.NumpyRNG(seed=98765), distribution='uniform', parameters=[0.9,1.1]) self.net.rset('cm', rd1) output_values = self.net.get('cm', as_array=True) input_values = rd2.next(9).reshape(self.net.dim) assert numpy.equal(input_values, output_values).all()
def test_permutation(self): # only works for NumpyRNG at the moment. pygsl has a permutation module, but I can't find documentation for it. random.mpi_rank = 0 random.num_processes = 2 rng0 = random.NumpyRNG(seed=1000, parallel_safe=True) random.mpi_rank = 1 random.num_processes = 2 rng1 = random.NumpyRNG(seed=1000, parallel_safe=True) A = range(10) perm0 = rng0.permutation(A) perm1 = rng1.permutation(A) assert_arrays_almost_equal(perm0, perm1, 1e-99)
def testRSetNumpy(self): """Population.rset(): with numpy rng.""" rd1 = random.RandomDistribution(rng=random.NumpyRNG(seed=98765), distribution='uniform', parameters=[0.9, 1.1]) rd2 = random.RandomDistribution(rng=random.NumpyRNG(seed=98765), distribution='uniform', parameters=[0.9, 1.1]) self.net.rset('cm', rd1) output_values = self.net.get('cm', as_array=True) input_values = rd2.next(9) for i in range(9): self.assertAlmostEqual(input_values[i], output_values[i], places=5)
def test_1(self): C = connectors.FixedTotalNumberConnector(n=12, rng=random.NumpyRNG()) syn = sim.StaticSynapse(weight="0.5*d") prj = sim.Projection(self.p1, self.p2, C, syn) connections = prj.get(["weight", "delay"], format='list', gather=False) self.assertLess(len(connections), 12) # unlikely to be 12, since we have 2 MPI nodes self.assertGreater(len(connections), 0) # unlikely to be 0
def setUp(self): setup() self.target = Population((3,3),IF_curr_alpha) self.target = Population((3,3),IF_curr_alpha) self.source = Population((3,3),SpikeSourcePoisson,{'rate': 100}) self.distrib_Numpy = random.RandomDistribution('uniform',(0,1),random.NumpyRNG(12345)) self.distrib_Native= random.RandomDistribution('Uniform',(0,1),NativeRNG(12345))
def setUp(self): random.get_mpi_config = lambda: (0, 1) self.rnglist = [random.NumpyRNG(seed=987)] if random.have_gsl: self.rnglist.append(random.GSLRNG(seed=654)) if have_nrn: self.rnglist.append(NativeRNG(seed=321))
def testRSetNumpy(self): """Population.rset(): with numpy rng.""" rd1 = random.RandomDistribution(rng=random.NumpyRNG(seed=98765), distribution='uniform', parameters=[0.9,1.1]) rd2 = random.RandomDistribution(rng=random.NumpyRNG(seed=98765), distribution='uniform', parameters=[0.9,1.1]) self.popul1.rset('cm',rd1) output_values = numpy.zeros((3,3),numpy.float) for i in 0,1,2: for j in 0,1,2: output_values[i,j] = 1e9*simulator.net.object(self.popul1.getObjectID(self.popul1[i,j])).Cm input_values = rd2.next(9) output_values = output_values.reshape((9,)) for i in range(9): self.assertAlmostEqual(input_values[i],output_values[i],places=5)
def testDistantDependentProbability(self): """For all connections created with "distanceDependentProbability" ...""" # Test should be improved..." distrib_Numpy = random.RandomDistribution('uniform',(0,1),random.NumpyRNG(12345)) distrib_Native= random.RandomDistribution('Uniform',(0,1),NativeRNG(12345)) prj1 = Projection(self.source33, self.target33, DistanceDependentProbabilityConnector([ 0.1, 2]), distrib_Numpy) prj2 = Projection(self.source33, self.target33, DistanceDependentProbabilityConnector([ 0.1, 3]), distrib_Native) assert (0 < len(prj1) < len(self.source33)*len(self.target33)) and (0 < len(prj2) < len(self.source33)*len(self.target33))
def setUp(self): self.rnglist = [random.NumpyRNG(seed=987)] for rng in self.rnglist: rng.mpi_rank=0; rng.num_processes=1 if random.have_gsl: self.rnglist.append(random.GSLRNG(seed=654)) if have_nrn: self.rnglist.append(NativeRNG(seed=321))
def testPotentialRecording(self): """Population.record_v() and Population.print_v(): not a full test, just checking # there are no Exceptions raised.""" rng = random.NumpyRNG(123) v_reset = -65.0 v_thresh = -50.0 uniformDistr = random.RandomDistribution(rng=rng, distribution='uniform', parameters=[v_reset, v_thresh]) self.pop2.randomInit(uniformDistr) self.pop2.record_v([self.pop2[0,0], self.pop2[1,1]]) simtime = 10.0 neuron.running = False neuron.run(simtime) self.pop2.print_v("temp_neuron.v", gather=True, compatible_output=True)
def testFixedProbability(self): """For all connections created with "fixedProbability"...""" for srcP in [self.source5, self.source22]: for tgtP in [self.target1, self.target6, self.target33]: prj1 = sim.Projection(srcP, tgtP, sim.FixedProbabilityConnector(0.5), rng=random.NumpyRNG(12345)) prj2 = sim.Projection(srcP, tgtP, sim.FixedProbabilityConnector(0.5), rng=random.NativeRNG(12345)) for prj in prj1, prj2: assert (0 < len(prj) < len(srcP) * len(tgtP) ), 'len(prj) = %d, len(srcP)*len(tgtP) = %d' % ( len(prj), len(srcP) * len(tgtP))
def setUp(self): nest.setup(max_delay=0.5) nest.Population.nPop = 0 self.target33 = nest.Population((3, 3), nest.IF_curr_alpha) self.target6 = nest.Population((6, ), nest.IF_curr_alpha) self.source5 = nest.Population((5, ), nest.SpikeSourcePoisson) self.source22 = nest.Population((2, 2), nest.SpikeSourcePoisson) self.prjlist = [] self.distrib_Numpy = random.RandomDistribution( rng=random.NumpyRNG(12345), distribution='uniform', parameters=(0.1, 0.5)) for tgtP in [self.target6, self.target33]: for srcP in [self.source5, self.source22]: for method in ('allToAll', 'fixedProbability'): self.prjlist.append( nest.Projection(srcP, tgtP, method, {'p_connect': 0.5}))
def setUp(self): random.mpi_rank = 0 random.num_processes = 1 self.rnglist = [random.NumpyRNG(seed=987)] if random.have_gsl: self.rnglist.append(random.GSLRNG(seed=654))
def __init__(self, presynaptic_neurons, postsynaptic_neurons, method, source=None, target=None, synapse_dynamics=None, label=None, rng=None): """ presynaptic_neurons and postsynaptic_neurons - Population, PopulationView or Assembly objects. source - string specifying which attribute of the presynaptic cell signals action potentials. This is only needed for multicompartmental cells with branching axons or dendrodendriticsynapses. All standard cells have a single source, and this is the default. target - string specifying which synapse on the postsynaptic cell to connect to. For standard cells, this can be 'excitatory' or 'inhibitory'. For non-standard cells, it could be 'NMDA', etc. If target is not given, the default values of 'excitatory' is used. method - a Connector object, encapsulating the algorithm to use for connecting the neurons. synapse_dynamics - a `standardmodels.SynapseDynamics` object specifying which synaptic plasticity mechanisms to use. rng - specify an RNG object to be used by the Connector. """ for prefix, pop in zip(("pre", "post"), (presynaptic_neurons, postsynaptic_neurons)): if not isinstance(pop, (BasePopulation, Assembly)): raise errors.ConnectionError( "%ssynaptic_neurons must be a Population, PopulationView or Assembly, not a %s" % (prefix, type(pop))) if isinstance(postsynaptic_neurons, Assembly): if not postsynaptic_neurons._homogeneous_synapses: raise Exception( 'Projection to an Assembly object can be made only with homogeneous synapses types' ) self.pre = presynaptic_neurons # } these really self.source = source # } should be self.post = postsynaptic_neurons # } read-only self.target = target # } self.label = label if isinstance(rng, random.AbstractRNG): self.rng = rng elif rng is None: self.rng = random.NumpyRNG(seed=151985012) else: raise Exception( "rng must be either None, or a subclass of pyNN.random.AbstractRNG" ) self._method = method self.synapse_dynamics = synapse_dynamics #self.connection = None # access individual connections. To be defined by child, simulator-specific classes self.weights = [] if label is None: if self.pre.label and self.post.label: self.label = "%s→%s" % (self.pre.label, self.post.label) if self.synapse_dynamics: assert isinstance(self.synapse_dynamics, models.BaseSynapseDynamics), \ "The synapse_dynamics argument, if specified, must be a models.BaseSynapseDynamics object, not a %s" % type(synapse_dynamics)
import matplotlib.gridspec as gridspec import scipy.stats import pyNN.random as random try: from neuron import h except ImportError: have_nrn = False else: have_nrn = True from pyNN.neuron.random import NativeRNG n = 100000 nbins = 100 rnglist = [random.NumpyRNG(seed=984527)] if random.have_gsl: rnglist.append(random.GSLRNG(seed=668454)) if have_nrn: rnglist.append(NativeRNG(seed=321245)) cases = ( ("uniform", { "low": -65, "high": -55 }, (-65, -55), scipy.stats.uniform(loc=-65, scale=10)), ("gamma", { "k": 2.0, "theta": 0.5 }, (0, 5), scipy.stats.gamma(2.0, loc=0.0, scale=0.5)), ("normal", {
def test_1(self): C = connectors.FixedTotalNumberConnector(n=12, rng=random.NumpyRNG()) syn = sim.StaticSynapse(weight="0.5*d") prj = sim.Projection(self.p1, self.p2, C, syn) connections = prj.get(["weight", "delay"], format='list', gather=False) self.assertEqual(len(connections), 12)
def setUp(self): self.rnglist = [random.NumpyRNG(seed=987), random.GSLRNG(seed=654)]
def testRecordWithRNG(self): """Population.record(n, rng): not a full test, just checking there are no Exceptions raised.""" self.pop1.record(5, random.NumpyRNG())
def setUp(self): self.target = neuron.Population((3,3), neuron.IF_curr_alpha) self.source = neuron.Population((3,3), neuron.SpikeSourcePoisson,{'rate': 200}) self.distrib_Numpy = random.RandomDistribution(rng=random.NumpyRNG(12345), distribution='uniform', parameters=(0.2,1)) self.distrib_Native= random.RandomDistribution(rng=random.NativeRNG(12345), distribution='uniform', parameters=(0.2,1))