-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathfeatures_bahsic.py
More file actions
56 lines (46 loc) · 1.26 KB
/
features_bahsic.py
File metadata and controls
56 lines (46 loc) · 1.26 KB
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
import time
import sys
import numpy
import vector
from bahsic import CBAHSIC
usage = "yolo"
if __name__ == "__main__":
if (len(sys.argv)<4):
print usage
else:
file_x = sys.argv[1];
file_y = sys.argv[2];
file_out = sys.argv[3];
if (sys.argv==5):
file_normalized = sys.argv[5]
X = numpy.genfromtxt(file_x, delimiter=' ')
y = numpy.genfromtxt(file_y, delimiter=' ')
bahsic = CBAHSIC()
data_no = 160
features_tokeep = 5040
y.shape = (data_no,1)
# Normalize the labels.
y = 1.0*y
tmp_no = numpy.sum(y)
pno = (data_no + tmp_no) / 2
nno = (data_no - tmp_no) / 2
y[y>0] = y[y>0]/pno
y[y<0] = y[y<0]/nno
# Normalize the data.
m = X.mean(0)
s = X.std(0)
X.__isub__(m).__idiv__(s)
t1 = time.clock()
tmp = bahsic.BAHSICRaw(X, y, vector.CLinearKernel(), vector.CLinearKernel(), features_tokeep, 0.1)
t2 = time.clock()
print "time taken: "+str(t2-t1)
print '--rank of the features'
print '--better features towards the end of the list:'
print tmp
hsicfeatures= numpy.zeros(shape=(data_no,features_tokeep))
for i in range(0,data_no):
for j in range(0,features_tokeep):
hsicfeatures[i][j] = X[i][tmp[features_tokeep+j]]
numpy.savetxt(file_out, hsicfeatures)
if (sys.argv==5):
numpy.savetxt('original.csv', X)