aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCalvin <calvin@EESI>2013-03-19 16:37:40 -0400
committerCalvin <calvin@EESI>2013-03-19 16:37:40 -0400
commit187ef9e49088d89a41a5c242c6e29a8c09a71b33 (patch)
treeb9a0f9f98b00d57fc6661fd4abdeaae148318cb1
parent3fe802a182d16760b8dbab0533458d2aaf225221 (diff)
working on feast ctypes
-rw-r--r--python/demo_feast_wrapper.py8
-rw-r--r--python/feast.py25
2 files changed, 28 insertions, 5 deletions
diff --git a/python/demo_feast_wrapper.py b/python/demo_feast_wrapper.py
index 0913788..6642ca8 100644
--- a/python/demo_feast_wrapper.py
+++ b/python/demo_feast_wrapper.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-
+import feast
import numpy as np
##################################################################
@@ -34,7 +34,7 @@ data, labels = 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
+method = 'JMI' # feature selection algorithm
print '---> Information'
@@ -43,7 +43,5 @@ print ' :n_features - ' + str(n_features)
print ' :n_select - ' + str(n_select)
print ' :algorithm - ' + str(method)
+selected_features = feast.select(data, labels, n_observations, n_features, n_select, method)
-# Calvin: feature selection wrapper goes here
-#selected_features = feast(data, labels, n_observations, n_features, n_select, \
-# method) \ No newline at end of file
diff --git a/python/feast.py b/python/feast.py
new file mode 100644
index 0000000..bc6fc93
--- /dev/null
+++ b/python/feast.py
@@ -0,0 +1,25 @@
+import numpy as np
+from ctypes import *
+
+def select(data, labels, n_observations, n_features, n_select, method):
+
+ selected_features = []
+
+ try:
+ libFSToolbox = CDLL("libFSToolbox.so");
+ except:
+ print "Error: could not find libFSToolbox"
+ exit()
+
+# JMI(n_features_to_ret, int n_samples, int n_feats, double *featureMatrix, double *classcol, outputFeatures);
+ c_output = (c_double * n_select)
+ c_n_observations = c_int(n_observations)
+ c_n_select = c_int(n_select)
+ c_n_features = c_int(n_features)
+ c_data = (c_double * n_observations * n_features)(*data.tolist())
+ c_labels = (c_int * len(labels))(*labels)
+
+ # right now just call only JMI, work out the rest later
+ libFSToolbox.JMI(c_n_select, c_n_observations, c_n_features, c_data, c_labels, c_output)
+
+ return selected_features