1 """
2 Homeostatic output functions, which are designed to keep an activity
3 value in a desired range over time.
4
5 Originally implemented by Veldri Kurniawan, 2006.
6
7 $Id: homeostatic.py 7868 2008-02-07 14:16:01Z jbednar $
8 """
9 __version__='$Revision: 7868 $'
10
11
12
13 import copy
14 import topo
15 from numpy import exp,zeros,ones
16
17 from topo.base.functionfamilies import OutputFn, OutputFnWithState, OutputFnParameter, IdentityOF
18 from topo.base.parameterclasses import Number, BooleanParameter, ListParameter, StringParameter
19 from topo.base.parameterizedobject import ParameterizedObject
20 from topo.base.sheet import activity_type
21 from topo.commands.pylabplots import vectorplot
22 from topo.misc.filepaths import normalize_path
23
24
26 """
27 Implementation of homeostatic intrinsic plasticity from Jochen Triesch,
28 ICANN 2005, LNCS 3696 pp.65-70.
29
30 A sigmoid activation function is adapted automatically to achieve
31 desired average firing rate and approximately exponential
32 distribution of firing rates (for the maximum possible entropy).
33
34 Note that this OutputFn has state, so the history of calls to it
35 will affect future behavior. The updating parameter can be used
36 to disable changes to the state.
37
38 Also calculates average activity as useful debugging information,
39 for use with ValueTrackingOutoutFn Average activity is calculated as
40 an exponential moving average with a smoothing factor (smoothing).
41 For more information see:
42 NIST/SEMATECH e-Handbook of Statistical Methods, Single Exponential Smoothing
43 http://www.itl.nist.gov/div898/handbook/pmc/section4/pmc431.htm
44 """
45
46 a_init = Number(default=13,doc="Multiplicative parameter controlling the exponential.")
47
48 b_init = Number(default=-4,doc="Additive parameter controlling the exponential.")
49
50 eta = Number(default=0.0002,doc="Learning rate for homeostatic plasticity.")
51
52 mu = Number(default=0.01,doc="Target average firing rate.")
53
54 smoothing = Number(default=0.9997, doc="""
55 Weighting of previous activity vs. current activity when calculating the average.""")
56
60
62
63 if self.first_call:
64 self.first_call = False
65 self.a = ones(x.shape, x.dtype.char) * self.a_init
66 self.b = ones(x.shape, x.dtype.char) * self.b_init
67 self.y_avg = zeros(x.shape, x.dtype.char)
68
69
70 x_orig = copy.copy(x)
71 x *= 0.0
72 x += 1.0 / (1.0 + exp(-(self.a*x_orig + self.b)))
73
74 if self.updating:
75
76 self.y_avg = (1.0-self.smoothing)*x + self.smoothing*self.y_avg
77
78
79 self.a += self.eta * (1.0/self.a + x_orig - (2.0 + 1.0/self.mu)*x_orig*x + x_orig*x*x/self.mu)
80 self.b += self.eta * (1.0 - (2.0 + 1.0/self.mu)*x + x*x/self.mu)
81
82
83
85 """
86 Scales input activity based on the current average activity (x_avg).
87
88 The scaling is calculated to bring x_avg for each unit closer to a
89 specified target average. Calculates a scaling factor that is
90 greater than 1 if x_avg is less than the target and less than 1 if
91 x_avg is greater than the target, and multiplies the input
92 activity by this scaling factor.
93
94 The updating parameter allows the updating of the average values
95 to be disabled temporarily, e.g. while presenting test patterns.
96 """
97
98 target = Number(default=0.01, doc="""
99 Target average activity for each unit.""")
100
101 step=Number(default=1, doc="""
102 How often to calculate the average activity and scaling factor.""")
103
104 smoothing = Number(default=0.9997, doc="""
105 Determines the degree of weighting of previous activity vs.
106 current activity when calculating the average.""")
107
108
114
132
133
134
136 """
137 Implementation of homeostatic intrinsic plasticity from Jochen Triesch,
138 ICANN 2005, LNCS 3696 pp.65-70, modified to change only the b value.
139
140 A sigmoid activation function is adapted automatically to achieve
141 desired average firing rate and approximately exponential
142 distribution of firing rates (for the maximum possible entropy).
143
144 Note that this OutputFn has state, so the history of calls to it
145 will affect future behavior. The updating parameter can be used
146 to disable changes to the state.
147
148 Also calculates average activity as useful debugging information,
149 for use with ValueTrackingOutoutFn Average activity is calculated as
150 an exponential moving average with a smoothing factor (smoothing).
151 For more information see:
152 NIST/SEMATECH e-Handbook of Statistical Methods, Single Exponential Smoothing
153 http://www.itl.nist.gov/div898/handbook/pmc/section4/pmc431.htm
154 """
155
156 a_init = Number(default=13,doc="Multiplicative parameter controlling the exponential.")
157
158 b_init = Number(default=-4,doc="Additive parameter controlling the exponential.")
159
160 eta = Number(default=0.0002,doc="Learning rate for homeostatic plasticity.")
161
162 mu = Number(default=0.01,doc="Target average firing rate.")
163
164 smoothing = Number(default=0.9997, doc="""
165 Weighting of previous activity vs. current activity when calculating the average.""")
166
167