-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
38 lines (30 loc) · 945 Bytes
/
utils.py
File metadata and controls
38 lines (30 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import numpy as np
def logist(x, k, max, min, mean):
"""
For calculating the decay factor df.
Higher grad = sharper
"""
max = max - min;
y = min + (max / (1 + np.exp(k * (x - mean))))
return y
def spm_norm(A):
"""
Normalisation of a probability transition matrix (columns)
"""
A = np.dot(A, np.diag(1 / np.sum(A, 0)))
return A
def spm_softmax(x, k = 1):
"""
Softmax (neural transfer) function of COLUMN vectors
Format [y] = spm_softmax(x,k)
x - vector of activity
k - temperature or inverse sensitivity parameter (default k = 1)
y = exp(k*x)/sum(exp(k*x))
NB: If supplied with a matrix this rotine will return the softmax
function over columns - so that spm_softmax([x1,x2,...]) = [1,1,...]
"""
x = x * k
x = x - np.max(x)
ex = np.exp(x)
y = ex / np.sum(ex, axis = 0)
return y