test += 1 aux_clusters[curr_indx].remove(k) aux_clusters[pred_idx].append(k) self.obj_to_cluster[k] = pred_idx self.clusters = aux_clusters return test def objective_function(self): print("calculating J_kcm_f_gh...") result = 0. self.part2 = self.__all_against_all_cluster_sum() for i in range(self.c): for k in self.clusters[i]: result += 1 - self.__object_against_cluster_sum(k, i) + self.part2[i] return result def rand_score(self): return adjusted_rand_score(labels_true=self.y, labels_pred=self.obj_to_cluster.values()) if __name__ == "__main__": import pandas as pd from load_data import Dataset datadir='../../data/segmentation_2.test' df = pd.read_csv(datadir, sep=',') mydata = Dataset() mydata.load(df, 'rgb') kcm = KCM_F_GH(c=7, p=mydata.X.values.shape[1], data=mydata)
if __name__ == '__main__': datadir = '../../data/segmentation_2.test' result_dir = '../../results/clustering' result_file = 'results' bresult_file = 'best_result' view = 'rgb' norm = True result_file = '{}{}_{}'.format(view, '_norm' if norm else '', result_file) bresult_file = '{}{}_{}'.format(view, '_norm' if norm else '', bresult_file) df = pd.read_csv(datadir, sep=',') mydata = Dataset() mydata.load(df, view) # Variáveis para armazenar resultado da execução do algoritmo res_obj_function = [] res_cluster = [] res_obj_to_cluster = [] res_hp = [] res_ari = [] # adjusted rand indexes list res_J = [] # uma lista com a melhor serie de convergência de J # executar o algoritmo 100x for epoch in range(5): start_total_time = time.time() # inicialização do algoritmo kcm = KCM_F_GH(c=7, p=mydata.X.shape[1], data=mydata, norm=norm) kcm.initialization() # parte iterativa do algoritmo