示例#1
0
def test_KM_config():
	# KM--config =========================
	G=nx.karate_club_graph()
	print("Running KM_config ...")
	km = cpa.KM_config()
	km.detect(G)
	pair_id = km.get_pair_id()
	coreness = km.get_coreness()
	sig_pair_id, sig_coreness, significance, p_values = cpa.qstest(pair_id, coreness, G, km)
edges = mpatches.Patch(color='white', label='Edge Length - Indicator of Trust Inversely')
plt.legend(handles=[trusted, untrusted, size], loc='lower right')

pos = nx.spring_layout(DG, k=0.25)
sizes = [get_size(n) for n in DG]
colors = [get_color(n) for n in DG]

nc = nx.draw_networkx_nodes(DG, pos, nodelist=DG.nodes(), node_size=sizes, linewidths=2.0, node_color=colors, cmap=plt.cm.RdYlGn, alpha=0.8)

ec = nx.draw_networkx_edges(DG, pos, arrows=True, alpha=0.08)
ax = plt.axis('off')
plt.show()

import cpalgorithm as cp

km = cp.KM_config();
km.detect(DG)
c = km.get_pair_id()
x = km.get_coreness()

#for k, v in sorted(c.items()):
#    print(k, v)

print("END! END! END! END! ")
#sig_pair_id, sig_coreness, significance, p_values = cp.qstest(c, x, DG, km)

#x_sorted = {k: v for k, v in sorted(x.items(), key=lambda y: y[1])}

#for k, v in x_sorted.items():
#    print(k, v)
示例#3
0
import pandas as pd
import networkx as nx
import cpalgorithm as cp

G = nx.karate_club_graph()
be = cp.KM_config(num_runs=100000)
be.detect(G)
c = be.get_pair_id()
x = be.get_coreness()

print('Name\tPairID\tCoreness')
for key, value in sorted(c.items(), key=lambda x: x[1]):
    print('%s\t%d\t%f' % (key, c[key], x[key]))
示例#4
0
import networkx as nx
import pandas as pd
import cpalgorithm as cp

df = pd.read_csv('Using dataset.csv', sep=',')  #load data from dataset

G = nx.from_pandas_edgelist(df)

algorithm = cp.KM_config()
algorithm.detect(G)
c = algorithm.get_pair_id()
x = algorithm.get_coreness()

print('Name\tPairID\tCoreness')
for key, value in sorted(c.items(), key=lambda x: x[1]):
    print('%s\t%d\t%f' % (key, c[key], x[key]))
示例#5
0
def detect_core_periphery(G):
    algorithm = cp.KM_config()
    algorithm.detect(G)
    c = algorithm.get_pair_id()
    x = algorithm.get_coreness()