cpnet package
Submodules
cpnet.BE module
- class cpnet.BE.BE(num_runs=10)
Bases:
CPAlgorithmBorgatti Everett algorithm.
Algorithm for finding single core-periphery pair in networks.
Borgatti and M. G. Everett. Models of core/periphery structures. Social Networks, 21, 375–395, 2000
>>> import cpnet >>> be = cpnet.BE() >>> be.detect(G) >>> pair_id = be.get_pair_id() >>> coreness = be.get_coreness()
Note
[ ] weighted
[ ] directed
[ ] multiple groups of core-periphery pairs
[ ] continuous core-periphery structure
- detect(G)
Detect core-periphery structure.
- Parameters
G (networkx.Graph or scipy sparse matrix) – Graph
- Returns
None
- Return type
None
cpnet.CPAlgorithm module
cpnet.Cucuringu module
- class cpnet.Cucuringu.LapCore(beta=0.1)
Bases:
CPAlgorithmLapCore algorithm.
Cucuringu, P. Rombach, S. H. Lee, and M. A. Porter Detection of core-periphery structure in networks using spectral methods and geodesic paths. Euro. J. Appl. Math., 27:846–887, 2016.
>>> import cpnet >>> lc = cpnet.LapCore() >>> lc.detect(G) >>> pair_id = lc.get_pair_id() >>> coreness = lc.get_coreness()
Note
[ ] weighted
[ ] directed
[ ] multiple groups of core-periphery pairs
[ ] continuous core-periphery structure
- detect(G)
Detect core-periphery structure.
- Parameters
G (networkx.Graph or scipy sparse matrix) – Graph
- class cpnet.Cucuringu.LapSgnCore(beta=0.1)
Bases:
CPAlgorithmLowSgnCore algorithm.
Cucuringu, P. Rombach, S. H. Lee, and M. A. Porter Detection of core-periphery structure in networks using spectral methods and geodesic paths. Euro. J. Appl. Math., 27:846–887, 2016.
>>> import cpnet >>> lsc = cpnet.LapSgnCore() >>> lsc.detect(G) >>> pair_id = lsc.get_pair_id() >>> coreness = lsc.get_coreness()
Note
[ ] weighted
[ ] directed
[ ] multiple groups of core-periphery pairs
[ ] continuous core-periphery structure
- detect(G)
Detect a single core-periphery pair.
- Parameters
G (networkx.Graph or scipy sparse matrix) – Graph
- class cpnet.Cucuringu.LowRankCore(beta=0.1)
Bases:
CPAlgorithmLowRankCore algorithm.
Cucuringu, P. Rombach, S. H. Lee, and M. A. Porter Detection of core-periphery structure in networks using spectral methods and geodesic paths. Euro. J. Appl. Math., 27:846–887, 2016.
>>> import cpnet >>> lrc = cpnet.LowRankCore() >>> lrc.detect(G) >>> pair_id = lrc.get_pair_id() >>> coreness = lrc.get_coreness()
Note
[ ] weighted
[ ] directed
[ ] multiple groups of core-periphery pairs
[ ] continuous core-periphery structure
- detect(G)
Detect a single core-periphery pair.
- Parameters
G (networkx.Graph or scipy sparse matrix) – Graph
cpnet.Divisive module
- class cpnet.Divisive.Divisive(num_runs=10)
Bases:
CPAlgorithmDivisive algorithm.
This algorithm partitions a network into communities using the Louvain algorithm. Then, it partitions each community into a core and a periphery using the BE algorithm. The quality of a community is computed by that equipped with the BE algorithm.
Kojaku and N. Masuda. Core-periphery structure requires something else in the network. New Journal of Physics, 20(4):43012, 2018
>>> import cpnet >>> alg = cpnet.Divisive() >>> alg.detect(G) >>> pair_id = alg.get_pair_id() >>> coreness = alg.get_coreness()
Note
[x] weighted
[ ] directed
[x] multiple groups of core-periphery pairs
[ ] continuous core-periphery structure
- detect(G)
Detect core-periphery structure.
- Parameters
G (networkx.Graph or scipy sparse matrix) – Graph
- Returns
None
- Return type
None
cpnet.KM_ER module
- class cpnet.KM_ER.KM_ER(num_runs=10)
Bases:
CPAlgorithmKojaku-Masuda algorithm with the Erdos-Renyi random graph.
This algorithm finds multiple core-periphery pairs in networks.
Kojaku and N. Masuda. Finding multiple core-periphery pairs in network. Phys. Rev. 96(5):052313, 2017
>>> import cpnet >>> alg = cpnet.KM_ER() >>> alg.detect(G) >>> pair_id = alg.get_pair_id() >>> coreness = alg.get_coreness()
Note
[x] weighted
[ ] directed
[x] multiple groups of core-periphery pairs
[ ] continuous core-periphery structure
- detect(G)
Detect core-periphery structure.
- Parameters
G (networkx.Graph or scipy sparse matrix) – Graph
- Returns
None
- Return type
None
- significance()
cpnet.KM_config module
- class cpnet.KM_config.KM_config(num_runs=10)
Bases:
CPAlgorithmKojaku-Masuda algorithm with the configuration model.
This algorithm finds multiple core-periphery pairs in networks.
Kojaku and N. Masuda. Core-periphery structure requires something else in networks. New J. Phys. 2018
>>> import cpnet >>> alg = cpnet.KM_config() >>> alg.detect(G) >>> pair_id = alg.get_pair_id() >>> coreness = alg.get_coreness()
Note
[x] weighted
[ ] directed
[x] multiple groups of core-periphery pairs
[ ] continuous core-periphery structure
- detect(G)
Detect core-periphery structure.
- Parameters
G (networkx.Graph or scipy sparse matrix) – Graph
- Returns
None
- Return type
None
- significance()
cpnet.Lip module
- class cpnet.Lip.Lip
Bases:
CPAlgorithmLip’s algorithm.
W.~ Lip. A fast algorithm for the discrete core/periphery bipartitioning problem. arXiv, pages 1102.5511, 2011.
>>> import cpnet >>> alg = cpnet.Lip() >>> alg.detect(G) >>> pair_id = alg.get_pair_id() >>> coreness = alg.get_coreness()
Note
[ ] weighted
[ ] directed
[ ] multiple groups of core-periphery pairs
[ ] continuous core-periphery structure
- detect(G)
Detect core-periphery structure.
- Parameters
G (networkx.Graph or scipy sparse matrix) – Graph
- Returns
None
- Return type
None
cpnet.MINRES module
- class cpnet.MINRES.MINRES(num_runs=10)
Bases:
CPAlgorithmMINRES algorithm.
Boyd, J. P., Fitzgerald, W. J., Mahutga, M. C., & Smith, D. A. (2010). Computing continuous core/periphery structures for social relations data with MINRES/SVD. Social Networks, 32(2), 125–137. https://doi.org/10.1016/j.socnet.2009.09.003
>>> import cpnet >>> alg = cpnet.MINRES() >>> alg.detect(G) >>> pair_id = alg.get_pair_id() >>> coreness = alg.get_coreness()
Note
[x] weighted
[ ] directed
[ ] multiple groups of core-periphery pairs
[x] continuous core-periphery structure
- detect(G)
Detect core-periphery structure.
- Parameters
G (networkx.Graph or scipy sparse matrix) – Graph
- Returns
None
- Return type
None
cpnet.Rombach module
- class cpnet.Rombach.Rombach(num_runs=10, alpha=0.5, beta=0.8, algorithm='ls')
Bases:
CPAlgorithmRombach’s algorithm for finding continuous core-periphery structure.
Rombach, M. A. Porter, J. H. Fowler, and P. J. Mucha. Core-Periphery Structure in Networks (Revisited). SIAM Review, 59(3):619–646, 2017
>>> import cpnet >>> alg = cpnet.Rombach() >>> alg.detect(G) >>> pair_id = alg.get_pair_id() >>> coreness = alg.get_coreness()
Note
[x] weighted
[ ] directed
[ ] multiple groups of core-periphery pairs
[x] continuous core-periphery structure
- detect(G)
Detect core-periphery structure.
- Parameters
G (networkx.Graph or scipy sparse matrix) – Graph
- Returns
None
- Return type
None
cpnet.Rossa module
- class cpnet.Rossa.Rossa
Bases:
CPAlgorithmRossa’s algorithm for finding continuous core-periphery structure.
This algorithm finds multiple core-periphery pairs in networks.
Rossa, F. Dercole, and C. Piccardi. Profiling core-periphery network structure by random walkers. Scientific Reports, 3, 1467, 2013
>>> import cpnet >>> alg = cpnet.Rossa() >>> alg.detect(G) >>> pair_id = alg.get_pair_id() >>> coreness = alg.get_coreness()
Note
[x] weighted
[x] directed
[ ] multiple groups of core-periphery pairs
[ ] continuous core-periphery structure
- detect(G)
Detect core-periphery structure.
- Parameters
G (networkx.Graph or scipy sparse matrix) – Graph
- Returns
None
- Return type
None
cpnet.Surprise module
- class cpnet.Surprise.Surprise(num_runs=10)
Bases:
CPAlgorithmCore-periphery detection by Surprise.
van Lidth de Jeude, G. Caldarelli, T. Squartini. Detecting Core-Periphery Structures by Surprise. EPL, 125, 2019
>>> import cpnet >>> alg = cpnet.Surprise() >>> alg.detect(G) >>> pair_id = alg.get_pair_id() >>> coreness = alg.get_coreness()
Note
[ ] weighted
[ ] directed
[ ] multiple groups of core-periphery pairs
[ ] continuous core-periphery structure
- detect(G)
Detect core-periphery structure.
- Parameters
G (networkx.Graph or scipy sparse matrix) – Graph
- Returns
None
- Return type
None
cpnet.adam module
cpnet.qstest module
- cpnet.qstest.config_model(G)
- cpnet.qstest.erdos_renyi(G)
- cpnet.qstest.qstest(pair_id, coreness, G, cpa, significance_level=0.05, null_model=<function config_model>, sfunc=<function sz_n>, num_of_rand_net=100, q_tilde=[], s_tilde=[], **params)
(q,s)-test for core-periphery structure.
Sadamori Kojaku and Naoki Masuda. A generalised significance test for individual communities in networks. Scientific Reports, 8:7351 (2018)
- Parameters
pair_id (dict) – node i belongs to pair pair_id[i]
coreness (dict) – node i is a core (x[i]=1) or a periphery (x[i]=0)
G (networkx.Graph or scipy sparse martix) – Network
cpa (CPAlgorithm) – algorithm that detects the core-periphery structure in question
significance_level (float, optional) – Significicance level, defaults to 0.05
null_model (func, optional) – funcion to produce a null model, defaults to config_model
sfunc (func, optional) – Size function that calculates the size of a community, defaults to sz_n
num_of_thread (int, optional) – Number of threads, defaults to 4
num_of_rand_net (int, optional) – Number of random networks, defaults to 300
q_tilde (list, optional) – pre-computed sampled of strength q of core-periphery structure, defaults to []
s_tilde (list, optional) – pre-computed sample of the size of a core-periphery pair, defaults to []
>>> import cpnet >>> km = cpnet.KM_config() >>> km.detect(G) >>> pair_id = km.get_pair_id() >>> coreness = km.get_coreness() >>> sig_pair_id, sig_coreness, significance, p_values = cpnet.qstest(pair_id, coreness, G, km)
- cpnet.qstest.sampling(G, cpa, sfunc, null_model)
- cpnet.qstest.sz_degree(network, c, x)
- cpnet.qstest.sz_n(network, c, x)
cpnet.utils module
- cpnet.utils.calc_node_pos(G, layout_algorithm)
- cpnet.utils.classify_nodes(G, c, x, max_num=None)
- cpnet.utils.draw(G, c, x, ax, draw_edge=True, font_size=0, pos=None, cmap=None, max_group_num=None, draw_nodes_kwd={}, draw_edges_kwd={'edge_color': '#adadad'}, draw_labels_kwd={}, layout_algorithm=None)
Plot the core-periphery structure in the networks.
- Parameters
G (networkx.Graph) – Graph
c (group membership c[i] of i) – dict
x (dict) – core (x[i])=1 or periphery (x[i]=0)
ax (matplotlib.pyplot.ax) – axis
draw_edge (bool, optional) – whether to draw edges, defaults to True
font_size (int, optional) – font size for node labels, defaults to 0
pos (dict, optional) – pos[i] is the xy coordinate of node i, defaults to None
cmap (matplotlib.cmap, optional) – colomap defaults to None
max_group_num (int, optional) – Number of groups to color, defaults to None
draw_nodes_kwd (dict, optional) – Parameter for networkx.draw_networkx_nodes, defaults to {}
draw_edges_kwd (dict, optional) – Parameter for networkx.draw_networkx_edges, defaults to {“edge_color”: “#adadad”}
draw_labels_kwd (dict, optional) – Parameter for networkx.draw_networkx_labels, defaults to {}
layout_kwd (dict, optional) – layout keywords, defaults to {}
- Returns
(ax, pos)
- Return type
matplotlib.pyplot.ax, dict
- cpnet.utils.draw_interactive(G, c, x, hover_text=None, node_size=10.0, pos=None, cmap=None)
- cpnet.utils.set_node_colors(c, x, cmap, colored_nodes)
- cpnet.utils.to_adjacency_matrix(net)
- cpnet.utils.to_nxgraph(net)