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