dhg.random
Random Seed
Generate Graph
- dhg.random.graph_Gnp(num_v, prob)[source]
Return a random graph with
num_vvertices and probabilityprobof 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_vvertices and probabilityprobof 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_vverteices andnum_eedges. 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_vvertices and probabilityprobof 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_vvertices and probabilityprobof 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_vverteices andnum_eedges. 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_uvertices in set \(\mathcal{U}\) andnum_vvertices in set \(\mathcal{V}\) and probabilityprobof 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_uvertices in set \(\mathcal{U}\) andnum_vvertices in set \(\mathcal{V}\) andnum_eedges. 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 withnum_vvertices and probabilityprobof 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 withnum_vvertices andnum_ehyperedges.- 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_vvertices andnum_ehyperedges.- 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])