@@ -0,0 +1,2170 @@
+from pygraphc.similarity.CosineSimilarity import CosineSimilarity%0Afrom itertools import product%0A%0A%0Aclass XieBeniIndex(object):%0A    def __init__(self, clusters, preprocessed_logs, log_length):%0A        self.clusters = clusters%0A        self.preprocessed_logs = preprocessed_logs%0A        self.log_length = log_length%0A        self.cluster_centroids = %7B%7D%0A        self.cluster_total_nodes = %7B%7D%0A        self.total_cluster = 0%0A        self.__get_all_cluster_properties()%0A%0A    def __get_centroid(self, cluster):%0A        # centroid for a particular cluster%0A        centroid = ''%0A        for log_id in cluster:%0A            centroid += self.preprocessed_logs%5Blog_id%5D%0A%0A        return centroid%0A%0A    def __get_all_cluster_properties(self):%0A        for cluster_id, log_ids in self.clusters.iteritems():%0A            self.cluster_centroids%5Bcluster_id%5D = self.__get_centroid(log_ids)%0A            self.cluster_total_nodes%5Bcluster_id%5D = len(log_ids)%0A        self.total_cluster = len(self.clusters.keys())%0A%0A    @staticmethod%0A    def __get_distance(source, dest):%0A        cs = CosineSimilarity()%0A        distance = cs.get_cosine_similarity(source, dest)%0A        return distance%0A%0A    def __get_compactness(self):%0A        all_distances = %5B%5D%0A        for cluster_id, log_ids in self.clusters.iteritems():%0A            cluster_distances = %5B%5D%0A            for log_id in log_ids:%0A                distance = self.__get_distance(self.preprocessed_logs%5Blog_id%5D, self.cluster_centroids%5Bcluster_id%5D)%0A                cluster_distances.append(pow(distance, 2))%0A            all_distances.append(sum(cluster_distances))%0A%0A        compactness = sum(all_distances)%0A        return compactness%0A%0A    def __get_separation(self):%0A        all_distances = %5B%5D%0A        for cluster_id1, cluster_id2 in product(xrange(self.total_cluster), repeat=2):%0A            distance = self.__get_distance(self.cluster_centroids%5Bcluster_id1%5D, self.cluster_centroids%5Bcluster_id2%5D)%0A            all_distances.append(pow(distance, 2))%0A%0A        separation = self.log_length * min(all_distances)%0A        return separation%0A%0A    def get_xie_beni(self):%0A        xb_index = self.__get_separation() / self.__get_compactness()%0A        return xb_index%0A%0A

Add generic Xie-Beni index