Example #1
0
 def test_native_rng_pick(self):
     rng = Mock()
     rng.seed = 28754
     rarr = simulator.nativeRNG_pick(100, rng, 'uniform', [-3, 6])
     assert isinstance(rarr, numpy.ndarray)
     self.assertEqual(rarr.shape, (100,))
     assert -3 <= rarr.min() < -2.5
     assert 5.5 < rarr.max() < 6
Example #2
0
 def test_native_rng_pick(self):
     rng = Mock()
     rng.seed = 28754
     rarr = simulator.nativeRNG_pick(100, rng, 'uniform', [-3, 6])
     assert isinstance(rarr, numpy.ndarray)
     self.assertEqual(rarr.shape, (100,))
     assert -3 <= rarr.min() < -2.5
     assert 5.5 < rarr.max() < 6
Example #3
0
 def randomizeDelays(self, rand_distr):
     """
     Set delays to random values taken from rand_distr.
     """
     # If we have a native rng, we do the loops in hoc. Otherwise, we do the loops in
     # Python
     if isinstance(rand_distr.rng, NativeRNG):
         rarr = simulator.nativeRNG_pick(len(self), rand_distr.rng,
                                         rand_distr.name,
                                         rand_distr.parameters)
     else:
         rarr = rand_distr.next(len(self))
     logger.info("--- Projection[%s].__randomizeDelays__() ---" %
                 self.label)
     self.setDelays(rarr)
Example #4
0
                try:
                    val = value[addr]
                except IndexError, e:
                    raise IndexError("%s. addr=%s" % (e, addr))
                if numpy.isnan(val):
                    raise Exception(
                        "Array contains no value for synapse from %d to %d" %
                        (c.source, c.target))
                else:
                    setattr(c, name, val)
        elif core.is_listlike(value):
            for c, val in zip(self.connections, value):
                setattr(c, name, val)
        elif isinstance(value, RandomDistribution):
            if isinstance(value.rng, NativeRNG):
                rarr = simulator.nativeRNG_pick(len(self), value.rng,
                                                value.name, value.parameters)
            else:
                rarr = value.next(len(self))
            for c, val in zip(self.connections, rarr):
                setattr(c, name, val)
        else:
            raise TypeError(
                "Argument should be a numeric type (int, float...), a list, or a numpy array."
            )

    def get(self, parameter_name, format, gather=True):
        """
        Get the values of a given attribute (weight, delay, etc) for all
        connections on the local MPI node.
        
        `parameter_name` -- name of the attribute whose values are wanted.
Example #5
0
                addr = (self.pre.id_to_index(c.source), self.post.id_to_index(c.target))
                try:
                    val = value[addr]
                except IndexError, e:
                    raise IndexError("%s. addr=%s" % (e, addr))
                if numpy.isnan(val):
                    raise Exception("Array contains no value for synapse from %d to %d" % (c.source, c.target))
                else:
                    setattr(c, name, val)
        elif core.is_listlike(value):
            for c,val in zip(self.connections, value):
                setattr(c, name, val)
        elif isinstance(value, RandomDistribution):
            if isinstance(value.rng, NativeRNG):
                rarr = simulator.nativeRNG_pick(len(self),
                                                value.rng,
                                                value.name,
                                                value.parameters)
            else:       
                rarr = value.next(len(self))
            for c,val in zip(self.connections, rarr):
                setattr(c, name, val)   
        else:
            raise TypeError("Argument should be a numeric type (int, float...), a list, or a numpy array.")

    def get(self, parameter_name, format, gather=True):
        """
        Get the values of a given attribute (weight, delay, etc) for all
        connections on the local MPI node.
        
        `parameter_name` -- name of the attribute whose values are wanted.
        `format` -- "list" or "array". Array format implicitly assumes that all