-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathweights.py
51 lines (43 loc) · 1.38 KB
/
weights.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
import numpy as np
"""
Parameters used in the paper:
These were initialized with distributions.py with some minor adjustments
described in the supplementary material.
"""
mu1=1.3
mu2=0.9282957
mu3=0.4991303
mu4=0.2655985
sigma=0.35
threshold=0.724
"""
Parameters generated by distributions.py (run the script to regenerate them):
Uncomment to run simulations with these parameters. The results will be
essentially equivalent to those reported in the paper using the parameters above.
The point here is that the results are not particularly sensitive to modest
variations in the parameter settings.
"""
# mu1=1.25
# mu2=0.970515977492
# mu3=0.48004121207
# mu4=0.213147729935
# sigma=0.4
# threshold=0.737
def murphy(seed=None):
# Set seed for generating weight distributions
if seed != None:
np.random.seed(seed=seed)
# Initialize dot product and weight matrices
products = np.zeros((8,4))
weights = np.zeros((8,4))
# Compute weights for 8 categories from parameters using least squares
for i in range(8):
F = np.array([[1,1,1,1],[1,0,1,1],[0,1,1,1],[0,0,0,1]])
X = [np.random.normal(mu1, sigma, 1), np.random.normal(mu2, sigma, 1),
np.random.normal(mu3, sigma, 1), np.random.normal(mu4, sigma, 1)]
G = np.linalg.pinv(np.dot(np.transpose(F),F))
T = np.dot(np.transpose(F),X)
W = np.dot(G,T)
products[i,:] = X
weights[i,:] = np.transpose(W)
return [weights, products]