generated from scotthlee/template
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.py
More file actions
66 lines (54 loc) · 1.76 KB
/
test.py
File metadata and controls
66 lines (54 loc) · 1.76 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
57
58
59
60
61
62
63
64
65
import numpy as np
import pandas as pd
import tracemalloc
import time
import seaborn as sns
from matplotlib import pyplot as plt
from importlib import reload
from kudos import optimizers as ops
from kudos import metrics
if __name__ == '__main__':
# Importing the original data
records = pd.read_csv('data/tb_data.csv')
# Making them combined
y = records.mtb.values.astype(np.uint8)
X = records.iloc[:, records.columns != 'mtb'].fillna(0)
X = X.astype(np.uint8)
# Setting up a pruner to whittle down the variables
pruner = ops.FeaturePruner()
pruner.fit(X, y, factor=5)
# Trying the different solvers on the simple problem
start = time.time()
ip = ops.IntegerProgram()
ip.fit(pruner.X, y)
end = time.time()
ip_time = end - start
start = time.time()
nola = ops.NonlinearApproximation()
nola.fit(pruner.X, y)
end = time.time()
nola_time = end - start
tracemalloc.start()
start = time.time()
fe = ops.FullEnumeration()
fe.fit(pruner.X, y, chunksize=int(1e4))
end = time.time()
fe_size, fe_peak = tracemalloc.get_traced_memory()
fe_time = end - start
tracemalloc.clear_traces()
tracemalloc.start()
start = time.time()
fe_share = ops.FullEnumeration(share_memory=True)
fe_share.fit(pruner.X, y, chunksize=int(1e4))
end = time.time()
fe_share_size, fe_share_peak = tracemalloc.get_traced_memory()
fe_share_time = end - start
# Trying the full enumeration and approximation on the compound problem
start = time.time()
fe.fit(pruner.X, y, compound=True, write_full=False)
end = time.time()
fe_comp_time = end - start
start = time.time()
nola.fit(pruner.X, y, compound=True)
end = time.time()
nola_comp_time = end - start