1 """
2 Basic function objects.
3
4 TransferFns: accept and modify a 2d array
5 ResponseFns: accept two 2d arrays and return a scalar
6 LearningFns: accept two 2d arrays and a scalar, return one of the arrays modified
7
8 $Id: functionfamily.py 11088 2010-06-17 17:23:59Z ceball $
9 """
10 __version__='$Revision: 11088 $'
11
12
13
14 import numpy
15
16 import param
17
18
20 """
21 Function object to modify a matrix in place, e.g. for normalization.
22
23 Used for transforming an array of intermediate results into a
24 final version, by cropping it, normalizing it, squaring it, etc.
25
26 Objects in this class must support being called as a function with
27 one matrix argument, and are expected to change that matrix in place.
28 """
29 __abstract = True
30
31
32
33 norm_value = param.Parameter(default=None)
34
35
37 raise NotImplementedError
38
39
40
41
43 """
44 Identity function, returning its argument as-is.
45
46 For speed, calling this function object is sometimes optimized
47 away entirely. To make this feasible, it is not allowable to
48 derive other classes from this object, modify it to have different
49 behavior, add side effects, or anything of that nature.
50 """
51
54
55
56
57
59 """
60 Abstract base class for learning functions that plug into
61 CFPLF_Plugin.
62 """
63
64 __abstract = True
65
66
67
68 - def __call__(self,input_activity, unit_activity, weights, single_connection_learning_rate):
69 """
70 Apply this learning function given the input and output
71 activities and current weights.
72
73 Must be implemented by subclasses.
74 """
75 raise NotImplementedError
76
77
79 """
80 Basic Hebbian rule; Dayan and Abbott, 2001, equation 8.3.
81
82 Increases each weight in proportion to the product of this
83 neuron's activity and the input activity.
84
85 Requires some form of output_fn normalization for stability.
86 """
87
88 - def __call__(self,input_activity, unit_activity, weights, single_connection_learning_rate):
89 weights += single_connection_learning_rate * unit_activity * input_activity
90
91
93 """
94 Identity function; does not modify the weights.
95
96 For speed, calling this function object is sometimes optimized
97 away entirely. To make this feasible, it is not allowable to
98 derive other classes from this object, modify it to have different
99 behavior, add side effects, or anything of that nature.
100 """
101
102 - def __call__(self,input_activity, unit_activity, weights, single_connection_learning_rate):
104
105
106
108 """Abstract base class for response functions that plug into CFPRF_Plugin."""
109
110 __abstract = True
111
113 """
114 Apply the response function; must be implemented by subclasses.
115 """
116 raise NotImplementedError
117
118
119
121 """
122 Return the sum of the element-by-element product of two 2D
123 arrays.
124 """
126
127
128
129
130 return numpy.dot(m1.ravel(),m2.ravel())
131
132
133
135 """Abstract base class for functions mapping from a 2D coordinate into another one."""
136
137 __abstract = True
138
140 """
141 Apply the coordinate mapping function; must be implemented by subclasses.
142 """
143 raise NotImplementedError
144
145
147 """Return the x coordinate of the given coordinate."""
150
151
153 """
154 Abstract base class for various stimulus-response types of analysis.
155
156 This type of analysis consists of presenting a set of input
157 patterns and collecting the responses to each one, which one will
158 often want to do in a way that does not affect the current state
159 of the network.
160
161 To achieve this, the class defines several types of hooks where
162 arbitrary function objects (i.e., callables) can be registered.
163 These hooks are generally used to ensure that unrelated previous
164 activity is eliminated, that subsequent patterns do not interact,
165 and that the initial state is restored after analysis.
166
167 Any subclasses must ensure that these hook lists are run at the
168 appropriate stage in their processing, using e.g.
169 "for f in some_hook_list: f()".
170 """
171
172 __abstract = True
173
174 pre_analysis_session_hooks = param.HookList(default=[],instantiate=False,doc="""
175 List of callable objects to be run before an analysis session begins.""")
176
177 pre_presentation_hooks = param.HookList(default=[],instantiate=False,doc="""
178 List of callable objects to be run before each pattern is presented.""")
179
180 post_presentation_hooks = param.HookList(default=[],instantiate=False,doc="""
181 List of callable objects to be run after each pattern is presented.""")
182
183 post_analysis_session_hooks = param.HookList(default=[],instantiate=False,doc="""
184 List of callable objects to be run after an analysis session ends.""")
185