Changeset 421
- Timestamp:
- 07/17/08 09:34:30 (1 month ago)
- Files:
-
- trunk/src/random.py (modified) (4 diffs)
- trunk/test/brunel.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/random.py
r366 r421 145 145 numbers from a given distribution.""" 146 146 147 def __init__(self, distribution='uniform', parameters=[], rng=None ):147 def __init__(self, distribution='uniform', parameters=[], rng=None, boundaries=None, constrain="clip"): 148 148 """ 149 149 If present, rng should be a NumpyRNG or GSLRNG object. … … 153 153 by the underlying method in the correct order. named arguments are 154 154 not yet supported. 155 boundaries is a tuple (min, max) used to specify explicitely, for distribution 156 like Gaussian, Gamma or others, hard boundaries for the parameters. If 157 parameters are drawn outside those boundaries, the policy applied will depend 158 on the constrain parameter. 159 constrain control the policy for weights out of the specified boundaries. 160 If "clip", random numbers are clipped to the boundaries. 161 If "redraw", random numbers are drawn till they fall within the boundaries. 155 162 Note that NumpyRNG and GSLRNG distributions may not have the same names, 156 163 e.g., 'normal' for NumpyRNG and 'gaussian' for GSLRNG, and the … … 160 167 assert isinstance(parameters, (list, tuple, dict)), "The parameters argument must be a list or tuple or dict" 161 168 self.parameters = parameters 169 self.boundaries = boundaries 170 self.constrain = constrain 162 171 if rng: 163 172 assert isinstance(rng, AbstractRNG), "rng must be a pyNN.random RNG object" … … 168 177 def next(self, n=1): 169 178 """Return n random numbers from the distribution.""" 170 return self.rng.next(n=n, 179 if self.boundaries: 180 res = self.rng.next(n=n, 181 distribution=self.name, 182 parameters=self.parameters) 183 if self.constrain == "clip": 184 return numpy.maximum(numpy.minimum(res,self.boundaries[1]),self.boundaries[0]) 185 elif self.constrain == "redraw": 186 idx = numpy.where((res > self.boundaries[1]) | (res < self.boundaries[0]))[0] 187 while len(idx) > 0: 188 res[idx] = self.rng.next(len(idx),distribution=self.name,parameters=self.parameters) 189 idx = numpy.where((res > self.boundaries[1]) | (res < self.boundaries[0]))[0] 190 return res 191 else: 192 raise Exception("This constrain method (%s) does not exist" %self.constrain) 193 else: 194 return self.rng.next(n=n, 171 195 distribution=self.name, 172 196 parameters=self.parameters) trunk/test/brunel.py
r415 r421 170 170 print "input --> E\t", len(input_to_E), "connections" 171 171 172 print E_to_E.describe()173 174 172 print "%d Connecting inhibitory population." %myid 175 173 E_to_I = Projection(E_net, I_net, E_Connector, rng=rng, target="excitatory")
