def edge_centrality(net):
    values ={}
    
    bet = nx.edge_betweenness(net,normalized= True)
    flow = nx.edge_current_flow_betweenness_centrality(net,normalized= True)
    load = nx.edge_load(net)
    com = nx.communicability(net)
    bet_list =[]
    flow_list = []
    load_list = []
    com_list = []
    for edge,value in bet.iteritems() :
        origin,end = edge
        value_flow = max(flow.get(edge),flow.get((end,origin)))
        values[edge] = [value,value_flow,load.get(edge),com.get(origin).get(end)]
        bet_list.append(value)
        flow_list.append(value_flow)
        load_list.append(load.get(edge))
        com_list.append(com.get(origin).get(end))
    file3 = open("bl.csv",'w')
    for xt in [bet_list,load_list,flow_list,com_list] :
        for yt in [bet_list,load_list,flow_list,com_list] :
            corr(xt,yt,file3)
        print
        file3.write("\n")
    file3.close()
    return values
def edge_centrality(net):
    values = {}

    bet = nx.edge_betweenness(net, normalized=True)
    flow = nx.edge_current_flow_betweenness_centrality(net, normalized=True)
    load = nx.edge_load(net)
    com = nx.communicability(net)
    bet_list = []
    flow_list = []
    load_list = []
    com_list = []
    for edge, value in bet.iteritems():
        origin, end = edge
        value_flow = max(flow.get(edge), flow.get((end, origin)))
        values[edge] = [
            value, value_flow,
            load.get(edge),
            com.get(origin).get(end)
        ]
        bet_list.append(value)
        flow_list.append(value_flow)
        load_list.append(load.get(edge))
        com_list.append(com.get(origin).get(end))
    file3 = open("bl.csv", 'w')
    for xt in [bet_list, load_list, flow_list, com_list]:
        for yt in [bet_list, load_list, flow_list, com_list]:
            corr(xt, yt, file3)
        print
        file3.write("\n")
    file3.close()
    return values
 def test_p4_edge_load(self):
     G=self.P4
     c = nx.edge_load(G)
     d={(0, 1): 6.000,
        (1, 2): 8.000,
        (2, 3): 6.000}
     for n in G.edges():
         assert_almost_equal(c[n],d[n],places=3)
 def test_p4_edge_load(self):
     G=self.P4
     c = nx.edge_load(G)
     d={(0, 1): 6.000,
        (1, 2): 8.000,
        (2, 3): 6.000}
     for n in G.edges():
         assert_almost_equal(c[n],d[n],places=3)
 def test_tree_edge_load(self):
     G=self.T
     c = nx.edge_load(G)
     d={(0, 1): 24.000,
        (0, 2): 24.000,
        (1, 3): 12.000,
        (1, 4): 12.000,
        (2, 5): 12.000,
        (2, 6): 12.000}
     for n in G.edges():
         assert_almost_equal(c[n],d[n],places=3)
 def test_tree_edge_load(self):
     G=self.T
     c = nx.edge_load(G)
     d={(0, 1): 24.000,
        (0, 2): 24.000,
        (1, 3): 12.000,
        (1, 4): 12.000,
        (2, 5): 12.000,
        (2, 6): 12.000}
     for n in G.edges():
         assert_almost_equal(c[n],d[n],places=3)
 def test_k5_edge_load(self):
     G=self.K5
     c = nx.edge_load(G)
     d={(0, 1): 5.000,
        (0, 2): 5.000,
        (0, 3): 5.000,
        (0, 4): 5.000,
        (1, 2): 5.000,
        (1, 3): 5.000,
        (1, 4): 5.000,
        (2, 3): 5.000,
        (2, 4): 5.000,
        (3, 4): 5.000}
     for n in G.edges():
         assert_almost_equal(c[n],d[n],places=3)
 def test_k5_edge_load(self):
     G=self.K5
     c = nx.edge_load(G)
     d={(0, 1): 5.000,
        (0, 2): 5.000,
        (0, 3): 5.000,
        (0, 4): 5.000,
        (1, 2): 5.000,
        (1, 3): 5.000,
        (1, 4): 5.000,
        (2, 3): 5.000,
        (2, 4): 5.000,
        (3, 4): 5.000}
     for n in G.edges():
         assert_almost_equal(c[n],d[n],places=3)
    def edge_attributes(self):
        result = {}
        result['edge_betweenness_centrality'] = nx.edge_betweenness_centrality(
            self.graph)
        result['edge_load'] = nx.edge_load(self.graph)

        edge_attributes = []
        for edge in self.graph.edges():
            edge_attributes.append(
                (edge, result['edge_betweenness_centrality'][edge],
                 result['edge_load'][edge]))
        edge_attributes.insert(
            0, ['edge', 'edge_betweenness_centrality', 'edge_load'])

        return edge_attributes
