-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdemo.py
More file actions
52 lines (43 loc) · 1.27 KB
/
demo.py
File metadata and controls
52 lines (43 loc) · 1.27 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
import os
import matplotlib.pyplot as plt
import subprocess
import local_pyutils
from anomalyframework import liblinear_utils
from anomalyframework import run
# Open logging file: stdout
local_pyutils.open_stdout_logger()
# Build project files
subprocess.check_call('cmake -Bbuild -H.', shell=True)
os.chdir('build')
try:
subprocess.check_output('make')
os.chdir('../')
except:
os.chdir('../')
raise
# Mark this directory as root
os.environ['ANOMALYROOT'] = os.path.abspath(os.path.curdir)
print(os.environ['ANOMALYROOT'])
infile_features = 'data/input/features/Avenue/03_feaPCA_new.train'
infile_features = os.path.abspath(os.path.expanduser(infile_features))
if not os.path.isfile(infile_features):
raise ValueError('{} does not exist.'.format(infile_features))
# Run anomaly detection
a, pars = run.main(infile_features=infile_features, n_shuffles=10)
import pickle
pickle.dump(dict(a=a, pars=pars), open(infile_features.replace('.train', '_res.pickle'),'wb'))
# Display
if(0):
X, y = liblinear_utils.read(pars.paths.files.infile_features, False)
plt.figure(1)
plt.cla()
plt.plot(a/(1.0-a))
plt.figure(2)
plt.cla()
plt.plot(a)
plt.figure(3)
plt.cla()
X = X.toarray()
plt.imshow(X.T)
plt.title('X')
plt.show(block=True)