Skip to content
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

Add relabel node functionality to dropout_node #8524

Merged
merged 23 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
809c075
Adding typing and TorchScript support
Jun 14, 2022
12d5d31
Adding Typing to JumpingKnowledge and Torch Script Support
Jun 14, 2022
e2c0601
Merge branch 'master' of github.com:will-leeson/pytorch_geometric
Jun 14, 2022
8b31c3d
Fixing comment
Jun 14, 2022
3e2152f
Update torch_geometric/nn/models/jumping_knowledge.py
Jun 14, 2022
85ffaaa
update
rusty1s Jun 15, 2022
e667f2a
Merge branch 'pyg-team:master' into master
Jun 15, 2022
d72c0fa
Merge branch 'master' of github.com:will-leeson/pytorch_geometric
Dec 4, 2023
abdd2e9
Adding relabel node functionality to dropout_nodes
Dec 4, 2023
150d424
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 4, 2023
087ccef
Adding Changelog
Dec 4, 2023
ec91314
Merge branch 'master' of github.com:will-leeson/pytorch_geometric
Dec 4, 2023
56d9016
Merge branch 'master' into master
Dec 4, 2023
65662c2
Updating for pre-commit bot
Dec 4, 2023
b74020f
Merge branch 'master' of github.com:will-leeson/pytorch_geometric
Dec 4, 2023
def651f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 4, 2023
b40421b
Merge branch 'master' into master
EdisonLeeeee Dec 5, 2023
28573b9
Update dropout.py
EdisonLeeeee Dec 5, 2023
af4924e
Update CHANGELOG.md
EdisonLeeeee Dec 5, 2023
757c7ba
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 5, 2023
9977128
Merge branch 'master' into master
EdisonLeeeee Dec 5, 2023
334f4a0
Update dropout.py
EdisonLeeeee Dec 5, 2023
fbfe532
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 5, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Added

- Added relabel node functionality to `dropout_node` ([#8524](https://github.com/pyg-team/pytorch_geometric/pull/8524))
- Added support for type checking via `mypy` ([#8254](https://github.com/pyg-team/pytorch_geometric/pull/8254))
- Added support for link-prediction retrieval metrics ([#8499](https://github.com/pyg-team/pytorch_geometric/pull/8499))
- Added METIS partitioning with CSC/CSR format selection in `ClusterData` ([#8438](https://github.com/pyg-team/pytorch_geometric/pull/8438))
Expand Down
14 changes: 11 additions & 3 deletions torch_geometric/utils/dropout.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ def dropout_adj(
return edge_index, edge_attr


def dropout_node(edge_index: Tensor, p: float = 0.5,
num_nodes: Optional[int] = None,
training: bool = True) -> Tuple[Tensor, Tensor, Tensor]:
def dropout_node(
edge_index: Tensor,
p: float = 0.5,
num_nodes: Optional[int] = None,
training: bool = True,
relabel_nodes: bool = False,
) -> Tuple[Tensor, Tensor, Tensor]:
r"""Randomly drops nodes from the adjacency matrix
:obj:`edge_index` with probability :obj:`p` using samples from
a Bernoulli distribution.
Expand All @@ -108,6 +112,9 @@ def dropout_node(edge_index: Tensor, p: float = 0.5,
:obj:`max_val + 1` of :attr:`edge_index`. (default: :obj:`None`)
training (bool, optional): If set to :obj:`False`, this operation is a
no-op. (default: :obj:`True`)
relabel_nodes (bool, optional): If set to `True`, the resulting
`edge_index` will be relabeled to hold consecutive indices
starting from zero.

:rtype: (:class:`LongTensor`, :class:`BoolTensor`, :class:`BoolTensor`)

Expand Down Expand Up @@ -138,6 +145,7 @@ def dropout_node(edge_index: Tensor, p: float = 0.5,
node_mask = prob > p
edge_index, _, edge_mask = subgraph(node_mask, edge_index,
num_nodes=num_nodes,
relabel_nodes=relabel_nodes,
return_edge_mask=True)
return edge_index, edge_mask, node_mask

Expand Down
Loading