spectral_bipartivity

spectral_bipartivity#

graph_tool.clustering.spectral_bipartivity(g, weight=None, local=False)[git][source]#

Return the spectral bipartivity of the graph.

Parameters:
gGraph

Graph to be used. If it is directed, it is treated as undirected.

weightEdgePropertyMap (optional, default: None)

Edge weights. If omitted, a constant value of 1 will be used.

localbool (optional, default: False)

If True, the contributions of the individual vertices are also returned.

Returns:
bfloat

Spectral bipartivity of the graph.

bvVertexPropertyMap

Spectral bipartivity of the vertices (only returned if local == True).

Notes

The spectral bipartivity [estrada-spectral-2005] is the fraction of the closed walks of the graph that have even length, where a walk of length \(l\) is weighted by \(1/l!\),

\[b = \frac{\operatorname{tr}\cosh\boldsymbol A} {\operatorname{tr}\exp\boldsymbol A} = \frac{\sum_j\cosh\lambda_j}{\sum_j e^{\lambda_j}},\]

where \(\boldsymbol A\) is the (weighted) adjacency matrix (see adjacency()) and \(\lambda_j\) are its eigenvalues. Since bipartite graphs have no closed walks of odd length, for them \(b = 1\), and otherwise \(1/2 < b < 1\). The contribution of vertex \(v\) is the same fraction for the closed walks that start at \(v\),

\[b_v = \frac{[\cosh\boldsymbol A]_{vv}}{[\exp\boldsymbol A]_{vv}}.\]

The values are computed from the eigenvalues (and, if local == True, the eigenvectors) of the dense adjacency matrix, which takes time \(O(V^3)\) and memory \(O(V^2)\). The eigenvalues are shifted by the largest one, so that the exponentials do not overflow.

References

[estrada-spectral-2005]

Ernesto Estrada and Juan A. Rodríguez-Velázquez, “Spectral measures of bipartivity in complex networks”, Phys. Rev. E 72, 046105 (2005), DOI: 10.1103/PhysRevE.72.046105 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["karate"]
>>> b, bv = gt.spectral_bipartivity(g, local=True)
>>> print(b)
0.597414149...
>>> print(bv.a[:5])
[0.5734... 0.5500... 0.5590... 0.5354... 0.6452...]

The contributions of the vertices can be visualized by drawing the network with vertex colors and sizes given by them:

>>> cmap = matplotlib.colors.LinearSegmentedColormap.from_list(
...     "gray-blue", ["#d9d9d9", "#7dabd1"])
>>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=bv, vcmap=cmap,
...               vertex_size=gt.prop_to_size(bv, mi=5, ma=15),
...               output="spectral_bipartivity-karate.pdf")
<...>
../_images/spectral_bipartivity-karate.png

Spectral bipartivity of the vertices of Zachary’s karate club network. The vertex colors, from gray to blue, and the vertex sizes increase with the value.#