-
Notifications
You must be signed in to change notification settings - Fork 3
/
dimensions.py
76 lines (54 loc) · 1.97 KB
/
dimensions.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
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
import numpy as np
import implementation as impl
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import os
def compare(origDistances, data, dimensionsRange, encode):
origShape = np.shape(data)
results = dict()
new_dimension = 10
orig_dimension = origShape[1]
results = dict()
x = dimensionsRange
for key in impl.actions.iterkeys():
print key
durations = list()
distances = list()
di = list()
du = list()
for dimension in dimensionsRange:
print " %s" % dimension
action = impl.actions[key]
reduced, d = impl.reduceAndMeasure(action, data, orig_dimension, dimension)
dist = impl.measureDistances(origDistances, data, reduced, key)
du.append(d)
di.append(dist)
durations.append(np.mean(du))
distances.append(np.mean(di))
results[key] = dict()
results[key]["durations"] = durations
results[key]["distances"] = distances
plt.subplot(211)
plt.grid()
plt.xlabel("iterations")
plt.ylabel("mean distance")
for key in results.iterkeys():
plt.plot(x, results[key]["distances"], label=key)
plt.legend(loc="best")
#plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.08), fancybox=True, shadow=True, ncol=2)
plt.subplot(212)
plt.grid()
plt.xlabel("iterations")
plt.ylabel("mean duration")
for key in results.iterkeys():
plt.plot(x, results[key]["durations"], label=key)
plt.legend(loc="best")
#plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.08), fancybox=True, shadow=True, ncol=2)
outputFolder = os.path.dirname(os.path.abspath(__file__))
outputFolder = "%s/output" % outputFolder
e = ""
if encode:
e = "encode"
d = "%s-%s" % (np.min(dimensionsRange), np.max(dimensionsRange))
plt.savefig( "%s/rp_dimensions_%s_%s.png" % (outputFolder,d, e), dpi=320, bbox_inches = "tight")