<s> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> from pyproct . clustering . evaluation . metrics . cython . cohesion import CohesionCalculator <EOL> class SeparationCalculator ( object ) : <EOL> def __init__ ( self ) : <EOL> pass <EOL> def evaluate ( self , clustering , condensed_distance_matrix , cohesions = None ) : <EOL> all_clusters = clustering . clusters <EOL> my_cohesions_dic = { } <EOL> if ( cohesions is None ) : <EOL> cohesion_calctor = CohesionCalculator ( ) <EOL> for cluster in all_clusters : <EOL> my_cohesions_dic [ cluster ] = cohesion_calctor . evaluate_cluster ( cluster , condensed_distance_matrix ) <EOL> else : <EOL> for i , cluster in enumerate ( all_clusters ) : <EOL> my_cohesions_dic [ cluster ] = cohesions [ i ] <EOL> total_separation = <NUM_LIT:0> <EOL> for i , cluster in enumerate ( all_clusters ) : <EOL> separation = self . cluster_separation ( cluster , clustering , my_cohesions_dic [ cluster ] , condensed_distance_matrix ) <EOL> total_separation = total_separation + separation <EOL> return total_separation <EOL> def cluster_separation ( self , cluster , clustering , clustering_cohesion , condensed_distance_matrix ) : <EOL> """<STR_LIT>""" <EOL> if clustering_cohesion > <NUM_LIT:0> : <EOL> weight = <NUM_LIT:1.> / clustering_cohesion <EOL> sep_and_cohe = <NUM_LIT:0.0> <EOL> where_am_i = clustering . cluster_index ( cluster ) <EOL> for i in range ( len ( clustering . clusters ) ) : <EOL> if i != where_am_i : <EOL> c_j = clustering . clusters [ i ] <EOL> sep_and_cohe = sep_and_cohe + self . __between_cluster_distance ( cluster , c_j , condensed_distance_matrix ) <EOL> return weight * sep_and_cohe <EOL> else : <EOL> return <NUM_LIT:0.> <EOL> def __between_cluster_distance ( self , cluster_1 , cluster_2 , condensed_distance_matrix ) : <EOL> """<STR_LIT>""" <EOL> mixed_cohesion = <NUM_LIT:0> <EOL> for c_i in cluster_1 . all_elements : <EOL> for c_j in cluster_2 . all_elements : <EOL> mixed_cohesion = mixed_cohesion + condensed_distance_matrix [ c_i , c_j ] <EOL> return mixed_cohesion </s>
