dhg.random

Random Seed

dhg.random.seed()[source]

Return current random seed of DHG. Defaultly, the random seed is synchronized with the value of int(time.time()).

dhg.random.set_seed(seed)[source]

Set the random seed of DHG.

Note

When you call this function, the random seeds of random, numpy, and pytorch will be set, simultaneously.

Parameters

seed (int) – The specified random seed.

Generate Graph

dhg.random.graph_Gnp(num_v, prob)[source]

Return a random graph with num_v vertices and probability prob of choosing an edge.

Parameters
  • num_v (int) – The Number of vertices.

  • prob (float) – Probability of choosing an edge.

Examples

>>> import dhg.random as random
>>> g = random.graph_Gnp(4, 0.5)
>>> g.e
([(0, 1), (0, 2), (0, 3)], [1.0, 1.0, 1.0])
dhg.random.graph_Gnp_fast(num_v, prob)[source]

Return a random graph with num_v vertices and probability prob of choosing an edge. This function is an implementation of Efficient generation of large random networks paper.

Parameters
  • num_v (int) – The Number of vertices.

  • prob (float) – Probability of choosing an edge.

Examples

>>> import dhg.random as random
>>> g = random.graph_Gnp_fast(4, 0.8)
>>> g.e
([(0, 1), (0, 2), (1, 2), (0, 3), (1, 3), (2, 3)], [1.0, 1.0, 1.0, 1.0, 1.0, 1.0])
dhg.random.graph_Gnm(num_v, num_e)[source]

Return a random graph with num_v verteices and num_e edges. Edges are drawn uniformly from the set of possible edges.

Parameters
  • num_v (int) – The Number of vertices.

  • num_e (int) – The Number of edges.

Examples

>>> import dhg.random as random
>>> g = random.graph_Gnm(4, 5)
>>> g.e
([(1, 2), (0, 3), (2, 3), (0, 2), (1, 3)], [1.0, 1.0, 1.0, 1.0, 1.0])

Generate Directed Graph

dhg.random.digraph_Gnp(num_v, prob)[source]

Return a random directed graph with num_v vertices and probability prob of choosing an edge.

Parameters
  • num_v (int) – The Number of vertices.

  • prob (float) – Probability of choosing an edge.

Examples

>>> import dhg.random as random
>>> g = random.digraph_Gnp(4, 0.5)
>>> g.e
([(0, 1), (0, 2), (1, 2), (2, 1), (3, 0)], [1.0, 1.0, 1.0, 1.0, 1.0])
dhg.random.digraph_Gnp_fast(num_v, prob)[source]

Return a random directed graph with num_v vertices and probability prob of choosing an edge. This function is an implementation of Efficient generation of large random networks paper.

Parameters
  • num_v (int) – The Number of vertices.

  • prob (float) – Probability of choosing an edge.

Examples

>>> import dhg.random as random
>>> g = random.digraph_Gnp_fast(4, 0.6)
>>> g.e
([(0, 1), (0, 3), (1, 3), (2, 3), (1, 0), (2, 1)], [1.0, 1.0, 1.0, 1.0, 1.0, 1.0])
dhg.random.digraph_Gnm(num_v, num_e)[source]

Return a random directed graph with num_v verteices and num_e edges. Edges are drawn uniformly from the set of possible edges.

Parameters
  • num_v (int) – The Number of vertices.

  • num_e (int) – The Number of edges.

Examples

>>> import dhg.random as random
>>> g = random.digraph_Gnm(4, 6)
>>> g.e
([(1, 2), (2, 1), (0, 3), (2, 0), (2, 3), (0, 2)], [1.0, 1.0, 1.0, 1.0, 1.0, 1.0])

Generate Bipartite Graph

dhg.random.bigraph_Gnp(num_u, num_v, prob)[source]

Return a random bipartite graph with num_u vertices in set \(\mathcal{U}\) and num_v vertices in set \(\mathcal{V}\) and probability prob of choosing an edge.

Parameters
  • num_u (int) – The Number of vertices in set \(\mathcal{U}\).

  • num_v (int) – The Number of vertices in set \(\mathcal{V}\).

  • prob (float) – Probability of choosing an edge.

Examples

>>> import dhg.random as random
>>> g = random.bigraph_Gnp(2, 3, 0.6)
>>> g.e
([(0, 1), (1, 0), (1, 2)], [1.0, 1.0, 1.0])
dhg.random.bigraph_Gnm(num_u, num_v, num_e)[source]

Return a random bipartite graph with num_u vertices in set \(\mathcal{U}\) and num_v vertices in set \(\mathcal{V}\) and num_e edges. Edges are drawn uniformly from the set of possible edges.

Parameters
  • num_u (int) – The Number of vertices in set \(\mathcal{U}\).

  • num_v (int) – The Number of vertices in set \(\mathcal{V}\).

  • num_e (int) – The Number of edges.

Examples

>>> import dhg.random as random
>>> g = random.bigraph_Gnm(3, 3, 5)
>>> g.e
([(1, 2), (2, 1), (1, 1), (2, 0), (1, 0)], [1.0, 1.0, 1.0, 1.0, 1.0])

Generate Hypergraph

dhg.random.uniform_hypergraph_Gnp(k, num_v, prob)[source]

Return a random k-uniform hypergraph with num_v vertices and probability prob of choosing a hyperedge.

Parameters
  • num_v (int) – The Number of vertices.

  • k (int) – The Number of vertices in each hyperedge.

  • prob (float) – Probability of choosing a hyperedge.

Examples

>>> import dhg.random as random
>>> hg = random.uniform_hypergraph_Gnp(3, 5, 0.5)
>>> hg.e
([(0, 1, 3), (0, 1, 4), (0, 2, 4), (1, 3, 4), (2, 3, 4)], [1.0, 1.0, 1.0, 1.0, 1.0])
dhg.random.uniform_hypergraph_Gnm(k, num_v, num_e)[source]

Return a random k-uniform hypergraph with num_v vertices and num_e hyperedges.

Parameters
  • k (int) – The Number of vertices in each hyperedge.

  • num_v (int) – The Number of vertices.

  • num_e (int) – The Number of hyperedges.

Examples

>>> import dhg.random as random
>>> hg = random.uniform_hypergraph_Gnm(3, 5, 4)
>>> hg.e
([(0, 1, 2), (0, 1, 3), (0, 3, 4), (2, 3, 4)], [1.0, 1.0, 1.0, 1.0])
dhg.random.hypergraph_Gnm(num_v, num_e, prob_k_list=None)[source]

Return a random hypergraph with num_v vertices and num_e hyperedges.

Parameters
  • num_v (int) – The Number of vertices.

  • num_e (int) – The Number of hyperedges.

Examples

>>> import dhg.random as random
>>> hg = random.hypergraph_Gnm(5, 4)
>>> hg.e
([(0, 1, 3, 4), (0, 2, 3, 4), (0, 2, 3), (0, 2, 4)], [1.0, 1.0, 1.0, 1.0])