Beispiel #1
0
    def show_result():
        m = path.get()

        #input user graph
        with open(m) as csvfile:  #read the csv file, row by row
            reader = csv.reader(csvfile)
            next(reader)
            source = []
            target = []
            value = []
            for row in reader:
                source.append(int(row[0]))
                target.append(int(row[1]))
                value.append(int(row[2]))

        util.create_graph(G, source, target, value)
        degrees = G.degree(G.nodes(), None)
        list_degrees = list(degrees)
        in_degree = G.in_degree(degrees)
        out_degree = G.out_degree(degrees)
        messagebox.showinfo(title='Result',
                            message=('the degrees of the nodes are:', degrees))
        if selection == "is_g":
            messagebox.showinfo(title='Result',
                                message=('the result of is_graphical:',
                                         nx.is_graphical(degrees)))
        elif selection == "is_d":
            messagebox.showinfo(title='Result',
                                message=('the result of is_digraphical:',
                                         nx.is_digraphical(
                                             in_degree, out_degree)))
        elif selection == "is_m":
            messagebox.showinfo(title='Result',
                                message=('the result of is_multigraphical:',
                                         nx.is_multigraphical(degrees)))
        elif selection == "is_p":
            messagebox.showinfo(title='Result',
                                message=('the result of is_psuedographical:',
                                         nx.is_pseudographical(degrees)))
        elif selection == "is_hh":
            messagebox.showinfo(
                title='Result',
                message=(
                    'the result of is_havel_hakimi:',
                    nx.is_valid_degree_sequence_havel_hakimi(list_degrees)))
        elif selection == "is_eg":
            messagebox.showinfo(
                title='Result',
                message=(
                    'the result of is_erdos=galli:',
                    nx.is_valid_degree_sequence_erdos_gallai(list_degrees)))

        util.draw_graph(G)
Beispiel #2
0
def get_geo_dist(X, adaptive_neighbor=False, K='auto', local_intr_dim=False, verbose=0):
    
    m = X.shape[0]
    
    if adaptive_neighbor:
        
        if local_intr_dim:
            local_dims = mide(X)[1]
        else:
            local_dims = mide(X)[0]
            
        nbrs = select_neighborhood(X, local_dims, verbose=2) # list of neighborhood indices
        
        A = np.zeros((m, m)) # adjacency matrix
        D = np.zeros((m, m)) # adjacency matrix with pairwise distance
        for i in range(m):
            A[i, nbrs[i]] = np.ones((len(nbrs[i]),))
            for nbr in nbrs[i]:
                D[i, nbr] = np.linalg.norm(X[i] - X[nbr])
        
        G = graph_shortest_path(D, directed=False) # shortest path graph
        
    else:
        
        if K == 'auto':
            k_min, k_max = get_k_range(X)
            K = k_max
        
        G = create_graph(X, K, verbose=verbose)
            
    return G
Beispiel #3
0
def run(state, inp_, out, file_name):
    util.create_fsm(state, inp_, out, file_name)
    g, g_data = util.create_graph(file_name)
    input_size = int(math.pow(2, inp_))
    # output_size = int(math.pow(2, out))
    test_suite_w = w_method.run(g, g_data, input_size)

    # test_suite_sna = sna_method.run(g, g_data, input_size)
    # kill_w_ = mutation_analysis.run(g_data, test_suite_w, output_size)
    # kill_sna_ = mutation_analysis.run(g_data, test_suite_sna, output_size)
    # return kill_w_, kill_sna_
    return test_suite_w
Beispiel #4
0
repeated = 5
experiment = 10

start = 2
finish = 30

betweenness = []
normal = []
degree = []
eigenvector = []
closeness = []
clustering = []

