Exemple #1
0
    def calculate_two_step_walks(self):
        two_st_walks = now.all_pairs_number_of_walks(self._graph,2)
        G = self._graph

        for h1 in two_st_walks:
            for h2 in two_st_walks[h1]:
                if G.degree(h1) == 0 or G.degree(h2) == 0:
                    two_st_walks[h1][h2] = 0
                    continue
                two_st_walks[h1][h2] = (two_st_walks[h1][h2] + 0.0)/min(G.degree(h1),G.degree(h2))

        # This structure stores the NORMALIZED number of 2 step walks
        self._num_two_step_walks = two_st_walks
Exemple #2
0
    def calculate_two_step_walks(self):
        two_st_walks = now.all_pairs_number_of_walks(self._graph, 2)
        G = self._graph

        for h1 in two_st_walks:
            for h2 in two_st_walks[h1]:
                if G.degree(h1) == 0 or G.degree(h2) == 0:
                    two_st_walks[h1][h2] = 0
                    continue
                two_st_walks[h1][h2] = (two_st_walks[h1][h2] + 0.0) / min(
                    G.degree(h1), G.degree(h2))

        # This structure stores the NORMALIZED number of 2 step walks
        self._num_two_step_walks = two_st_walks
G = nx.read_graphml('hanja_unip.graphml', unicode)

# The 2-hanja graph projection is not connected, thus we must get the largest
# connected component of the graph.
gen = nxa.connected_components(G)
mainLst = gen.next()
G = G.subgraph(mainLst)

if nxa.is_connected(G) == False:
    print("We have a PROBLEM, Houston.")

import number_of_walks as now
import numpy as np

num_2step_walks = now.all_pairs_number_of_walks(G, 2)

num_2step_walk_dist = {}
normalized_2step_w = []
for h1 in num_2step_walks:
    for h2 in num_2step_walks[h1]:
        if h1 == h2: continue
        if num_2step_walks[h1][h2] not in num_2step_walk_dist:
            num_2step_walk_dist[num_2step_walks[h1][h2]] = 0
        num_2step_walk_dist[num_2step_walks[h1][h2]] += 1
        if num_2step_walks[h1][h2] == 0: continue
        normalized_2step_w.append(num_2step_walks[h1][h2] /
                                  ((G.degree(h1) * G.degree(h2)) + .0))

gen_99pc = np.percentile(normalized_2step_w, 99)
gen_98pc = np.percentile(normalized_2step_w, 98)

# The 2-hanja graph projection is not connected, thus we must get the largest
# connected component of the graph.
gen = nxa.connected_components(G)
mainLst = gen.next()
G = G.subgraph(mainLst)

if nxa.is_connected(G) == False:
    print("We have a PROBLEM, Houston.")

        
import number_of_walks as now
import numpy as np

num_2step_walks = now.all_pairs_number_of_walks(G,2)

num_2step_walk_dist = {}
normalized_2step_w = []
for h1 in num_2step_walks:
    for h2 in num_2step_walks[h1]:
        if h1 == h2: continue
        if num_2step_walks[h1][h2] not in num_2step_walk_dist:
            num_2step_walk_dist[num_2step_walks[h1][h2]] = 0
        num_2step_walk_dist[num_2step_walks[h1][h2]] += 1
        if num_2step_walks[h1][h2] == 0: continue
        normalized_2step_w.append(num_2step_walks[h1][h2]/((G.degree(h1)*G.degree(h2))+.0))

gen_99pc = np.percentile(normalized_2step_w,99)
gen_98pc = np.percentile(normalized_2step_w,98)
gen_97pc = np.percentile(normalized_2step_w,97)