-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmost_common_load_shapes.py
70 lines (56 loc) · 1.61 KB
/
most_common_load_shapes.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
import sys, math
import numpy as np
from sklearn.cluster import KMeans, MiniBatchKMeans
from numpy import linalg as LA
import matplotlib.pyplot as plt
import operator
fileName = sys.argv[1]
numberOfLoadShapes = int(sys.argv[2])
centroidMap = {}
clusterSizeMap = {}
centroidLine = False
clusterSizeLine = False
vectorLength = None
label = 0
K = None
totalShapes = 0
with open(fileName, 'r') as f:
for line in f:
if centroidLine:
coords = map(float, line.split())
if vectorLength == None:
vectorLength = len(coords)
centroidMap[label] = np.array(coords)
centroidLine = False
clusterSizeLine = True
elif clusterSizeLine:
clusterSize = map(int, line.split())[0]
clusterSizeMap[label] = clusterSize
centroidLine = True
clusterSizeLine = False
label += 1
totalShapes += clusterSize
else:
K = int(line)
centroidLine = True
sortedClusterMapEntries = sorted(clusterSizeMap.items(), key=operator.itemgetter(1), reverse=True)
sortedClusterSizeLabels = map(lambda x: x[0], sortedClusterMapEntries)
mostCommonClusterSizeLabels = sortedClusterSizeLabels[:numberOfLoadShapes]
x = range(1, 25)
w = math.ceil((numberOfLoadShapes) ** .5)
h = math.ceil((numberOfLoadShapes) ** .5)
for i in range(1, numberOfLoadShapes + 1):
label = mostCommonClusterSizeLabels[i - 1]
y = centroidMap[label]
plt.subplot(h, w, i)
plt.scatter(x, y)
clusterSize = clusterSizeMap[label]
percent = 100. * clusterSize / totalShapes
plt.title(str(percent) + "%")
plt.xlabel("Hour")
plt.ylabel("Norm. Usage")
plt.xlim(0, 25)
plt.ylim(0.003, 0.040)
#plt.tight_layout()
plt.subplots_adjust(wspace=0.7, hspace=0.7)
plt.show()