easygraph.functions.centrality package
Submodules
easygraph.functions.centrality.betweenness module
- easygraph.functions.centrality.betweenness.betweenness_centrality(G, weight=None, sources=None, normalized=True, endpoints=False, n_workers=None)[source]
Compute the shortest-basic betweenness centrality for nodes.
\[c_B(v) = \sum_{s,t \in V} \frac{\sigma(s, t|v)}{\sigma(s, t)}\]where V is the set of nodes,
\[\sigma(s, t)\]is the number of shortest (s, t)-paths, and
\[\sigma(s, t|v)\]is the number of those paths passing through some node v other than s, t.
\[If\ s\ =\ t,\ \sigma(s, t) = 1, and\ if\ v \in {s, t}, \sigma(s, t|v) = 0 [2]_.\]- Parameters
G (graph) – A easygraph graph.
weight (None or string, optional (default=None)) – If None, all edge weights are considered equal. Otherwise holds the name of the edge attribute used as weight.
sources (None or nodes list, optional (default=None)) – If None, all nodes are considered. Otherwise,the set of source vertices to consider when calculating shortest paths.
normalized (bool, optional) – If True the betweenness values are normalized by 2/((n-1)(n-2)) for graphs, and 1/((n-1)(n-2)) for directed graphs where n is the number of nodes in G.
endpoints (bool, optional) – If True include the endpoints in the shortest basic counts.
- Returns
nodes (dictionary) – Dictionary of nodes with betweenness centrality as the value.
>>> betweenness_centrality(G,weight=”weight”)
easygraph.functions.centrality.closeness module
- easygraph.functions.centrality.closeness.closeness_centrality(G, weight=None, sources=None, n_workers=None)[source]
Compute closeness centrality for nodes.
\[C_{WF}(u) = \frac{n-1}{N-1} \frac{n - 1}{\sum_{v=1}^{n-1} d(v, u)},\]Notice that the closeness distance function computes the outcoming distance to u for directed graphs. To use incoming distance, act on G.reverse().
- Parameters
G (graph) – A easygraph graph
weight (None or string, optional (default=None)) – If None, all edge weights are considered equal. Otherwise holds the name of the edge attribute used as weight.
sources (None or nodes list, optional (default=None)) – If None, all nodes are returned Otherwise,the set of source vertices to creturn.
- Returns
nodes – Dictionary of nodes with closeness centrality as the value.
- Return type
dictionary
easygraph.functions.centrality.degree module
- easygraph.functions.centrality.degree.degree_centrality(G)[source]
Compute the degree centrality for nodes in a bipartite network.
The degree centrality for a node v is the fraction of nodes it is connected to.
- Parameters
G (graph) – A easygraph graph
- Returns
nodes – Dictionary of nodes with degree centrality as the value.
- Return type
dictionary
Notes
The degree centrality are normalized by dividing by n-1 where n is number of nodes in G.
- easygraph.functions.centrality.degree.in_degree_centrality(G)[source]
Compute the in-degree centrality for nodes.
The in-degree centrality for a node v is the fraction of nodes its incoming edges are connected to.
- Parameters
G (graph) – A EasyGraph graph
- Returns
nodes – Dictionary of nodes with in-degree centrality as values.
- Return type
dictionary
- Raises
EasyGraphNotImplemented: – If G is undirected.
See also
Notes
The degree centrality values are normalized by dividing by the maximum possible degree in a simple graph n-1 where n is the number of nodes in G.
For multigraphs or graphs with self loops the maximum degree might be higher than n-1 and values of degree centrality greater than 1 are possible.
- easygraph.functions.centrality.degree.out_degree_centrality(G)[source]
Compute the out-degree centrality for nodes.
The out-degree centrality for a node v is the fraction of nodes its outgoing edges are connected to.
- Parameters
G (graph) – A EasyGraph graph
- Returns
nodes – Dictionary of nodes with out-degree centrality as values.
- Return type
dictionary
- Raises
EasyGraphNotImplemented: – If G is undirected.
See also
Notes
The degree centrality values are normalized by dividing by the maximum possible degree in a simple graph n-1 where n is the number of nodes in G.
For multigraphs or graphs with self loops the maximum degree might be higher than n-1 and values of degree centrality greater than 1 are possible.
easygraph.functions.centrality.ego_betweenness module
- easygraph.functions.centrality.ego_betweenness.ego_betweenness(G, node)[source]
ego networks are networks consisting of a single actor (ego) together with the actors they are connected to (alters) and all the links among those alters.[1] Burt (1992), in his book Structural Holes, provides ample evidence that having high betweenness centrality, which is highly correlated with having many structural holes, can bring benefits to ego.[1] Returns the betweenness centrality of a ego network whose ego is set
- Parameters
G (graph) –
node (int) –
- Returns
sum – the betweenness centrality of a ego network whose ego is set
- Return type
float
Examples
Returns the betwenness centrality of node 1.
>>> ego_betweenness(G,node=1)
- 1
Martin Everett, Stephen P. Borgatti. “Ego network betweenness.” Social Networks, Volume 27, Issue 1, Pages 31-38, 2005.
easygraph.functions.centrality.flowbetweenness module
- easygraph.functions.centrality.flowbetweenness.flowbetweenness_centrality(G)[source]
Compute the independent-basic betweenness centrality for nodes in a flow network.
\[c_B(v) =\sum_{s,t \in V}\]rac{sigma(s, t|v)}{sigma(s, t)}
where V is the set of nodes,
\[\sigma(s, t)\ is\ the\ number\ of\ independent\ (s, t)-paths,\]\[\sigma(s, t|v)\ is\ the\ maximum\ number\ possible\ of\ those\ paths\ passing\ through\ some\ node\ v\ other\ than\ s, t.\]\[If\ s\ =\ t,\ \sigma(s, t)\ =\ 1,\ and\ if\ v \in \{s, t\},\ \sigma(s, t|v)\ =\ 0\ [2]_.\]- Ggraph
A easygraph directed graph.
- nodesdictionary
Dictionary of nodes with independent-basic betweenness centrality as the value.
A flow network is a directed graph where each edge has a capacity and each edge receives a flow.
easygraph.functions.centrality.laplacian module
- easygraph.functions.centrality.laplacian.laplacian(G, n_workers=None)[source]
Returns the laplacian centrality of each node in the weighted graph
- Parameters
G (graph) – weighted graph
- Returns
CL – the laplacian centrality of each node in the weighted graph
- Return type
dict
Examples
Returns the laplacian centrality of each node in the weighted graph G
>>> laplacian(G)
- 1
Xingqin Qi, Eddie Fuller, Qin Wu, Yezhou Wu, Cun-Quan Zhang.
“Laplacian centrality: A new centrality measure for weighted networks.” Information Sciences, Volume 194, Pages 240-253, 2012.