Skip to content

fix the bug of the visualization #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
- 2022-12-28 -> **v0.9.3** 正式发布! 包含更多数据集和超图操作!
- 2022-09-25 -> **v0.9.2** is now available! More datasets, SOTA models, and visualizations are included!
- 2022-09-25 -> **v0.9.2** 正式发布! 包含更多数据集、最新模型和可视化功能!
- 2022-08-25 -> DHG's first version **v0.9.1** is now available!
- 2022-08-25 -> DHG's first version **v0.9.1** is now available!
- 2022-08-25 -> DHG的第一个版本 **v0.9.1** 正式发布!


**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**.

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.
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.

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.

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

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

## Highlights

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

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

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.
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.
If you find any bugs, please report it to us in [GitHub Issues](https://github.com/iMoonLab/DeepHypergraph/issues).

### Dependencies

**DHG** requires the following dependencies:

- Python >= 3.8
- PyTorch >= 1.12.1, < 2.0
- scipy >= 1.8
- matplotlib >= 3.7.0
- numpy
- scikit-learn
- optuna
- requests

For visualization features, matplotlib 3.7.0 or higher is required to properly render 3D plots.

## Quick Start

### Visualization
Expand Down Expand Up @@ -227,7 +243,7 @@ class GCNConv(nn.Module):
self.reset_parameters()

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

## License

DHG uses Apache License 2.0.
DHG uses Apache License 2.0.
23 changes: 11 additions & 12 deletions dhg/visualization/feature/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def make_animation(embeddings: np.ndarray, colors: Union[np.ndarray, str], cmap=
r"""Make an animation of embeddings.

Args:
``embeddings`` (``np.ndarray``): The embedding matrix. Size :math:`(N, 3)`.
``colors`` (``Union[np.ndarray, str]``): The color matrix. ``str`` or Size :math:`(N, )`.
``embeddings`` (``np.ndarray``): The embedding matrix. Size :math:`(N, 3)`.
``colors`` (``Union[np.ndarray, str]``): The color matrix. ``str`` or Size :math:`(N, )`.
``cmap`` (``str``, optional): The `color map <https://matplotlib.org/stable/tutorials/colors/colormaps.html>`_. Defaults to ``"viridis"``.
"""
embeddings = normalize(embeddings)
Expand All @@ -29,7 +29,7 @@ def init():
if colors is not None:
ax.scatter(x, y, z, c=colors, cmap=cmap)
else:
ax.scatter(x, y, z, cmap=cmap)
ax.scatter(x, y, z)
return fig

def animate(i):
Expand All @@ -41,7 +41,7 @@ def animate(i):

def plot_2d_embedding(embeddings: np.ndarray, label: Optional[np.ndarray] = None, cmap="viridis"):
r"""Plot the embedding in 2D.

Args:
``embeddings`` (``np.ndarray``): The embedding matrix. Size :math:`(N, 2)`.
``label`` (``np.ndarray``, optional): The label matrix.
Expand All @@ -52,16 +52,15 @@ def plot_2d_embedding(embeddings: np.ndarray, label: Optional[np.ndarray] = None
if label is not None:
plt.scatter(embeddings[:, 0], embeddings[:, 1], c=label, cmap=cmap)
else:
plt.scatter(embeddings[:, 0], embeddings[:, 1], cmap=cmap)

plt.xlim((0, 1.0))
plt.ylim((0, 1.0))
plt.scatter(embeddings[:, 0], embeddings[:, 1])
plt.xlim(0, 1.0)
plt.ylim(0, 1.0)
fig.tight_layout()


def plot_3d_embedding(embeddings: np.ndarray, label: Optional[np.ndarray] = None, cmap="viridis"):
r"""Plot the embedding in 3D.

Args:
``embeddings`` (``np.ndarray``): The embedding matrix. Size :math:`(N, 3)`.
``label`` (``np.ndarray``, optional): The label matrix.
Expand All @@ -70,11 +69,11 @@ def plot_3d_embedding(embeddings: np.ndarray, label: Optional[np.ndarray] = None
embeddings = normalize(embeddings)
x, y, z = embeddings[:, 0], embeddings[:, 1], embeddings[:, 2]
fig = plt.figure(figsize=(8, 8))
ax = fig.gca(projection="3d")
ax = fig.add_subplot(111, projection="3d")
if label is not None:
ax.scatter(x, y, z, c=label, cmap=cmap)
else:
ax.scatter(x, y, z, cmap=cmap)
ax.scatter(x, y, z)

ax.set_xlim3d(0, 1.0)
ax.set_ylim3d(0, 1.0)
Expand All @@ -90,7 +89,7 @@ def normalize(coor):
# for poincare_ball
def tanh(x, clamp=15):
r"""Calculate the tanh value of the matrix x.

Args:
``x`` (``np.ndarray``): The feature matrix. Size :math:`(N, C)`.
``clap`` (``int``): Boundary value.
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ sphinxcontrib-bibtex
numpy
optuna
torch>=1.11.0
matplotlib
matplotlib>=3.7.0
scikit-learn
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ optuna = "*"
numpy = "*"
scikit-learn = "*"
requests = "*"
matplotlib = "*"
matplotlib = ">= 3.7.0"

[tool.poetry.dev-dependencies]

Expand Down
2 changes: 1 addition & 1 deletion tests/random/test_random_hypergraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_uniform_hypergraph_Gnp():
assert all(map(lambda e: len(e) == k, edges))

max_n_e = C(n_v, k)
assert pytest.approx(g.num_e / max_n_e, 1) == prob
assert pytest.approx(g.num_e / max_n_e, rel=0.5) == prob


def test_uniform_hypergraph_Gnm():
Expand Down