Package topo :: Package sheets :: Module cfsom
[hide private]
[frames] | no frames]

Source Code for Module topo.sheets.cfsom

 1  """ 
 2  Defines CFSOM, a sheet class that works like a Kohonen SOM extended to 
 3  support topographically restricted receptive fields. 
 4   
 5  $Id: cfsom.py 5636 2007-04-25 04:14:53Z jbednar $ 
 6  """ 
 7  __version__='$Revision: 5636 $' 
 8   
 9  from numpy.oldnumeric import argmax,exp,floor 
10   
11  from topo.base.arrayutils import L2norm 
12  from topo.base.parameterclasses import Number 
13  from topo.base.cf import CFSheet 
14  from topo.learningfns.som import CFPLF_SOM 
15   
16   
17  ### JABHACKALERT: This class (and this file) will be removed once the 
18  ### examples no longer rely upon it 
19 -class CFSOM(CFSheet):
20 """ 21 Kohonen Self-Organizing Map algorithm extended to support ConnectionFields. 22 23 This is an implementation of the Kohonen SOM algorithm extended to 24 support ConnectionFields, i.e., different spatially restricted 25 input regions for different units. With fully connected input 26 regions, it should be usable as a regular SOM as well. 27 28 This implementation is obsolete and will be removed soon. 29 Please see examples/cfsom_or.ty for current SOM support. 30 """ 31 alpha_0 = Number(0.5, doc="Initial value of the learning rate.") 32 radius_0 = Number(1.0, doc="Initial value of the neighborhood radius.") 33 precedence = Number(0.6) 34 learning_length = Number(1000, doc="Number of input presentations to use, by default.") 35
36 - def __init__(self,**params):
37 super(CFSOM,self).__init__(**params) 38 self.half_life = self.learning_length/8 39 self.warning("CFSOM is deprecated -- see the example in cfsom_or.ty for how to build a SOM")
40
41 - def decay(self, time, half_life):
42 """Exponential decay.""" 43 return 0.5**(time/float(half_life))
44
45 - def alpha(self):
46 """Return the learning rate at a specified simulation time, using exponential falloff.""" 47 return self.alpha_0 * self.decay(float(self.simulation.time()),self.half_life)
48
49 - def radius(self):
50 """Return the radius at a specified simulation time, using exponential falloff.""" 51 return self.radius_0 * self.decay(float(self.simulation.time()),self.half_life)
52
53 - def learn(self):
54 """ 55 Call the learn() method on every CFProjection to the Sheet. 56 """ 57 rows,cols = self.activity.shape 58 radius = self.radius() * self.xdensity 59 for proj in self.in_connections: 60 proj.learning_rate = self.alpha() 61 if isinstance(proj.learning_fn, CFPLF_SOM): 62 proj.learning_fn.learning_radius = radius 63 proj.learn()
64