-
Notifications
You must be signed in to change notification settings - Fork 14
/
online_clustering.py
executable file
·34 lines (29 loc) · 1.16 KB
/
online_clustering.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
import settings
import time
from tsa import TSA
class OnlineClustering(object):
"""OnlineClustering: Algorithms to perform online clustering over items"""
def __init__(self, debug, universe, bucket_chain, clusters):
self.debug = debug
self.universe = universe
self.bucket_chain = bucket_chain
self.clusters = clusters
self.tsa = TSA(debug, universe, bucket_chain, clusters)
def pre_clustering_work(self):
if settings.tsa == True:
self.debug.log("Pre-clustering work...")
operation_time = time.time()
self.tsa.compute()
self.debug.log("\tFinished in: "+str(time.time()-operation_time))
def online_clustering(self):
self.debug.log("Clustering...")
operation_time = time.time()
for item in self.bucket_chain.analyzed_bucket.items:
max_sim_val, max_sim_cluster = self.clusters.get_max_similarity(item)
if max_sim_val > settings.merge_threshold:
self.clusters.merge_item(max_sim_cluster, item)
else:
self.clusters.create_cluster(item)
self.debug.log("\tFinished in: "+str(time.time()-operation_time))
if self.clusters.centroid_counts is not None:
self.debug.log("\tCentroids shape: "+str(self.clusters.centroid_counts.shape))