graphoskop 0.4.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- graphoskop-0.4.8/PKG-INFO +144 -0
- graphoskop-0.4.8/README.md +127 -0
- graphoskop-0.4.8/graphoskop/__init__.py +64 -0
- graphoskop-0.4.8/graphoskop/backboning.py +1370 -0
- graphoskop-0.4.8/graphoskop/bipartite_projections.py +534 -0
- graphoskop-0.4.8/graphoskop/centrality.py +1209 -0
- graphoskop-0.4.8/graphoskop/coloring.py +345 -0
- graphoskop-0.4.8/graphoskop/communities.py +226 -0
- graphoskop-0.4.8/graphoskop/equivalence.py +817 -0
- graphoskop-0.4.8/graphoskop/exploration.py +116 -0
- graphoskop-0.4.8/graphoskop/generators.py +1392 -0
- graphoskop-0.4.8/graphoskop/hierarchy.py +42 -0
- graphoskop-0.4.8/graphoskop/multilayer.py +170 -0
- graphoskop-0.4.8/graphoskop/network.py +1561 -0
- graphoskop-0.4.8/graphoskop/network_statistics.py +1259 -0
- graphoskop-0.4.8/graphoskop/node_vector_analysis.py +513 -0
- graphoskop-0.4.8/graphoskop/planarity.py +207 -0
- graphoskop-0.4.8/graphoskop/shortest_paths.py +658 -0
- graphoskop-0.4.8/graphoskop/signed.py +592 -0
- graphoskop-0.4.8/graphoskop/transformations.py +401 -0
- graphoskop-0.4.8/graphoskop/utils.py +622 -0
- graphoskop-0.4.8/graphoskop.egg-info/PKG-INFO +144 -0
- graphoskop-0.4.8/graphoskop.egg-info/SOURCES.txt +26 -0
- graphoskop-0.4.8/graphoskop.egg-info/dependency_links.txt +1 -0
- graphoskop-0.4.8/graphoskop.egg-info/requires.txt +9 -0
- graphoskop-0.4.8/graphoskop.egg-info/top_level.txt +1 -0
- graphoskop-0.4.8/pyproject.toml +21 -0
- graphoskop-0.4.8/setup.cfg +4 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: graphoskop
|
|
3
|
+
Version: 0.4.8
|
|
4
|
+
Summary: Analysis of networks and of vectors defined on their nodes.
|
|
5
|
+
Project-URL: Homepage, https://github.com/mikk-c/graphoskop
|
|
6
|
+
Project-URL: Issues, https://github.com/mikk-c/graphoskop/issues
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Requires-Dist: numpy
|
|
10
|
+
Requires-Dist: pandas
|
|
11
|
+
Requires-Dist: scipy
|
|
12
|
+
Requires-Dist: torch
|
|
13
|
+
Requires-Dist: torch_geometric
|
|
14
|
+
Provides-Extra: docs
|
|
15
|
+
Requires-Dist: sphinx; extra == "docs"
|
|
16
|
+
Requires-Dist: sphinx_rtd_theme; extra == "docs"
|
|
17
|
+
|
|
18
|
+
# Graphoskop
|
|
19
|
+
|
|
20
|
+
Analysis of networks and of vectors defined on their nodes.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
pip install graphoskop
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
import graphoskop as gsk
|
|
29
|
+
net = gsk.load_network("edges.tsv", "nodes.tsv")
|
|
30
|
+
net = gsk.load_network(edges_df, nodes_df) # or from pandas DataFrames
|
|
31
|
+
edges_df, nodes_df = net.to_pandas_dataframes() # and back
|
|
32
|
+
gsk.save_network(net, "out/net") # out/net_edges.tsv, out/net_nodes.tsv (and _interlayer.tsv)
|
|
33
|
+
gsk.save_network(net, "out/net", pickle = True) # out/net.pt, read with gsk.load_pickled_network
|
|
34
|
+
|
|
35
|
+
Directed networks can be symmetrized, combining the attributes of the two directions:
|
|
36
|
+
|
|
37
|
+
und = gsk.to_undirected(net, combine = "sum") # or "mean", "max"; sign: disagree = "zero", "positive", "negative"
|
|
38
|
+
core = gsk.remove_isolates(net) # drop nodes without edges
|
|
39
|
+
clean = gsk.remove_self_loops(net) # drop edges from a node to itself
|
|
40
|
+
simple = gsk.remove_parallel_edges(net) # merge parallel edges (same direction, same layer)
|
|
41
|
+
ego = gsk.subgraph(net, ["alice", "bob"]) # induced subgraph
|
|
42
|
+
scc = gsk.to_strongly_connected(net) # directed: split into strongly connected components
|
|
43
|
+
|
|
44
|
+
Degree and clustering:
|
|
45
|
+
|
|
46
|
+
gsk.connected_components_count(net, type = "strong"), gsk.connected_components_nodes(net)
|
|
47
|
+
gsk.degree(net, "alice"), gsk.degree(net, distribution = "ccdf")
|
|
48
|
+
gsk.degree(net, "alice", weight = "weight") # weighted degree (strength)
|
|
49
|
+
gsk.degree_power_law(net) # exponent, k_min and cutoff, after likelihood ratio tests (Clauset et al.)
|
|
50
|
+
gsk.degree_power_law(net, ccdf = True)["ccdf"] # empirical and fitted ccdf, to plot
|
|
51
|
+
gsk.degree_power_law(net)["formula"] # best fit written out, e.g. "P(k) = 0.27 * k^(-2.37) / 0.026, for k >= 12"
|
|
52
|
+
gsk.degree_centralization(net)["centralization"] # degree entropy vs random networks of the same size
|
|
53
|
+
gsk.average_degree(net) # 2m / n (undirected), m / n (directed)
|
|
54
|
+
gsk.density(net) # also directed, bipartite, multilayer (per layer)
|
|
55
|
+
gsk.reciprocity(net), gsk.reciprocity(net, normalized = True) # directed networks
|
|
56
|
+
gsk.average_shortest_path_length(net) # same paths as the shortest_paths module
|
|
57
|
+
gsk.shortest_path_length_distribution(net) # number of node pairs at each distance (edges)
|
|
58
|
+
gsk.diameter(net) # longest shortest path
|
|
59
|
+
net.is_planar() # drawable without edge crossings
|
|
60
|
+
gsk.maximally_filtered_graph(net, "weight") # planar backbone (PMFG), a new network
|
|
61
|
+
gsk.triangulated_filtered_graph(net, "weight") # faster planar backbone (TMFG), on the GPU
|
|
62
|
+
gsk.bfs(net, "alice", max_depth = 2), gsk.dfs(net, "alice") # exploration: node, depth, parent in visit order
|
|
63
|
+
|
|
64
|
+
Random walks: `gsk.stationary_distribution(net)`, `gsk.effective_resistance(net)`, and hitting times
|
|
65
|
+
`H = gsk.hitting_time(net)` (`H[i, j]`: expected steps from `i` to reach `j`; `alpha` for teleportation).
|
|
66
|
+
|
|
67
|
+
Centralities (closeness, harmonic, betweenness of nodes and edges) can share precomputed shortest path lengths:
|
|
68
|
+
|
|
69
|
+
P = gsk.all_pairs_shortest_path_lengths(net)
|
|
70
|
+
b = gsk.betweenness_centrality(net, lengths = P) # also closeness_centrality, harmonic_centrality
|
|
71
|
+
eb = gsk.edge_betweenness_centrality(net, lengths = P) # per stored edge: net.set_edge_attribute("eb", eb)
|
|
72
|
+
c = gsk.closeness_centrality(net, component = None, lin = True) # all components, comparable
|
|
73
|
+
f = gsk.flow_centrality(net) # random walk betweenness (Newman, 2005)
|
|
74
|
+
gsk.eigenvector_centrality(net, weight = "weight") # power iteration on the device
|
|
75
|
+
gsk.pagerank(net, component = None, personalization = {"alice": 1}) # personalized PageRank
|
|
76
|
+
hubs, authorities = gsk.hits(net) # HITS
|
|
77
|
+
gsk.k_core_centrality(net) # core number of every node
|
|
78
|
+
gsk.centralization(net, gsk.betweenness_centrality) # Freeman centralization of any centrality
|
|
79
|
+
gsk.structural_equivalence(net, "alice", "bob") # Jaccard coefficient of their neighbors
|
|
80
|
+
gsk.automorphic_equivalence(net, "alice", "bob") # 1 if some automorphism swaps them
|
|
81
|
+
gsk.pairwise_structural_equivalence(net), gsk.pairwise_automorphic_equivalence(net) # all pairs, n x n
|
|
82
|
+
gsk.pairwise_regular_equivalence(dnet) # REGE: directed or valued networks
|
|
83
|
+
gsk.pairwise_path_regular_equivalence(net, alpha = 0.97) # Leicht, Holme and Newman similarity
|
|
84
|
+
gsk.katz_centrality(net, alpha = 0.05) # alpha below 1 / largest eigenvalue
|
|
85
|
+
gsk.alpha_centrality(net, alpha = 0.5, exo = "wealth") # Bonacich alpha centrality, any alpha
|
|
86
|
+
gsk.reach_centrality(dnet) # directed networks: fraction of nodes reached
|
|
87
|
+
gsk.global_reach_centrality(dnet) # hierarchy of a directed network
|
|
88
|
+
gsk.modularity(net, "party") # partition from a node attribute, a dict or a list
|
|
89
|
+
gsk.maximal_cliques(net) # node sets of maximal cliques with 3+ nodes
|
|
90
|
+
gsk.graph_coloring(net), gsk.maximum_independent_set(net) # exact when proven within time_limit
|
|
91
|
+
gsk.local_clustering(net, "alice") # or a vector over a component
|
|
92
|
+
gsk.global_clustering(net), gsk.average_clustering(net)
|
|
93
|
+
gsk.assortativity(net), gsk.assortativity(net, "age"), gsk.assortativity(net, "city") # degree, numeric, qualitative
|
|
94
|
+
|
|
95
|
+
Numeric node attributes go to the chosen `device` (e.g. `"cuda"`); qualitative ones (strings,
|
|
96
|
+
categories) always stay in CPU memory.
|
|
97
|
+
|
|
98
|
+
Bipartite networks need a `bipartite_type` column in the node table, with two values:
|
|
99
|
+
|
|
100
|
+
net = gsk.load_network("edges.tsv", "nodes.tsv", bipartite = True)
|
|
101
|
+
users = gsk.simple_count_projection(net, "user") # projection onto the "user" nodes
|
|
102
|
+
users = gsk.hyperbolic_projection(net, "user") # also hist_intersection_projection
|
|
103
|
+
items = gsk.resource_allocation_projection(net, "item", lambd = 1) # ProbS; 0 HeatS, 0.5 hybrid
|
|
104
|
+
items = gsk.random_walk_projection(net, "item") # YCN random walks
|
|
105
|
+
|
|
106
|
+
Multilayer networks need a `layer` column in the edge table; nodes become copies `(entity, layer)`:
|
|
107
|
+
|
|
108
|
+
net = gsk.load_network("edges.tsv", "nodes.tsv", multilayer = True, coupling = "all") # or "ordinal", "temporal"
|
|
109
|
+
gsk.laplacian(net) # supra-Laplacian
|
|
110
|
+
gsk.degree(net, ("alice", "work")), gsk.degree(net, "alice") # in one layer, summed over layers
|
|
111
|
+
work = gsk.layer_network(net, "work") # one layer as an ordinary network
|
|
112
|
+
flat = gsk.aggregate_network(net) # all layers flattened
|
|
113
|
+
|
|
114
|
+
Signed networks carry a +1 / -1 `sign` edge attribute; build them from a positive and a negative
|
|
115
|
+
layer, or by thresholding an edge weight:
|
|
116
|
+
|
|
117
|
+
signed = gsk.signed_network(net, positive = "ally", negative = "enemy") # multilayer net
|
|
118
|
+
signed = gsk.signed_network(net, weight = "score", threshold = 0) # >= 0 positive
|
|
119
|
+
A = gsk.signed_adjacency(signed) # sparse, per component
|
|
120
|
+
gsk.structural_balance(signed) # Tr(A^3) / Tr(|A|^3)
|
|
121
|
+
gsk.structural_balance(signed, beta = 0.5) # Tr(e^(beta A)) / Tr(e^(beta |A|)), all closed walks
|
|
122
|
+
gsk.signed_triangle_counts(signed) # per sign pattern, vs. shuffled signs (exact)
|
|
123
|
+
|
|
124
|
+
Synthetic networks: every generator takes its parameters, or an existing network to randomize
|
|
125
|
+
(same nodes and attributes, new random edges, edge attributes shuffled over them):
|
|
126
|
+
|
|
127
|
+
g = gsk.gnm_random_graph(1000, 5000, seed = 1) # random: 1000 nodes, 5000 random edges
|
|
128
|
+
g = gsk.gnp_random_graph(1000, 0.01, seed = 1) # random: each pair an edge with probability 0.01
|
|
129
|
+
b = gsk.gnm_random_graph((100, 300), 1000) # bipartite
|
|
130
|
+
c = gsk.caveman_graph(10, 5, connected = True) # clustered: 10 cliques of 5 in a ring; node attribute "cave"
|
|
131
|
+
w = gsk.watts_strogatz_graph(1000, 6, 0.1) # clustered: small world; rewire = "target", "both" or "add"
|
|
132
|
+
ba = gsk.barabasi_albert_graph(10000, 6) # broad degree: preferential attachment, average degree 6 (m = 3)
|
|
133
|
+
ls = gsk.link_selection_graph(10000, 6) # broad degree: new nodes link to an end of random links
|
|
134
|
+
cp = gsk.copying_graph(10000, 6) # broad degree: new nodes copy a link of random nodes
|
|
135
|
+
hk = gsk.holme_kim_graph(10000, 6, 0.8) # broad degree with clustering: triangles closed with probability 0.8
|
|
136
|
+
rnd = gsk.gnm_random_graph(net = net) # randomization of net, same n and m
|
|
137
|
+
rnd = gsk.gnp_random_graph(net = net) # same n, p = density of net
|
|
138
|
+
rnd = gsk.caveman_graph(net = net) # nodes in random caves, cave size from the average degree
|
|
139
|
+
rnd = gsk.watts_strogatz_graph(net = net, p = 0.1) # nodes on a ring, same n and m, then rewired
|
|
140
|
+
rnd = gsk.barabasi_albert_graph(net = net) # same n and m, nodes arrive in random order
|
|
141
|
+
rnd = gsk.link_selection_graph(net = net) # same n and m, nodes arrive in random order
|
|
142
|
+
rnd = gsk.copying_graph(net = net) # same n and m, nodes arrive in random order
|
|
143
|
+
rnd = gsk.holme_kim_graph(net = net) # same n, m and average clustering (p inferred)
|
|
144
|
+
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Graphoskop
|
|
2
|
+
|
|
3
|
+
Analysis of networks and of vectors defined on their nodes.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
pip install graphoskop
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
import graphoskop as gsk
|
|
12
|
+
net = gsk.load_network("edges.tsv", "nodes.tsv")
|
|
13
|
+
net = gsk.load_network(edges_df, nodes_df) # or from pandas DataFrames
|
|
14
|
+
edges_df, nodes_df = net.to_pandas_dataframes() # and back
|
|
15
|
+
gsk.save_network(net, "out/net") # out/net_edges.tsv, out/net_nodes.tsv (and _interlayer.tsv)
|
|
16
|
+
gsk.save_network(net, "out/net", pickle = True) # out/net.pt, read with gsk.load_pickled_network
|
|
17
|
+
|
|
18
|
+
Directed networks can be symmetrized, combining the attributes of the two directions:
|
|
19
|
+
|
|
20
|
+
und = gsk.to_undirected(net, combine = "sum") # or "mean", "max"; sign: disagree = "zero", "positive", "negative"
|
|
21
|
+
core = gsk.remove_isolates(net) # drop nodes without edges
|
|
22
|
+
clean = gsk.remove_self_loops(net) # drop edges from a node to itself
|
|
23
|
+
simple = gsk.remove_parallel_edges(net) # merge parallel edges (same direction, same layer)
|
|
24
|
+
ego = gsk.subgraph(net, ["alice", "bob"]) # induced subgraph
|
|
25
|
+
scc = gsk.to_strongly_connected(net) # directed: split into strongly connected components
|
|
26
|
+
|
|
27
|
+
Degree and clustering:
|
|
28
|
+
|
|
29
|
+
gsk.connected_components_count(net, type = "strong"), gsk.connected_components_nodes(net)
|
|
30
|
+
gsk.degree(net, "alice"), gsk.degree(net, distribution = "ccdf")
|
|
31
|
+
gsk.degree(net, "alice", weight = "weight") # weighted degree (strength)
|
|
32
|
+
gsk.degree_power_law(net) # exponent, k_min and cutoff, after likelihood ratio tests (Clauset et al.)
|
|
33
|
+
gsk.degree_power_law(net, ccdf = True)["ccdf"] # empirical and fitted ccdf, to plot
|
|
34
|
+
gsk.degree_power_law(net)["formula"] # best fit written out, e.g. "P(k) = 0.27 * k^(-2.37) / 0.026, for k >= 12"
|
|
35
|
+
gsk.degree_centralization(net)["centralization"] # degree entropy vs random networks of the same size
|
|
36
|
+
gsk.average_degree(net) # 2m / n (undirected), m / n (directed)
|
|
37
|
+
gsk.density(net) # also directed, bipartite, multilayer (per layer)
|
|
38
|
+
gsk.reciprocity(net), gsk.reciprocity(net, normalized = True) # directed networks
|
|
39
|
+
gsk.average_shortest_path_length(net) # same paths as the shortest_paths module
|
|
40
|
+
gsk.shortest_path_length_distribution(net) # number of node pairs at each distance (edges)
|
|
41
|
+
gsk.diameter(net) # longest shortest path
|
|
42
|
+
net.is_planar() # drawable without edge crossings
|
|
43
|
+
gsk.maximally_filtered_graph(net, "weight") # planar backbone (PMFG), a new network
|
|
44
|
+
gsk.triangulated_filtered_graph(net, "weight") # faster planar backbone (TMFG), on the GPU
|
|
45
|
+
gsk.bfs(net, "alice", max_depth = 2), gsk.dfs(net, "alice") # exploration: node, depth, parent in visit order
|
|
46
|
+
|
|
47
|
+
Random walks: `gsk.stationary_distribution(net)`, `gsk.effective_resistance(net)`, and hitting times
|
|
48
|
+
`H = gsk.hitting_time(net)` (`H[i, j]`: expected steps from `i` to reach `j`; `alpha` for teleportation).
|
|
49
|
+
|
|
50
|
+
Centralities (closeness, harmonic, betweenness of nodes and edges) can share precomputed shortest path lengths:
|
|
51
|
+
|
|
52
|
+
P = gsk.all_pairs_shortest_path_lengths(net)
|
|
53
|
+
b = gsk.betweenness_centrality(net, lengths = P) # also closeness_centrality, harmonic_centrality
|
|
54
|
+
eb = gsk.edge_betweenness_centrality(net, lengths = P) # per stored edge: net.set_edge_attribute("eb", eb)
|
|
55
|
+
c = gsk.closeness_centrality(net, component = None, lin = True) # all components, comparable
|
|
56
|
+
f = gsk.flow_centrality(net) # random walk betweenness (Newman, 2005)
|
|
57
|
+
gsk.eigenvector_centrality(net, weight = "weight") # power iteration on the device
|
|
58
|
+
gsk.pagerank(net, component = None, personalization = {"alice": 1}) # personalized PageRank
|
|
59
|
+
hubs, authorities = gsk.hits(net) # HITS
|
|
60
|
+
gsk.k_core_centrality(net) # core number of every node
|
|
61
|
+
gsk.centralization(net, gsk.betweenness_centrality) # Freeman centralization of any centrality
|
|
62
|
+
gsk.structural_equivalence(net, "alice", "bob") # Jaccard coefficient of their neighbors
|
|
63
|
+
gsk.automorphic_equivalence(net, "alice", "bob") # 1 if some automorphism swaps them
|
|
64
|
+
gsk.pairwise_structural_equivalence(net), gsk.pairwise_automorphic_equivalence(net) # all pairs, n x n
|
|
65
|
+
gsk.pairwise_regular_equivalence(dnet) # REGE: directed or valued networks
|
|
66
|
+
gsk.pairwise_path_regular_equivalence(net, alpha = 0.97) # Leicht, Holme and Newman similarity
|
|
67
|
+
gsk.katz_centrality(net, alpha = 0.05) # alpha below 1 / largest eigenvalue
|
|
68
|
+
gsk.alpha_centrality(net, alpha = 0.5, exo = "wealth") # Bonacich alpha centrality, any alpha
|
|
69
|
+
gsk.reach_centrality(dnet) # directed networks: fraction of nodes reached
|
|
70
|
+
gsk.global_reach_centrality(dnet) # hierarchy of a directed network
|
|
71
|
+
gsk.modularity(net, "party") # partition from a node attribute, a dict or a list
|
|
72
|
+
gsk.maximal_cliques(net) # node sets of maximal cliques with 3+ nodes
|
|
73
|
+
gsk.graph_coloring(net), gsk.maximum_independent_set(net) # exact when proven within time_limit
|
|
74
|
+
gsk.local_clustering(net, "alice") # or a vector over a component
|
|
75
|
+
gsk.global_clustering(net), gsk.average_clustering(net)
|
|
76
|
+
gsk.assortativity(net), gsk.assortativity(net, "age"), gsk.assortativity(net, "city") # degree, numeric, qualitative
|
|
77
|
+
|
|
78
|
+
Numeric node attributes go to the chosen `device` (e.g. `"cuda"`); qualitative ones (strings,
|
|
79
|
+
categories) always stay in CPU memory.
|
|
80
|
+
|
|
81
|
+
Bipartite networks need a `bipartite_type` column in the node table, with two values:
|
|
82
|
+
|
|
83
|
+
net = gsk.load_network("edges.tsv", "nodes.tsv", bipartite = True)
|
|
84
|
+
users = gsk.simple_count_projection(net, "user") # projection onto the "user" nodes
|
|
85
|
+
users = gsk.hyperbolic_projection(net, "user") # also hist_intersection_projection
|
|
86
|
+
items = gsk.resource_allocation_projection(net, "item", lambd = 1) # ProbS; 0 HeatS, 0.5 hybrid
|
|
87
|
+
items = gsk.random_walk_projection(net, "item") # YCN random walks
|
|
88
|
+
|
|
89
|
+
Multilayer networks need a `layer` column in the edge table; nodes become copies `(entity, layer)`:
|
|
90
|
+
|
|
91
|
+
net = gsk.load_network("edges.tsv", "nodes.tsv", multilayer = True, coupling = "all") # or "ordinal", "temporal"
|
|
92
|
+
gsk.laplacian(net) # supra-Laplacian
|
|
93
|
+
gsk.degree(net, ("alice", "work")), gsk.degree(net, "alice") # in one layer, summed over layers
|
|
94
|
+
work = gsk.layer_network(net, "work") # one layer as an ordinary network
|
|
95
|
+
flat = gsk.aggregate_network(net) # all layers flattened
|
|
96
|
+
|
|
97
|
+
Signed networks carry a +1 / -1 `sign` edge attribute; build them from a positive and a negative
|
|
98
|
+
layer, or by thresholding an edge weight:
|
|
99
|
+
|
|
100
|
+
signed = gsk.signed_network(net, positive = "ally", negative = "enemy") # multilayer net
|
|
101
|
+
signed = gsk.signed_network(net, weight = "score", threshold = 0) # >= 0 positive
|
|
102
|
+
A = gsk.signed_adjacency(signed) # sparse, per component
|
|
103
|
+
gsk.structural_balance(signed) # Tr(A^3) / Tr(|A|^3)
|
|
104
|
+
gsk.structural_balance(signed, beta = 0.5) # Tr(e^(beta A)) / Tr(e^(beta |A|)), all closed walks
|
|
105
|
+
gsk.signed_triangle_counts(signed) # per sign pattern, vs. shuffled signs (exact)
|
|
106
|
+
|
|
107
|
+
Synthetic networks: every generator takes its parameters, or an existing network to randomize
|
|
108
|
+
(same nodes and attributes, new random edges, edge attributes shuffled over them):
|
|
109
|
+
|
|
110
|
+
g = gsk.gnm_random_graph(1000, 5000, seed = 1) # random: 1000 nodes, 5000 random edges
|
|
111
|
+
g = gsk.gnp_random_graph(1000, 0.01, seed = 1) # random: each pair an edge with probability 0.01
|
|
112
|
+
b = gsk.gnm_random_graph((100, 300), 1000) # bipartite
|
|
113
|
+
c = gsk.caveman_graph(10, 5, connected = True) # clustered: 10 cliques of 5 in a ring; node attribute "cave"
|
|
114
|
+
w = gsk.watts_strogatz_graph(1000, 6, 0.1) # clustered: small world; rewire = "target", "both" or "add"
|
|
115
|
+
ba = gsk.barabasi_albert_graph(10000, 6) # broad degree: preferential attachment, average degree 6 (m = 3)
|
|
116
|
+
ls = gsk.link_selection_graph(10000, 6) # broad degree: new nodes link to an end of random links
|
|
117
|
+
cp = gsk.copying_graph(10000, 6) # broad degree: new nodes copy a link of random nodes
|
|
118
|
+
hk = gsk.holme_kim_graph(10000, 6, 0.8) # broad degree with clustering: triangles closed with probability 0.8
|
|
119
|
+
rnd = gsk.gnm_random_graph(net = net) # randomization of net, same n and m
|
|
120
|
+
rnd = gsk.gnp_random_graph(net = net) # same n, p = density of net
|
|
121
|
+
rnd = gsk.caveman_graph(net = net) # nodes in random caves, cave size from the average degree
|
|
122
|
+
rnd = gsk.watts_strogatz_graph(net = net, p = 0.1) # nodes on a ring, same n and m, then rewired
|
|
123
|
+
rnd = gsk.barabasi_albert_graph(net = net) # same n and m, nodes arrive in random order
|
|
124
|
+
rnd = gsk.link_selection_graph(net = net) # same n and m, nodes arrive in random order
|
|
125
|
+
rnd = gsk.copying_graph(net = net) # same n and m, nodes arrive in random order
|
|
126
|
+
rnd = gsk.holme_kim_graph(net = net) # same n, m and average clustering (p inferred)
|
|
127
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Graphoskop: analysis of networks and of vectors defined on their nodes.
|
|
3
|
+
|
|
4
|
+
All public functions and classes are available at the top level of the package.
|
|
5
|
+
|
|
6
|
+
Quick start, with an edge list ``edges.tsv``::
|
|
7
|
+
|
|
8
|
+
source target weight
|
|
9
|
+
alice bob 1.5
|
|
10
|
+
bob carol 2.0
|
|
11
|
+
|
|
12
|
+
and a node table ``nodes.tsv``::
|
|
13
|
+
|
|
14
|
+
id age height city
|
|
15
|
+
alice 34 170 Rome
|
|
16
|
+
carol 29 165 Oslo
|
|
17
|
+
|
|
18
|
+
.. code-block:: python
|
|
19
|
+
|
|
20
|
+
import graphoskop as gsk
|
|
21
|
+
|
|
22
|
+
net = gsk.load_network("edges.tsv", "nodes.tsv")
|
|
23
|
+
g = net.components[0] # largest weakly connected component
|
|
24
|
+
g.edge_index # edges, internal node ids
|
|
25
|
+
g.edge_attr # weight, one row per edge
|
|
26
|
+
g.node_attr # age and height (numeric), one row per node
|
|
27
|
+
net.qualitative_node_attr # city (qualitative), always in CPU memory
|
|
28
|
+
net.node_map["alice"] # (component, index)
|
|
29
|
+
|
|
30
|
+
Multilayer networks are loaded with ``multilayer = True`` from an edge list with a ``layer``
|
|
31
|
+
column; nodes are then copies ``(entity, layer)`` (see :doc:`multilayer`). Signed networks carry
|
|
32
|
+
a +1 / -1 sign on their edges, built from a positive and a negative layer or by thresholding a
|
|
33
|
+
weight (see :doc:`signed`).
|
|
34
|
+
|
|
35
|
+
Synthetic networks come from generators, which can also randomize an existing network, keeping
|
|
36
|
+
its nodes and their attributes (see :doc:`generators`).
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
from importlib.metadata import version, PackageNotFoundError
|
|
40
|
+
|
|
41
|
+
from .network import BIPARTITE, LAYER, Network, load_network, save_network, load_pickled_network
|
|
42
|
+
from .multilayer import layer_network, aggregate_network
|
|
43
|
+
from .transformations import to_undirected, remove_isolates, remove_self_loops, remove_parallel_edges, subgraph, to_strongly_connected
|
|
44
|
+
from .signed import SIGN, signed_network, signed_adjacency, structural_balance, signed_triangle_counts
|
|
45
|
+
from .utils import laplacian, laplacian_pinv, laplacian_solver, stationary_distribution, effective_resistance, hitting_time
|
|
46
|
+
from .shortest_paths import shortest_path, shortest_path_length, single_source_shortest_paths, single_source_shortest_path_lengths, all_pairs_shortest_paths, all_pairs_shortest_path_lengths, shortest_path_length_distribution, diameter
|
|
47
|
+
from .communities import modularity, maximal_cliques
|
|
48
|
+
from .coloring import graph_coloring, maximum_independent_set
|
|
49
|
+
from .exploration import bfs, dfs
|
|
50
|
+
from .centrality import closeness_centrality, harmonic_centrality, betweenness_centrality, edge_betweenness_centrality, flow_centrality, reach_centrality, eigenvector_centrality, pagerank, katz_centrality, alpha_centrality, hits, k_core_centrality, centralization
|
|
51
|
+
from .hierarchy import global_reach_centrality
|
|
52
|
+
from .equivalence import structural_equivalence, automorphic_equivalence, pairwise_structural_equivalence, pairwise_automorphic_equivalence, regular_equivalence, pairwise_regular_equivalence, path_regular_equivalence, pairwise_path_regular_equivalence
|
|
53
|
+
from .network_statistics import connected_components_count, connected_components_nodes, degree, average_degree, degree_power_law, degree_centralization, density, reciprocity, average_shortest_path_length, local_clustering, global_clustering, average_clustering, assortativity
|
|
54
|
+
from .backboning import noise_corrected, disparity_filter, doubly_stochastic, high_salience_skeleton, extract_backbone, test_bb_thresholds, find_bb_thresholds, spanning_tree, maximally_filtered_graph, triangulated_filtered_graph
|
|
55
|
+
from .bipartite_projections import simple_count_projection, hist_intersection_projection, hyperbolic_projection, resource_allocation_projection, random_walk_projection
|
|
56
|
+
from .generators import gnm_random_graph, gnp_random_graph, caveman_graph, watts_strogatz_graph, barabasi_albert_graph, link_selection_graph, copying_graph, holme_kim_graph
|
|
57
|
+
from .node_vector_analysis import generalized_euclidean, pairwise_generalized_euclidean, network_correlation, pairwise_network_correlation, network_variance, network_entropy
|
|
58
|
+
|
|
59
|
+
try:
|
|
60
|
+
__version__ = version("graphoskop")
|
|
61
|
+
except PackageNotFoundError:
|
|
62
|
+
__version__ = "unknown"
|
|
63
|
+
|
|
64
|
+
__all__ = ["BIPARTITE", "LAYER", "Network", "load_network", "save_network", "load_pickled_network", "layer_network", "aggregate_network", "to_undirected", "remove_isolates", "remove_self_loops", "remove_parallel_edges", "subgraph", "to_strongly_connected", "SIGN", "signed_network", "signed_adjacency", "structural_balance", "signed_triangle_counts", "laplacian", "laplacian_pinv", "laplacian_solver", "stationary_distribution", "generalized_euclidean", "pairwise_generalized_euclidean", "effective_resistance", "hitting_time", "network_correlation", "pairwise_network_correlation", "network_variance", "network_entropy", "shortest_path", "shortest_path_length", "single_source_shortest_paths", "single_source_shortest_path_lengths", "all_pairs_shortest_paths", "all_pairs_shortest_path_lengths", "shortest_path_length_distribution", "diameter", "noise_corrected", "disparity_filter", "doubly_stochastic", "high_salience_skeleton", "extract_backbone", "test_bb_thresholds", "find_bb_thresholds", "spanning_tree", "maximally_filtered_graph", "triangulated_filtered_graph", "connected_components_count", "connected_components_nodes", "degree", "average_degree", "degree_power_law", "degree_centralization", "density", "reciprocity", "average_shortest_path_length", "local_clustering", "global_clustering", "average_clustering", "assortativity", "modularity", "maximal_cliques", "graph_coloring", "maximum_independent_set", "bfs", "dfs", "closeness_centrality", "harmonic_centrality", "betweenness_centrality", "edge_betweenness_centrality", "flow_centrality", "reach_centrality", "eigenvector_centrality", "pagerank", "hits", "k_core_centrality", "centralization", "katz_centrality", "alpha_centrality", "global_reach_centrality", "structural_equivalence", "automorphic_equivalence", "pairwise_structural_equivalence", "pairwise_automorphic_equivalence", "regular_equivalence", "pairwise_regular_equivalence", "path_regular_equivalence", "pairwise_path_regular_equivalence", "simple_count_projection", "hist_intersection_projection", "hyperbolic_projection", "resource_allocation_projection", "random_walk_projection", "gnm_random_graph", "gnp_random_graph", "caveman_graph", "watts_strogatz_graph", "barabasi_albert_graph", "link_selection_graph", "copying_graph", "holme_kim_graph"]
|