generate_joint_degree

generate_joint_degree#

graph_tool.generation.generate_joint_degree(jdm, out_deg=None, in_deg=None)[git][source]#

Generate a random simple graph with a given joint degree matrix.

Parameters:
jdmtwo-dimensional numpy.ndarray

Joint degree matrix, where jdm[k, l] is the number of edges between vertices of degrees \(k\) and \(l\) (twice that number for \(k = l\)), or, if out_deg and in_deg are given, the number of edges from vertices of out-degree \(k\) to vertices of in-degree \(l\).

out_degiterable of int (optional, default: None)

Out-degree of every vertex. If given, a directed graph is generated.

in_degiterable of int (optional, default: None)

In-degree of every vertex.

Returns:
gGraph

The generated graph. In the undirected case, the vertices are numbered in increasing order of degree, and in the directed case they have the given degrees.

See also

is_joint_degree_graphical

Realizability of joint degree matrices

random_rewire

Degree-correlated rewiring

Notes

In the undirected case, the algorithm of Stanton and Pinar [stanton-constructing-2012] adds the edges of every pair of degree classes between random vertices of these classes; if a chosen vertex is already saturated, one of its edges is moved to an unsaturated vertex of the same class, which preserves the joint degrees. The directed case follows Gjoka, Tillman, and Markopoulou [gjoka-construction-2015], where the edges of every pair of classes are first assigned to distinct random pairs of vertices. A ValueError is raised if the matrix is not realizable (see is_joint_degree_graphical()). The resulting graph is not uniformly distributed, which can be fixed by random_rewire() with model="constrained-configuration" and the degrees as block_membership. The algorithm runs in time \(O(N + E\langle k\rangle)\) on average.

References

[stanton-constructing-2012]

Isabelle Stanton and Ali Pinar, “Constructing and sampling graphs with a prescribed joint degree distribution”, ACM Journal of Experimental Algorithmics 17, 3.5 (2012), DOI: 10.1145/2133803.2330086 [sci-hub, @tor], arXiv: 1103.4875

[gjoka-construction-2015]

Minas Gjoka, Balint Tillman and Athina Markopoulou, “Construction of simple graphs with a target joint degree matrix and beyond”, in 2015 IEEE Conference on Computer Communications (INFOCOM), 1553-1561 (2015), DOI: 10.1109/INFOCOM.2015.7218534 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["karate"]
>>> k = g.degree_property_map("total").a
>>> es = g.get_edges()
>>> jdm = np.zeros((k.max() + 1, k.max() + 1), dtype="int")
>>> np.add.at(jdm, (k[es[:, 0]], k[es[:, 1]]), 1)
>>> jdm += jdm.T
>>> h = gt.generate_joint_degree(jdm)
>>> print(h.num_edges(), sorted(h.degree_property_map("total").a) == sorted(k))
78 True

The generated graph is drawn as follows:

>>> gt.graph_draw(h, pos=gt.sfdp_layout(h),
...               output="generate_joint_degree-karate.pdf")
<...>
../_images/generate_joint_degree-karate.png

Random graph with the joint degree matrix of the karate club network.#