gammagl.transforms.DropEdge¶
- class DropEdge(p=0.3)[source]¶
Randomly drop edges, as described in DropEdge: Towards Deep Graph Convolutional Networks on Node Classification paper.
- Parameters:
p (float, optional) – Probability of an edge to be dropped.
Example
>>> import numpy as np >>> from gammagl.data import graph >>> from gammagl.transforms import DropEdge >>> import tensorlayerx as tlx >>> transform = DropEdge() >>> g = graph.Graph(x=np.random.randn(5, 16), edge_index=tlx.convert_to_tensor([[0, 0, 0], [1, 2, 3]]), edge_attr=tlx.convert_to_tensor([[0,0,0],[1,1,1],[2,2,2]]),num_nodes=5,) >>> new_g = transform(g) >>> print(g) Graph(edge_index=[2, 3], edge_attr=[3, 3], x=[5, 16], num_nodes=5) >>> print(new_g) Graph(edge_index=[2, 2], edge_attr=[2, 3], x=[5, 16], num_nodes=5) >>> from gammagl.data import HeteroGraph >>> data = HeteroGraph() >>> num_papers=5 >>> num_paper_features=6 >>> num_authors=7 >>> num_authors_features=8 >>> data['paper'].x = tlx.convert_to_tensor(np.random.uniform((num_papers, num_paper_features))) >>> data['author'].x = tlx.convert_to_tensor(np.random.uniform((num_authors, num_authors_features))) >>> data['author', 'writes', 'paper'].edge_index = tlx.convert_to_tensor([[0, 0, 0], [1, 2, 3]]) # [2, num_edges] >>> data['author', 'writes', 'paper'].edge_attr = tlx.convert_to_tensor([[0, 0, 0], [1, 1, 1],[2, 2, 2]]) >>> data['author', 'writes', 'author'].edge_index = tlx.convert_to_tensor([[1, 2, 3], [2, 3, 1]]) >>> print(data) HeteroGraph( paper={ x=[5, 6] }, author={ x=[7, 8] }, (author, writes, paper)={ edge_index=[2, 3], edge_attr=[3, 3] }, (author, writes, author)={ edge_index=[2, 3] } ) >>> transform = DropEdge() >>> new_data = transform(data) >>> print(new_data) HeteroGraph( paper={ x=[5, 6] }, author={ x=[7, 8] }, (author, writes, paper)={ edge_index=[2, 2], edge_attr=[2, 3] }, (author, writes, author)={ edge_index=[2, 2] } )