forked from Undin/recommender-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MetaFeatures.py
executable file
·41 lines (28 loc) · 988 Bytes
/
MetaFeatures.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
import numpy as np
import sys
import subprocess
class MetaFeatures:
def __init__(self, objects, features, meta):
self.objects = objects
self.features = features
self.meta = meta
self.proc = subprocess.Popen(["java", "-cp", "jars/*", "ru.ifmo.ctddev.ml.mfe.BinaryExtractor", str(objects), str(features)], stdin = subprocess.PIPE, stdout = subprocess.PIPE)
def extract(self, dataset):
self.proc.stdin.write(dataset.tobytes())
self.proc.stdin.flush()
return np.frombuffer(self.proc.stdout.read(self.meta * 8), dtype = np.float64, count = self.meta)
def close(self):
self.proc.kill()
objects = 128
features = 16
meta = 23 + 3 # 23 MetaFeatures + 3 Landmarks
mf = MetaFeatures(objects, features, meta)
dataset = np.random.rand(objects, features)
print(dataset)
result = mf.extract(dataset)
print(result)
dataset = np.random.rand(objects, features)
print(dataset)
result = mf.extract(dataset)
print(result)
mf.close()