def edgeCentralities(df, G):

    DF2 = pd.DataFrame(nx.edge_betweenness_centrality(G), 
    index=['edge_betweenness_centrality'])
    DF2 = DF2.T.unstack(level=0)
    DF2.columns = DF2.columns.get_level_values(1)

    DF3 = pd.DataFrame(nx.edge_current_flow_betweenness_centrality(G,normalized=True), 
    index=['edge_current_flow_betweenness_centrality'])
    DF3 = DF3.T.unstack(level=0)
    DF3.columns = DF3.columns.get_level_values(1)

    DF4 = pd.DataFrame(nx.edge_load(G), 
    index=['edge_load'])
    DF4 = DF4.T.unstack(level=0)
    DF4.columns = DF4.columns.get_level_values(1)

    DFB = pd.concat([DF2, DF3, DF4], axis=0) #buggy
    return pd.Panel({'edge_betweenness_centrality':DF2, 
                     'edge_current_flow_betweenness_centrality':DF3, 
                     'edge_load':DF4})
Пример #11
0
    def centrality(self):
        result = {}
        result['degree_centrality'] = nx.degree_centrality(self.graph)

        if self.directed == 'directed':
            result['in_degree_centrality'] = nx.in_degree_centrality(
                self.graph)
            result['out_degree_centrality'] = nx.out_degree_centrality(
                self.graph)

        result['closeness_centrality'] = nx.closeness_centrality(self.graph)
        result['betweenness_centrality'] = nx.betweenness_centrality(
            self.graph)

        # fix the tuple cant decode into json problem
        stringify_temp = {}
        temp = nx.edge_betweenness_centrality(self.graph)
        for key in temp.keys():
            stringify_temp[str(key)] = temp[key]
        result['edge_betweenness_centrality'] = stringify_temp

        if self.directed == 'undirected':
            result[
                'current_flow_closeness_centrality'] = nx.current_flow_closeness_centrality(
                    self.graph)
            result[
                'current_flow_betweenness_centrality'] = nx.current_flow_betweenness_centrality(
                    self.graph)

            stringify_temp = {}
            temp = nx.edge_current_flow_betweenness_centrality(self.graph)
            for key in temp.keys():
                stringify_temp[str(key)] = temp[key]
            result['edge_current_flow_betweenness_centrality'] = stringify_temp

            result[
                'approximate_current_flow_betweenness_centrality'] = nx.approximate_current_flow_betweenness_centrality(
                    self.graph)
            result['eigenvector_centrality'] = nx.eigenvector_centrality(
                self.graph)
            result[
                'eigenvector_centrality_numpy'] = nx.eigenvector_centrality_numpy(
                    self.graph)
            result['katz_centrality'] = nx.katz_centrality(self.graph)
            result['katz_centrality_numpy'] = nx.katz_centrality_numpy(
                self.graph)
            result['communicability'] = nx.communicability(self.graph)
            result['communicability_exp'] = nx.communicability_exp(self.graph)
            result[
                'communicability_centrality'] = nx.communicability_centrality(
                    self.graph)
            result[
                'communicability_centrality_exp'] = nx.communicability_centrality_exp(
                    self.graph)
            result[
                'communicability_betweenness_centrality'] = nx.communicability_betweenness_centrality(
                    self.graph)
            result['estrada_index'] = nx.estrada_index(self.graph)

        result['load_centrality'] = nx.load_centrality(self.graph)

        stringify_temp = {}
        temp = nx.edge_load(self.graph)
        for key in temp.keys():
            stringify_temp[str(key)] = temp[key]
        result['edge_load'] = stringify_temp
        result['dispersion'] = nx.dispersion(self.graph)

        fname_centra = self.DIR + '/centrality.json'
        with open(fname_centra, "w") as f:
            json.dump(result, f, cls=SetEncoder, indent=2)
        print(fname_centra)
def edgeload(net):
    return distri(nx.edge_load(net).values(),'edgeload')
def edgeload(net):
    return distri(nx.edge_load(net).values(), 'edgeload')
Пример #14
0
def add_load_edge(graf):
    print "Adding load to edges"
    l_dict = nx.edge_load(graf)
    nx.set_edge_attributes(graf, 'loa', l_dict)
Пример #15
0
import networkx as nx
import json
import matplotlib.cm as cm
import matplotlib.colors as colors
from networkx.readwrite import json_graph

G = nx.barabasi_albert_graph(250,1)
#G = nx.random_geometric_graph(256,.1)

cc = nx.closeness_centrality(G)
d = G.degree()
nd = nx.average_neighbor_degree(G)
eb = nx.edge_betweenness(G)
el = nx.edge_load(G)


min_cc = min(cc.values())
max_cc = max(cc.values())

for n in cc:
    cc[n] = (cc[n]-min_cc)/(max_cc-min_cc)

min_eb = min(eb.values())
max_eb = max(eb.values())

for e in eb:
    eb[e] = (eb[e]-min_eb)/(max_eb-min_eb)

min_el = min(el.values())
max_el = max(el.values())
Пример #16
0
def add_load_edge(graf):
    print "Adding load to edges"
    l_dict = nx.edge_load(graf)
    nx.set_edge_attributes(graf, 'loa', l_dict)