def visualize_col(): """ """ adj_matrix = col_matrix(col_k, nnc_mps, agreement_matrix, nnc_arbit, mps) classes = get_equiv_classes(nnc_mps, agreement_matrix, nnc_arbit, mps) classes_set = set(classes) classes_set.remove(-1) num_classes = len(classes_set) classes_ord = list(classes_set) classes_ord.sort() class_indices = {classes_ord[i]: i for i in range(num_classes)} class_sizes = [classes.count(cls) for cls in classes_ord] groups = [None for i in range(len(classes))] for i in range(len(classes_ord)): class_index = i rel_p = [mp[1][0] for mp in mps if classes[mps.index(mp)] == classes_ord[class_index]] counts = [rel_p.count(rel_p[j]) for j in range(len(rel_p))] dominant = rel_p[counts.index(max(counts))] groups[i] = dominant names = [str(i) for i in range(len(adj_matrix))] #groups = [str(i) for i in range(len(adj_matrix))] write_json_graph_general(adj_matrix, names, groups, filename = "viz/col/" + agr_method + '_' + str(start_session) + '_' + str(end_session) + 'minsess' + str(min_sessions) + '_' + 'k=' + str(col_k) + '_' + str(nnc_arbit) + ".json")
def visualize_col_equiv(): """ """ adj_matrix = general_equiv(col_matrix(col_k, nnc_mps, agreement_matrix, nnc_arbit, mps), nnc_arbit) names = [str(i) for i in range(len(adj_matrix))] groups = [str(i) for i in range(len(adj_matrix))] write_json_graph_general(adj_matrix, names, groups, filename = "viz/coleq/" + agr_method + '_' + str(start_session) + '_' + str(end_session) + 'minsess' + str(min_sessions) + '_' + 'k=' + str(col_k) + '_' + str(nnc_arbit) + ".json")
def visualize_sen_avg(): """ """ adj_matrix = col_matrix(col_k, sen_nnc_mps, sen_agreement_matrix, nnc_arbit, sen_mps) classes = get_equiv_classes(sen_nnc_mps, sen_agreement_matrix, nnc_arbit, sen_mps) classes_set = set(classes) classes_set = [thing for thing in classes_set if thing != -1] num_classes = len(classes_set) classes_ord = list(classes_set) classes_ord.sort() class_indices = {classes_ord[i]: i for i in range(num_classes)} class_sizes = [classes.count(cls) for cls in classes_ord] groups = [None for i in range(len(classes))] for i in range(len(classes_ord)): class_index = i rel_p = [mp[1][0] for mp in sen_mps if classes[sen_mps.index(mp)] == classes_ord[class_index]] counts = [rel_p.count(rel_p[j]) for j in range(len(rel_p))] dominant = rel_p[counts.index(max(counts))] groups[i] = dominant names = [str(classes.count(classes_ord[i])) for i in range(len(adj_matrix))] #groups = [str(i) for i in range(len(adj_matrix))] lis = [] for row in adj_matrix: lis += row lis = [thing for thing in lis if thing != 0] average = float(sum(lis))/len(lis) for i in range(len(adj_matrix)): for j in range(len(adj_matrix)): if adj_matrix[i][j] < average: adj_matrix[i][j] = 0 else: adj_matrix[i][j] = 1 write_json_graph_general(adj_matrix, names, groups, filename = "viz/col/sen" + str(sen_n) + agr_method + '_' + str(sen_start_session) + '_' + str(sen_end_session) + 'minsess' + str(sen_min_sessions) + '_' + 'k=' + str(col_k) + '_' + str(nnc_arbit) + "avg.json")
work[i].remove(j) work[j].remove(i) left -= 2 comp, C = compon(work) qual = quality(adj, elen, comp, C, total) print qual if qual > top_qual: top_qual = qual top_comp = comp[:] return top_comp if __name__ == '__main__': import cPickle as pickle from global_parameters import (mps, filename_agr, agr_method, min_sessions, start_session, end_session, nnc_k, nnc_mps, nnc_internal, col_k, nnc_arbit, none_value) f = open('data/full_voting_data.pkl', 'rb') mps = pickle.load(f) f.close() f = open(filename_agr, 'rb') agreement_matrix = pickle.load(f) common_session_matrix = pickle.load(f) f.close() from nnc import col_matrix print cluster(col_matrix(col_k, nnc_mps, agreement_matrix, nnc_arbit, mps))