-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBuildHistogram.py
55 lines (42 loc) · 1.18 KB
/
BuildHistogram.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
import numpy as np
from numpy import *
from histogram import *
#import matplotlib.pyplot as plt
from cluster import KMeansClustering
import numpy as np
from numpy import vstack,array
from scipy.cluster.vq import kmeans,vq
from cluster import KMeansClustering
WaitTimeArray = np.load('Fuck.npy')
np.vstack(WaitTimeArray)
centroids,_ = kmeans(WaitTimeArray,40, iter=50,thresh=1e-10)
clusters,_ = vq(WaitTimeArray,centroids)
print "The centroids are: " + repr(centroids)
print "The result of clustering is :" + repr(clusters)
NumCluster = len(centroids)
ClusterMap = {}
for item in clusters:
if(ClusterMap.has_key(item)):
newValue = ClusterMap.get(item) + 1
ClusterMap[item] = newValue
else:
ClusterMap[item] = 1
print "The CLustering is " + repr(ClusterMap)
Count = list()
for key in ClusterMap:
Count.append(ClusterMap[key])
Count = np.array(Count)
SortIndex = np.argsort(centroids)
Count[SortIndex]
'''
bins = arange(-0.001, max(WaitingTime)+0.001, 0.001)
Histogram, bin_edges = np.histogram(WaitingTime,bins)
h = histogram("Fuck",[('tof',bins)])
'''
'''
plt.hist(WaitingTime,bins)
plt.title("Fuck")
plt.xlabel("Bucket")
plt.ylabel("Frequency")
plt.show()
'''