for output_ in range(start, finish):
    util.create_fsm(state_, input_, output_, file_name)
    G, g_data = util.create_graph(file_name)
    input_size = int(math.pow(2, input_))
    test_suite = w_method.run(G, g_data, input_size)
    # ---------------edges----------------------
    betweenness_centrality_edges = sna.edge_betweenness_centrality(G, 0.1)
    # sna_load_edges = sna.edge_load_centrality(G, 0.2)
    # ---------------nodes----------------------
    degree_centrality_nodes = sna.degree_centrality(G, 0.5)
    betweenness_centrality_nodes = sna.betweenness_centrality(G, 0.5)
    eigenvector_centrality_nodes = sna.eigenvector_centrality(G, 0.5)
    closeness_centrality_nodes = sna.closeness_centrality(G, 0.5)
    clustering_coefficient_nodes = sna.clustering(G, 0.5)
    # g_sna_harmonic = sna.harmonic_centrality(G, 0.4)
    # g_load_centrality = sna.load_centrality(G, 0.4)
    # g_sna_edge_square = sna.square_clustering(G, 0.4)
    # g_sna_average_neighbor_degree = sna.average_neighbor_degree(G, 0.4)
Beispiel #5
0
def evaluate(adjacency_path=None,
             node_label_folder=None,
             all_gene_path=None,
             train_gene_folder=None,
             train_label_folder=None,
             n_iters=None,
             n_hops=None,
             n_clusters=None,
             svm_paras=None,
             save_folder=None):

    all_genes = util.load_list_from_file(all_gene_path)
    number_svm_parameters = len(svm_paras)

    dict_gene_idx = {}
    for idx, gene in enumerate(all_genes):
        dict_gene_idx[gene] = idx

    graph = util.create_graph(adjacency_path=adjacency_path)

    for n_cluster in n_clusters:
        util.node_labeling(g=graph,
                           label_path=node_label_folder + str(n_cluster))
        for n_iter in n_iters:

            WLvect = WLVectorizer(r=n_iter)
            iters_features = WLvect.transform([graph])
            M = iters_features[0][0]
            for iter_id in range(1, n_iter + 1):
                M = M + iters_features[iter_id][0]
            print 'Done WL compuation'
            sys.stdout.flush()

            for n_hop in n_hops:
                print 'Begining DWL compuation'
                sys.stdout.flush()
                G = util.deepwl(graph=graph, feature_matrix=M, n_hop=n_hop)
                print "Size of G", G.shape

                print 'Done DWL compuation'
                sys.stdout.flush()

                for disease_idx in range(12):
                    list_training_genes = util.load_list_from_file(
                        train_gene_folder + str(disease_idx))
                    list_training_labels = util.load_list_from_file(
                        train_label_folder + str(disease_idx))
                    list_training_labels = [
                        int(e) for e in list_training_labels
                    ]
                    list_qscores = [[] for i in range(number_svm_parameters)]

                    for gene_idx, gene in enumerate(list_training_genes):
                        list_training_genes_del = list_training_genes[:]
                        del list_training_genes_del[gene_idx]
                        training_genes_idx = [
                            dict_gene_idx[g] for g in list_training_genes_del
                        ]

                        list_training_labels_del = list_training_labels[:]
                        del list_training_labels_del[gene_idx]

                        unknown_genes_idx = [dict_gene_idx[gene]]
                        for idx in range(len(all_genes)):
                            if (idx not in training_genes_idx) and (
                                    idx != dict_gene_idx[gene]):
                                unknown_genes_idx.append(idx)

                        Mtr = util.extract_submatrix(training_genes_idx,
                                                     training_genes_idx, G)
                        M_unknown = util.extract_submatrix(
                            unknown_genes_idx, training_genes_idx, G)

                        for idx_svm, svm_para in enumerate(svm_paras):
                            clf = svm.SVC(C=svm_para, kernel='precomputed')
                            clf.fit(Mtr, list_training_labels_del)
                            scores = clf.decision_function(M_unknown)
                            len_scores = len(scores)
                            qscore = float(
                                sum([int(scores[0] > val)
                                     for val in scores])) / len_scores
                            list_qscores[idx_svm].append(qscore)
                    # computing auc
                    save_lines = []
                    for qscores_idx, qscores in enumerate(list_qscores):
                        fpr, tpr, thresholds = metrics.roc_curve(
                            list_training_labels, qscores, pos_label=1)
                        auc = metrics.auc(fpr, tpr)

                        line = str(n_cluster) + "_" + str(n_iter) + "_" + str(
                            n_hop) + "_" + str(qscores_idx) + ":\t" + str(
                                auc) + "\n"
                        save_lines.append(line)

                    f = open(save_folder + str(disease_idx), 'w')
                    f.writelines(save_lines)
                    f.close()