-
Notifications
You must be signed in to change notification settings - Fork 0
/
multithreaded_mrmr.py
93 lines (77 loc) · 2.12 KB
/
multithreaded_mrmr.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
import threading
import time
import ref_4_mifs as mifs
from sklearn.externals import joblib
def SelectSubSetmRMR(vectors, classes, useMethod='MRMR'):#, numOfFeatures=500):
X = vectors
y = classes
# define MI_FS feature selection method
feat_selector = mifs.MutualInformationFeatureSelector(method=useMethod) #n_features=numOfFeatures)
# find all relevant features
feat_selector.fit(X, y)
# check selected features
feat_selector.support_
# check ranking of features
return feat_selector.ranking_
"""
TEST PROGRAM
"""
from GlobalUtils import *
import scipy
from MachineSpecificSettings import Settings
import scipy.io
import numpy
from DataSetLoaderLib import DataSetLoader
import csv
values=[]
class myThread (threading.Thread):
def __init__(self, threadID, name,add_by, variables,targets):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
self.variables=variables
self.targets=targets
self.add_by=add_by
def run(self):
threadLock.acquire()
try:
useMethod = 'MRMR'
print "Starting " + self.name
print self.add_by
x=SelectSubSetmRMR(self.variables, self.targets, useMethod)
for i in x:
if i+self.add_by>=545089:
i+=1
values.append(i+self.add_by)
joblib.dump(values,'selected_indices'+'_'+useMethod+'.joblib.pkl', compress=9)
except:
print "Error Occured"
threadLock.release()
print len(values)
print "Exiting " + self.name
return
threads=[]
d = DataSetLoader();
G = d.LoadDataSet("B_train");
targets = d.LoadDataSetClasses("B_train");
print "Dataset loaded"
G=numpy.asarray(G)
targets =numpy.asarray(targets )
threadLock = threading.Lock()
print G.shape
vals=649
original=649
for i in range(0,1547):
print "vals= "+str(vals)+"\n"
# Create new threads
thread = myThread(i, "Thread-"+str(i),vals-original,G[:,vals-original:vals],targets)
# Add threads to thread list
threads.append(thread)
vals+=original
# Wait for all threads to complete
for t in threads:
# Start new Threads
t.start()
t.join()
#Saving the selected_indices
print "Exiting Main Thread"