| Trees | Indices | Help |
|
|---|
|
|
1 """ 2 Two-dimensional pattern generators drawing from various random distributions. 3 4 $Id: random.py 11293 2010-07-27 14:19:32Z ceball $ 5 """ 6 __version__='$Revision: 11293 $' 7 8 import numpy 9 10 import param 11 from param.parameterized import ParamOverrides 12 13 from topo.base.patterngenerator import PatternGenerator 14 from topo.pattern import Composite, Gaussian 15 from topo.base.sheetcoords import SheetCoordinateSystem 16 1719 """ 20 Set the seed on the shared RandomState instance. 21 22 Convenience function: shortcut to RandomGenerator.random_generator.seed(). 23 """ 24 RandomGenerator.random_generator.seed(seed)25 2628 """2D random noise pattern generator abstract class.""" 29 30 __abstract = True 31 32 # The orientation is ignored, so we don't show it in 33 # auto-generated lists of parameters (e.g. in the GUI) 34 orientation = param.Number(precedence=-1) 35 36 random_generator = param.Parameter( 37 default=numpy.random.RandomState(seed=(500,500)),precedence=-1,doc= 38 """ 39 numpy's RandomState provides methods for generating random 40 numbers (see RandomState's help for more information). 41 42 Note that all instances will share this RandomState object, 43 and hence its state. To create a RandomGenerator that has its 44 own state, set this parameter to a new RandomState instance. 45 """) 46 4766 67 68 74 75 7649 """Method for subclasses to override with a particular random distribution.""" 50 raise NotImplementedError51 52 # Optimization: We use a simpler __call__ method here to skip the 53 # coordinate transformations (which would have no effect anyway)55 p = ParamOverrides(self,params_to_override) 56 57 shape = SheetCoordinateSystem(p.bounds,p.xdensity,p.ydensity).shape 58 59 result = self._distrib(shape,p) 60 self._apply_mask(p,result) 61 62 for of in p.output_fns: 63 of(result) 64 65 return result78 """ 79 2D binary uniform random noise pattern generator. 80 81 Generates an array of random numbers that are 1.0 with the given 82 on_probability, or else 0.0, then scales it and adds the offset as 83 for other patterns. For the default scale and offset, the result 84 is a binary mask where some elements are on at random. 85 """ 86 87 on_probability = param.Number(default=0.5,bounds=[0.0,1.0],doc=""" 88 Probability (in the range 0.0 to 1.0) that the binary value 89 (before scaling) is on rather than off (1.0 rather than 0.0).""") 9094 95 9692 rmin = p.on_probability-0.5 93 return p.offset+p.scale*(p.random_generator.uniform(rmin,rmin+1.0,shape).round())98 """ 99 2D Gaussian random noise pattern generator. 100 101 Each pixel is chosen independently from a Gaussian distribution 102 of zero mean and unit variance, then multiplied by the given 103 scale and adjusted by the given offset. 104 """ 105 106 scale = param.Number(default=0.25,softbounds=(0.0,2.0)) 107 offset = param.Number(default=0.50,softbounds=(-2.0,2.0)) 108111 112 113 # CEBALERT: in e.g. script_repr, an instance of this class appears to 114 # have only pattern.Constant() in its list of generators, which might 115 # be confusing. The Constant pattern has no effect because the 116 # generators list is overridden in __call__. Shouldn't the generators 117 # parameter be hidden for this class (and possibly for others based on 118 # pattern.Composite)? For that to be safe, we'd at least have to have 119 # a warning if someone ever sets a hidden parameter, so that having it 120 # revert to the default value would always be ok. 121123 """Uniform random noise masked by a circular Gaussian.""" 124 125 operator = param.Parameter(numpy.multiply) 126 127 gaussian_size = param.Number(default=1.0,doc="Size of the Gaussian pattern.") 128 129 aspect_ratio = param.Number(default=1.0,bounds=(0.0,None),softbounds=(0.0,2.0), 130 precedence=0.31,doc=""" 131 Ratio of gaussian width to height; width is gaussian_size*aspect_ratio.""") 132138134 p = ParamOverrides(self,params_to_override) 135 p.generators=[Gaussian(aspect_ratio=p.aspect_ratio,size=p.gaussian_size), 136 UniformRandom()] 137 return super(GaussianCloud,self).__call__(**p)
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Thu Aug 5 14:59:58 2010 | http://epydoc.sourceforge.net |