Skip to content

Commit 9e93f29

Browse files
committed
hypergraph_Gnm: low_order_first & high_order_first, vis_strcture.rst: Basic Usage
1 parent 10ca59f commit 9e93f29

6 files changed

Lines changed: 97 additions & 11 deletions

File tree

‎dhg/random/hypergraphs/hypergraph.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def uniform_hypergraph_Gnm(k: int, num_v: int, num_e: int):
6464

6565
def hypergraph_Gnm(num_v: int, num_e: int, method:str="uniform", prob_k_list: Optional[List[float]] = None):
6666
r"""Return a random hypergraph with ``num_v`` vertices and ``num_e`` hyperedges. The ``method`` argument determines the distribution of the hyperedge degree.
67-
The ``method`` can be one of ``"uniform"``, ``"low_order_first"``, ``"high_order_first"``.
67+
The ``method`` can be one of ``"uniform"``, ``"low_order_first"``, ``"high_order_first"``.
6868
69-
- If set to ``"uniform"``, the number of hyperedges with the same degree will approximately to the capacity of each hyperedge degree.
69+
- If set to ``"uniform"``, the number of hyperedges with the same degree will approximately to the capacity of each hyperedge degree.
7070
For example, the ``num_v`` is :math:`10`. The capacity of hyperedges with degree :math:`2` is :math:`C^2_{10} = 45`.
7171
- If set to ``"low_order_first"``, the generated hyperedges will tend to have low degrees.
7272
- If set to ``"high_order_first"``, the generated hyperedges will tend to have high degrees.
@@ -90,10 +90,13 @@ def hypergraph_Gnm(num_v: int, num_e: int, method:str="uniform", prob_k_list: Op
9090
if method == "uniform":
9191
prob_k_list = [C(num_v, k) / (2 ** num_v - 1) for k in deg_e_list]
9292
elif method == "low_order_first":
93-
# TODO
94-
raise NotImplementedError
93+
prob_k_list = [1.8 ** (-k) for k in deg_e_list]
94+
sum_of_prob_k_list = sum(prob_k_list)
95+
prob_k_list = [prob_k / sum_of_prob_k_list for prob_k in prob_k_list]
9596
elif method == "high_order_first":
96-
raise NotImplementedError
97+
prob_k_list = [1.8 ** (-k) for k in deg_e_list].reverse()
98+
sum_of_prob_k_list = sum(prob_k_list)
99+
prob_k_list = [prob_k / sum_of_prob_k_list for prob_k in prob_k_list]
97100
else:
98101
raise ValueError(f"Unknown method: {method}")
99102

140 KB
Loading
59.5 KB
Loading
47 KB
Loading
55.7 KB
Loading

‎docs/source/tutorial/vis_structure.rst‎

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,95 @@ Structure Visualization
33

44
Coming soon!
55

6-
.. Basic Usage
7-
.. --------------
8-
.. init a structure, call the draw method, and plt.show(), and plt.savefig().
6+
Basic Usage
7+
--------------
8+
DHG provides a simple interface to visualize the structures:
9+
10+
1. Create a Structure object (*i.e.*, ``Graph``, ``BiGraph``, ``DiGraph``, and ``Hypergraph``);
11+
12+
2. Call the ``draw`` method of the object;
13+
14+
3. Call ``plt.show()`` to show the figure or ``plt.savefig()`` to save the figure.
15+
16+
Visualization for ``Graph``
17+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
19+
.. code-block:: python
20+
21+
import matplotlib.pyplot as plt
22+
from dhg.random import graph_Gnm
23+
24+
g = graph_Gnm(100, 50)
25+
g.draw()
26+
plt.show()
27+
28+
29+
.. image:: ../_static/img/vis_graph.png
30+
:align: center
31+
:alt: vis_graph
32+
:height: 200px
33+
34+
35+
Visualization for ``DiGraph``
36+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
37+
38+
.. code-block:: python
39+
40+
import matplotlib.pyplot as plt
41+
from dhg.random import digraph_Gnm
42+
43+
g = digraph_Gnm(100, 50)
44+
g.draw()
45+
plt.show()
46+
47+
48+
.. image:: ../_static/img/vis_digraph.png
49+
:align: center
50+
:alt: vis_digraph
51+
:height: 200px
52+
53+
54+
Visualization for ``BiGraph``
55+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56+
57+
58+
.. code-block:: python
59+
60+
import matplotlib.pyplot as plt
61+
from dhg.random import bigraph_Gnm
62+
63+
g = bigraph_Gnm(100, 80, 20)
64+
g.draw()
65+
plt.show()
66+
67+
68+
.. image:: ../_static/img/vis_bigraph.png
69+
:align: center
70+
:alt: vis_bigraph
71+
:height: 200px
72+
73+
74+
75+
Visualization for ``Hypergraph``
76+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
77+
78+
79+
.. code-block:: python
80+
81+
import matplotlib.pyplot as plt
82+
from dhg.random import hypergraph_Gnm
83+
84+
h = hypergraph_Gnm(100, 10, method='low_order_first')
85+
h.draw()
86+
plt.show()
87+
88+
89+
.. image:: ../_static/img/vis_hypergraph.png
90+
:align: center
91+
:alt: vis_hypergraph
92+
:height: 200px
93+
94+
995

1096

1197
.. Advanced Usage
@@ -28,6 +114,3 @@ Coming soon!
28114
29115
.. Simple Hypergraph
30116
.. ~~~~~~~~~~~~~~~~~~
31-
32-
33-

0 commit comments

Comments
 (0)