aboutsummaryrefslogtreecommitdiff
path: root/python/demo_feast_wrapper.py
blob: 0a9633a93ba2aa56bf0b9ce6a5b23d0db75cd9eb (plain)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python 
from feast import *
import numpy as np
import import_data 


def check_result(selected_features, n_relevant):
	selected_features = sorted(selected_features)
	success = True
	for k in range(n_relevant):
		if k != selected_features[k]:
			success = False
	return success



n_relevant = 5
data_source = 'uniform'    # set the data set we want to test


if data_source == 'uniform':
	data, labels = import_data.uniform_data(n_relevant = n_relevant)
elif data_source == 'digits':
	data, labels = import_data.read_digits('digit.txt')

n_observations = len(data)					# number of samples in the data set
n_features = len(data.transpose())	# number of features in the data set
n_select = 15												# how many features to select
method = 'JMI'											# feature selection algorithm


print '---> Information'
print '     :n_observations - ' + str(n_observations)
print '     :n_features     - ' + str(n_features)
print '     :n_select       - ' + str(n_select)
print '     :algorithm      - ' + str(method)
print ' '
print '---> Running unit tests on FEAST 4 Python... '


#################################################################
#################################################################
print '       Running BetaGamma... '
sf = BetaGamma(data, labels, n_select, beta=0.5, gamma=0.5)
if check_result(sf, n_relevant) == True:
	print '          BetaGamma passed!'
else:
	print '          BetaGamma failed!'


#################################################################
#################################################################
print '       Running CMIM... '
sf = CMIM(data, labels, n_select)
if check_result(sf, n_relevant) == True:
	print '          CMIM passed!'
else:
	print '          CMIM failed!'


#################################################################
#################################################################
print '       Running CondMI... '
sf = CondMI(data, labels, n_select)
if check_result(sf, n_relevant) == True:
	print '          CondMI passed!'
else:
	print '          CondMI failed!'


#################################################################
#################################################################
print '       Running DISR... '
sf = DISR(data, labels, n_select)
if check_result(sf, n_relevant) == True:
	print '          DISR passed!'
else:
	print '          DISR failed!'


#################################################################
#################################################################
print '       Running ICAP... '
sf = ICAP(data, labels, n_select)
if check_result(sf, n_relevant) == True:
	print '          ICAP passed!'
else:
	print '          ICAP failed!'


#################################################################
#################################################################
print '       Running JMI... '
sf = JMI(data, labels, n_select)
if check_result(sf, n_relevant) == True:
	print '          JMI passed!'
else:
	print '          JMI failed!'


#################################################################
#################################################################
print '       Running mRMR... '
sf = mRMR(data, labels, n_select)
if check_result(sf, n_relevant) == True:
	print '          mRMR passed!'
else:
	print '          mRMR failed!'

print '---> Done unit tests!'