1 """
2 Projection-level response functions.
3
4 For CFProjections, these function objects compute a response matrix
5 when given an input pattern and a set of ConnectionField objects.
6
7 $Id: projfn.py 10867 2010-01-31 18:55:35Z ceball $
8 """
9 __version__='$Revision: 10867 $'
10
11 from numpy import sum,exp,zeros,ravel
12 from numpy.oldnumeric import Float
13
14 import param
15
16 from topo.base.cf import CFPResponseFn
17 from topo.base.functionfamily import ResponseFn,DotProduct
18 from topo.base.arrayutil import L2norm
19
20
21 from topo.base.cf import CFPRF_Plugin
22
23
24
25
27 """
28 Euclidean-distance--based response function.
29 """
30 - def __call__(self, iterator, input_activity, activity, strength, **params):
31 cfs = iterator.flatcfs
32 rows,cols = activity.shape
33 euclidean_dist_mat = zeros((rows,cols),Float)
34 for r in xrange(rows):
35 for c in xrange(cols):
36 flati = r*cols+c
37 cf = cfs[flati]
38 r1,r2,c1,c2 = cf.input_sheet_slice
39 X = input_activity[r1:r2,c1:c2]
40 diff = ravel(X) - ravel(cf.weights)
41 euclidean_dist_mat.flat[flati] = L2norm(diff)
42
43 max_dist = max(euclidean_dist_mat.ravel())
44 activity *= 0.0
45 activity += (max_dist - euclidean_dist_mat)
46 activity *= strength
47
48
49
51 """
52 Calculate the activity of each unit nonlinearly based on the input activity.
53
54 The activity is calculated from the input activity, the weights,
55 and a strength that is a function of the input activity. This
56 allows connections to have either an excitatory or inhibitory
57 effect, depending on the activity entering the unit in question.
58
59 The strength function is a generalized logistic curve (Richards'
60 curve), a flexible function for specifying a nonlinear growth
61 curve::
62
63 y = l + ( u /(1 + b exp(-r (x - 2m)) ^ (1 / b)) )
64
65 This function has five parameters::
66
67 * l: the lower asymptote, i.e. the value at infinity;
68 * u: the upper asymptote minus l, i.e. (u + l) is the value at minus infinity;
69 * m: the time of maximum growth;
70 * r: the growth rate;
71 * b: affects near which asymptote maximum growth occurs.
72
73 Richards, F.J. 1959 A flexible growth function for empirical use.
74 J. Experimental Botany 10: 290--300, 1959.
75 http://en.wikipedia.org/wiki/Generalised_logistic_curve
76 """
77
78 l = param.Number(default=-1.3,doc="Value at infinity")
79 u = param.Number(default=1.2,doc="(u + l) is the value at minus infinity")
80 m = param.Number(default=0.25,doc="Time of maximum growth.")
81 r = param.Number(default=-200,doc="Growth rate, controls the gradient")
82 b = param.Number(default=2,doc="Controls position of maximum growth")
83 single_cf_fn = param.ClassSelector(ResponseFn,default=DotProduct(),doc="""
84 ResponseFn to apply to each CF individually.""")
85
86 - def __call__(self, iterator, input_activity, activity, strength):
98