-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprob_functions.py
65 lines (47 loc) · 1.68 KB
/
prob_functions.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import numpy as np
def p_independent(N_hypercolumns, units_per_hypercolumn,
X, low_noise=10e-10, normalize=True):
"""
This and that
"""
p = np.zeros((N_hypercolumns, units_per_hypercolumn))
for i in range(units_per_hypercolumn):
p[:, i] = np.sum(X == i, axis=0)
if normalize:
p = p * 1.0 / X.shape[0]
# Add low noise
p[p < low_noise] = low_noise
# Now we need to normalize
p = p / p.sum(axis=1)[:, np.newaxis]
return p
def coincidences(i, j, k, l, X, distribution):
"""
Caculates the number of coincidences between two distributions
"""
hits_1 = X[..., i] == distribution[k]
hits_2 = X[..., j] == distribution[l]
return np.sum(hits_1 * hits_2)
def joint(i, j, X, distribution, units_per_hypercolumn):
"""
This and that
"""
hypercolums = range(units_per_hypercolumn)
joint_probability = np.zeros((units_per_hypercolumn,
units_per_hypercolumn))
for k in hypercolums:
for l in hypercolums:
joint_probability[k, l] = coincidences(i, j, k, l, X, distribution)
return joint_probability * 1.0 / X.shape[0]
def p_joint(N_hypercolumns, units_per_hypercolumn, X, distribution):
"""
This and that
"""
p_joint = np.zeros((N_hypercolumns, N_hypercolumns,
units_per_hypercolumn, units_per_hypercolumn))
for i in xrange(N_hypercolumns):
for j in xrange(i, N_hypercolumns):
aux = joint(i, j, X, distribution,
units_per_hypercolumn)
p_joint[i, j, ...] = aux
p_joint[j, i, ...] = aux.T
return p_joint