Skip to content

Commit 53ff68b

Browse files
authored
Merge pull request #65 from AuroraMaster/main
fix the bug of the visualization
2 parents 5734d6a + 12178ad commit 53ff68b

File tree

5 files changed

+37
-27
lines changed

5 files changed

+37
-27
lines changed

README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
- 2022-12-28 -> **v0.9.3** 正式发布! 包含更多数据集和超图操作!
2424
- 2022-09-25 -> **v0.9.2** is now available! More datasets, SOTA models, and visualizations are included!
2525
- 2022-09-25 -> **v0.9.2** 正式发布! 包含更多数据集、最新模型和可视化功能!
26-
- 2022-08-25 -> DHG's first version **v0.9.1** is now available!
26+
- 2022-08-25 -> DHG's first version **v0.9.1** is now available!
2727
- 2022-08-25 -> DHG的第一个版本 **v0.9.1** 正式发布!
2828

2929

3030
**DHG** *(DeepHypergraph)* is a deep learning library built upon [PyTorch](https://pytorch.org) for learning with both Graph Neural Networks and Hypergraph Neural Networks. It is a general framework that supports both low-order and high-order message passing like **from vertex to vertex**, **from vertex in one domain to vertex in another domain**, **from vertex to hyperedge**, **from hyperedge to vertex**, **from vertex set to vertex set**.
3131

32-
It supports a wide variety of structures like low-order structures (graph, directed graph, bipartite graph, etc.), high-order structures (hypergraph, etc.). Various spectral-based operations (like Laplacian-based smoothing) and spatial-based operations (like message psssing from domain to domain) are integrated inside different structures. It provides multiple common metrics for performance evaluation on different tasks. Many state-of-the-art models are implemented and can be easily used for research. We also provide various visualization tools for both low-order structures and high-order structures.
32+
It supports a wide variety of structures like low-order structures (graph, directed graph, bipartite graph, etc.), high-order structures (hypergraph, etc.). Various spectral-based operations (like Laplacian-based smoothing) and spatial-based operations (like message psssing from domain to domain) are integrated inside different structures. It provides multiple common metrics for performance evaluation on different tasks. Many state-of-the-art models are implemented and can be easily used for research. We also provide various visualization tools for both low-order structures and high-order structures.
3333

3434
In addition, DHG's [dhg.experiments](https://deephypergraph.readthedocs.io/en/latest/api/experiments.html) module (that implements **Auto-ML** upon [Optuna](https://optuna.org)) can help you automatically tune the hyper-parameters of your models in training and easily outperforms the state-of-the-art models.
3535

@@ -39,6 +39,7 @@ In addition, DHG's [dhg.experiments](https://deephypergraph.readthedocs.io/en/la
3939

4040
* [Hightlights](#highlights)
4141
* [Installation](#installation)
42+
* [Dependencies](#dependencies)
4243
* [Quick Start](#quick-start)
4344
* [Examples](#examples)
4445
* [Datasets](#datasets)
@@ -50,7 +51,7 @@ In addition, DHG's [dhg.experiments](https://deephypergraph.readthedocs.io/en/la
5051

5152
## Highlights
5253

53-
- **Support High-Order Message Passing on Structure**:
54+
- **Support High-Order Message Passing on Structure**:
5455
DHG supports pair-wise message passing on the graph structure and beyond-pair-wise message passing on the hypergraph structure.
5556

5657
- **Shared Ecosystem with Pytorch Framework**:
@@ -89,9 +90,24 @@ You can also try the nightly version (0.9.5) of **DHG** library with ``pip`` as
8990
pip install git+https://github.com/iMoonLab/DeepHypergraph.git
9091
```
9192

92-
Nightly version is the development version of **DHG**. It may include the lastest SOTA methods and datasets, but it can also be unstable and not fully tested.
93+
Nightly version is the development version of **DHG**. It may include the lastest SOTA methods and datasets, but it can also be unstable and not fully tested.
9394
If you find any bugs, please report it to us in [GitHub Issues](https://github.com/iMoonLab/DeepHypergraph/issues).
9495

96+
### Dependencies
97+
98+
**DHG** requires the following dependencies:
99+
100+
- Python >= 3.8
101+
- PyTorch >= 1.12.1, < 2.0
102+
- scipy >= 1.8
103+
- matplotlib >= 3.7.0
104+
- numpy
105+
- scikit-learn
106+
- optuna
107+
- requests
108+
109+
For visualization features, matplotlib 3.7.0 or higher is required to properly render 3D plots.
110+
95111
## Quick Start
96112

97113
### Visualization
@@ -227,7 +243,7 @@ class GCNConv(nn.Module):
227243
self.reset_parameters()
228244

229245
def forward(self, X: torch.Tensor, g: dhg.Graph) -> torch.Tensor:
230-
# apply the trainable parameters ``theta`` to the input ``X``
246+
# apply the trainable parameters ``theta`` to the input ``X``
231247
X = self.theta(X)
232248
# smooth the input ``X`` with the GCN's Laplacian
233249
X = g.smoothing_with_GCN(X)
@@ -253,7 +269,7 @@ class GATConv(nn.Module):
253269
e_atten_score = x_for_src[g.e_src] + x_for_dst[g.e_dst]
254270
e_atten_score = F.leaky_relu(e_atten_score).squeeze()
255271
# apply ``e_atten_score`` to each edge in the graph ``g``, aggragete neighbor messages
256-
# with ``softmax_then_sum``, and perform vertex->vertex message passing in graph
272+
# with ``softmax_then_sum``, and perform vertex->vertex message passing in graph
257273
# with message passing function ``v2v()``
258274
X = g.v2v(X, aggr="softmax_then_sum", e_weight=e_atten_score)
259275
X = F.elu(X)
@@ -474,4 +490,4 @@ DHG is developed by DHG's core team including [Yifan Feng](http://fengyifan.site
474490

475491
## License
476492

477-
DHG uses Apache License 2.0.
493+
DHG uses Apache License 2.0.

dhg/visualization/feature/utils.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def make_animation(embeddings: np.ndarray, colors: Union[np.ndarray, str], cmap=
1616
r"""Make an animation of embeddings.
1717
1818
Args:
19-
``embeddings`` (``np.ndarray``): The embedding matrix. Size :math:`(N, 3)`.
20-
``colors`` (``Union[np.ndarray, str]``): The color matrix. ``str`` or Size :math:`(N, )`.
19+
``embeddings`` (``np.ndarray``): The embedding matrix. Size :math:`(N, 3)`.
20+
``colors`` (``Union[np.ndarray, str]``): The color matrix. ``str`` or Size :math:`(N, )`.
2121
``cmap`` (``str``, optional): The `color map <https://matplotlib.org/stable/tutorials/colors/colormaps.html>`_. Defaults to ``"viridis"``.
2222
"""
2323
embeddings = normalize(embeddings)
@@ -29,7 +29,7 @@ def init():
2929
if colors is not None:
3030
ax.scatter(x, y, z, c=colors, cmap=cmap)
3131
else:
32-
ax.scatter(x, y, z, cmap=cmap)
32+
ax.scatter(x, y, z)
3333
return fig
3434

3535
def animate(i):
@@ -41,7 +41,7 @@ def animate(i):
4141

4242
def plot_2d_embedding(embeddings: np.ndarray, label: Optional[np.ndarray] = None, cmap="viridis"):
4343
r"""Plot the embedding in 2D.
44-
44+
4545
Args:
4646
``embeddings`` (``np.ndarray``): The embedding matrix. Size :math:`(N, 2)`.
4747
``label`` (``np.ndarray``, optional): The label matrix.
@@ -52,16 +52,15 @@ def plot_2d_embedding(embeddings: np.ndarray, label: Optional[np.ndarray] = None
5252
if label is not None:
5353
plt.scatter(embeddings[:, 0], embeddings[:, 1], c=label, cmap=cmap)
5454
else:
55-
plt.scatter(embeddings[:, 0], embeddings[:, 1], cmap=cmap)
56-
57-
plt.xlim((0, 1.0))
58-
plt.ylim((0, 1.0))
55+
plt.scatter(embeddings[:, 0], embeddings[:, 1])
56+
plt.xlim(0, 1.0)
57+
plt.ylim(0, 1.0)
5958
fig.tight_layout()
6059

6160

6261
def plot_3d_embedding(embeddings: np.ndarray, label: Optional[np.ndarray] = None, cmap="viridis"):
6362
r"""Plot the embedding in 3D.
64-
63+
6564
Args:
6665
``embeddings`` (``np.ndarray``): The embedding matrix. Size :math:`(N, 3)`.
6766
``label`` (``np.ndarray``, optional): The label matrix.
@@ -70,11 +69,11 @@ def plot_3d_embedding(embeddings: np.ndarray, label: Optional[np.ndarray] = None
7069
embeddings = normalize(embeddings)
7170
x, y, z = embeddings[:, 0], embeddings[:, 1], embeddings[:, 2]
7271
fig = plt.figure(figsize=(8, 8))
73-
ax = fig.gca(projection="3d")
72+
ax = fig.add_subplot(111, projection="3d")
7473
if label is not None:
7574
ax.scatter(x, y, z, c=label, cmap=cmap)
7675
else:
77-
ax.scatter(x, y, z, cmap=cmap)
76+
ax.scatter(x, y, z)
7877

7978
ax.set_xlim3d(0, 1.0)
8079
ax.set_ylim3d(0, 1.0)
@@ -90,7 +89,7 @@ def normalize(coor):
9089
# for poincare_ball
9190
def tanh(x, clamp=15):
9291
r"""Calculate the tanh value of the matrix x.
93-
92+
9493
Args:
9594
``x`` (``np.ndarray``): The feature matrix. Size :math:`(N, C)`.
9695
``clap`` (``int``): Boundary value.

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ sphinxcontrib-bibtex
55
numpy
66
optuna
77
torch>=1.11.0
8-
matplotlib
8+
matplotlib>=3.7.0
99
scikit-learn

pyproject.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,9 @@ dependencies = [
3636
"numpy<2.0",
3737
"scikit-learn",
3838
"requests",
39-
"matplotlib<3.6",
39+
"matplotlib>=3.7.0",
4040
]
4141

42-
[project.urls]
43-
Homepage = "https://deephypergraph.com"
44-
Repository = "https://github.com/iMoonLab/DeepHypergraph"
45-
Documentation = "https://deephypergraph.com/docs"
46-
4742
[project.optional-dependencies]
4843
dev = [
4944
"pytest",

tests/random/test_random_hypergraph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_uniform_hypergraph_Gnp():
2424
assert all(map(lambda e: len(e) == k, edges))
2525

2626
max_n_e = C(n_v, k)
27-
assert pytest.approx(g.num_e / max_n_e, 1) == prob
27+
assert pytest.approx(g.num_e / max_n_e, rel=0.5) == prob
2828

2929

3030
def test_uniform_hypergraph_Gnm():

0 commit comments

Comments
 (0)