Gc nodes centralization

  • (import "Gc_negative.gml")
  • calculate degree centralization

In [6]:
import networkx as nx
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import os
from glob import glob

#Gc_files = glob('../output/network/Gc_negative.gml')
#Gc_files = glob('../output/network/Gc_positive.gml')
Gc_files = glob('../output/network/Gc_neutral.gml')

def calculate_graph_inf(graph):
    graph.name = filename
    info = nx.info(graph)
    print info

for graph_num, gml_graph in enumerate(Gc_files):
    graph = nx.read_gml(gml_graph)
    (filepath, filename) = os.path.split(gml_graph)
    print('-' * 10)
    print(gml_graph)
    calculate_graph_inf(graph)


----------
../output/network/Gc_neutral.gml
Name: Gc_neutral.gml
Type: MultiGraph
Number of nodes: 171
Number of edges: 221
Average degree:   2.5848

In [3]:
# negative

N = graph.order()
degrees = graph.degree().values()
max_in = max(degrees)
centralization = float((N*max_in - sum(degrees)))/(N-1)**2
centralization


Out[3]:
0.11493531670265107

In [5]:
# positive

N = graph.order()
degrees = graph.degree().values()
max_in = max(degrees)
centralization = float((N*max_in - sum(degrees)))/(N-1)**2
centralization


Out[5]:
0.11025755301182211

In [8]:
# neutral

N = graph.order()
degrees = graph.degree().values()
max_in = max(degrees)
centralization = float((N*max_in - sum(degrees)))/(N-1)**2
centralization


Out[8]:
0.17996539792387542

In [ ]: