| Trees | Indices | Help |
|
|---|
|
|
1 """ 2 GeneratorSheet: a sheet with a pattern generator. 3 4 5 $Id: generatorsheet.py 11110 2010-07-05 10:52:25Z ceball $ 6 """ 7 __version__='$Revision: 7629 $' 8 9 10 import param 11 from topo.base.sheet import Sheet 12 from topo.base.patterngenerator import PatternGenerator,Constant 13 from topo.base.simulation import FunctionEvent, PeriodicEventSequence 14 15 16 # JLALERT: This sheet should have override_plasticity_state/restore_plasticity_state 17 # functions that call override_plasticity_state/restore_plasticty_state on the 18 # sheet output_fn and input_generator output_fn.20 """ 21 Sheet for generating a series of 2D patterns. 22 23 Typically generates the patterns by choosing parameters from a 24 random distribution, but can use any mechanism. 25 """ 26 27 src_ports=['Activity'] 28 29 period = param.Number(default=1,bounds=(0,None),doc= 30 "Delay (in Simulation time) between generating new input patterns.") 31 32 phase = param.Number(default=0.05,doc= 33 """ 34 Delay after the start of the Simulation (at time zero) before 35 generating an input pattern. For a clocked, feedforward simulation, 36 one would typically want to use a small nonzero phase and use delays less 37 than the user-visible step size (typically 1.0), so that inputs are 38 generated and processed before this step is complete. 39 """) 40 41 input_generator = param.ClassSelector(PatternGenerator,default=Constant(), 42 doc="""Specifies a particular PatternGenerator type to use when creating patterns.""") 43 4412846 super(GeneratorSheet,self).__init__(**params) 47 self.input_generator_stack = [] 48 self.set_input_generator(self.input_generator) 49 50 # JABALERT: Should make period have an exclusive lower bound instead 51 assert self.period!=0, "Period must be greater than zero."5254 """ 55 Set the input_generator, overwriting the existing one by default. 56 57 If push_existing is false, the existing input_generator is 58 discarded permanently. Otherwise, the existing one is put 59 onto a stack, and can later be restored by calling 60 pop_input_generator. 61 """ 62 63 if push_existing: 64 self.push_input_generator() 65 66 self.input_generator = new_ig 67 68 # CEBALERT: replaces any bounds specified for the 69 # PatternGenerator with this sheet's own bounds. When 70 # PatternGenerators can draw patterns into supplied 71 # boundingboxes, should remove this. 72 self.input_generator.bounds = self.bounds 73 74 self.input_generator.xdensity = self.xdensity 75 self.input_generator.ydensity = self.ydensity76 7779 """Push the current input_generator onto a stack for future retrieval.""" 80 self.input_generator_stack.append(self.input_generator) 81 82 # CEBALERT: would be better to reorganize code so that 83 # push_input_generator must be supplied with a new generator. 84 # CEBALERT: presumably we can remove this import. 85 from topo.base.patterngenerator import Constant 86 self.set_input_generator(Constant())87 8890 """ 91 Discard the current input_generator, and retrieve the previous one from the stack. 92 93 Warns if no input_generator is available on the stack. 94 """ 95 if len(self.input_generator_stack) >= 1: 96 self.set_input_generator(self.input_generator_stack.pop()) 97 else: 98 self.warning('There is no previous input generator to restore.')99101 """ 102 Generate the output and send it out the Activity port. 103 """ 104 self.verbose("Generating a new pattern") 105 106 # JABALERT: What does the [:] achieve here? Copying the 107 # values, instead of the pointer to the array? Is that 108 # guaranteed? 109 self.activity[:] = self.input_generator() 110 111 if self.apply_output_fns: 112 for of in self.output_fns: 113 of(self.activity) 114 self.send_output(src_port='Activity',data=self.activity)115 116118 assert self.simulation 119 120 if self.period > 0: 121 # if it has a positive period, then schedule a repeating event to trigger it 122 e=FunctionEvent(0,self.generate) 123 now = self.simulation.time() 124 self.simulation.enqueue_event(PeriodicEventSequence(now+self.phase,self.period,[e]))125
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Thu Aug 5 14:59:58 2010 | http://epydoc.sourceforge.net |