-
Notifications
You must be signed in to change notification settings - Fork 1
/
inputMatrix.py
97 lines (73 loc) · 1.87 KB
/
inputMatrix.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import cPickle as pickle
import numpy as np
import sys
filename = 'inputMatrix' + sys.argv[1]
f = open('data/' + str(filename) + '.pckl')
data = pickle.load(f)
f.close()
cov = np.cov(data.T)
for i in xrange (0,len(cov)):
cov[i][i] = 0
cov = np.absolute(cov)
inputMatrix = np.zeros((5,103))
kernelSize = 3
row = 0
col = 0
i = 0
added = [] #list of attributes already added to our input matrix
while col < 103: #for the first 3 rows
rowIndex = np.unravel_index(np.argmax(cov > 0), cov.shape)[0]
colIndex = np.unravel_index(np.argmax(cov > 0), cov.shape)[1]
if rowIndex == 0 and colIndex == 0:
break
cov[rowIndex][colIndex] = 0
cov[colIndex][rowIndex] = 0
if rowIndex not in added:
added.append(rowIndex)
print 'added attribute', rowIndex
inputMatrix[row][col] = rowIndex
row += 1
if row == 3:
row = 0
col += 1
if colIndex not in added:
print 'added attribute', colIndex
added.append(colIndex)
inputMatrix[row][col] = colIndex
row += 1
if row == 3:
row = 0
col += 1
col = 0
row = 3
while col < 103: #for the first 3 rows
rowIndex = np.unravel_index(np.argmax(cov > 0), cov.shape)[0]
colIndex = np.unravel_index(np.argmax(cov > 0), cov.shape)[1]
if rowIndex == 0 and colIndex == 0:
break
cov[rowIndex][colIndex] = 0
cov[colIndex][rowIndex] = 0
if rowIndex not in added:
print 'added attribute', rowIndex
added.append(rowIndex)
inputMatrix[row][col] = rowIndex
row += 1
if row == 5:
row = 3
col += 1
if colIndex not in added:
print 'added attribute', colIndex
added.append(colIndex)
inputMatrix[row][col] = colIndex
row += 1
if row == 5:
row = 3
col += 1
inputArray = inputMatrix.reshape((1,515)).flatten()
missA = range(0,515)
missA = set(missA) - set(added)
missA = list(missA)
missIndex = np.argwhere(inputArray == 0).flatten()
for i in xrange(0,len(missIndex)):
inputArray[missIndex[i]] = missA[i]
print inputArray