egc.utils.graph_augmentation.transforms package

Submodules

egc.utils.graph_augmentation.transforms.feature_dropout module

Feature Dropout

class egc.utils.graph_augmentation.transforms.feature_dropout.FeatureDropout(p=0.5)[source]

Bases: BaseTransform

Augment features by randomly masking node feautres with 0.

Parameters:

p (float, optional) – Probability of a node feautre to be masked.

Example

>>> import dgl
>>> import torch
>>> from dglAug import FeatureDropout
>>> transform = FeatureDropout(p=0.2)
>>> g = dgl.rand_graph(4,2)
>>> g.ndata['feat'] = torch.rand((4,5))
>>> print(g.ndata['feat'])
tensor([[0.7706, 0.3505, 0.1246, 0.5076, 0.3071],
    [0.5388, 0.6082, 0.5088, 0.8058, 0.4955],
    [0.7638, 0.3115, 0.4265, 0.5507, 0.4404],
    [0.3127, 0.0056, 0.1876, 0.9971, 0.6389]])
>>> g = transform(g)
>>> print(g.ndata['feat'])
tensor([[0.0000, 0.0000, 0.1558, 0.6345, 0.3839],
    [0.0000, 0.7603, 0.6360, 0.0000, 0.6194],
    [0.0000, 0.3893, 0.5331, 0.0000, 0.5505],
    [0.3909, 0.0070, 0.2345, 1.2464, 0.0000]])

egc.utils.graph_augmentation.transforms.node_shuffle module

Randomly shuffle

class egc.utils.graph_augmentation.transforms.node_shuffle.NodeShuffle(is_use=True)[source]

Bases: BaseTransform

Randomly shuffle the nodes.

Example

>>> import dgl
>>> import torch
>>> from dgl import NodeShuffle
>>> transform = NodeShuffle()
>>> g = dgl.graph(([0, 1], [1, 2]))
>>> g.ndata['h1'] = torch.tensor([[1., 2.], [3., 4.], [5., 6.]])
>>> g.ndata['h2'] = torch.tensor([[7., 8.], [9., 10.], [11., 12.]])
>>> g = transform(g)
>>> print(g.ndata['h1'])
tensor([[5., 6.],
        [3., 4.],
        [1., 2.]])
>>> print(g.ndata['h2'])
tensor([[11., 12.],
        [ 9., 10.],
        [ 7.,  8.]])

egc.utils.graph_augmentation.transforms.random_mask module

random mask

class egc.utils.graph_augmentation.transforms.random_mask.RandomMask(p=0.5)[source]

Bases: BaseTransform

Augment features by randomly masking node feautres with 0.

Parameters:

p (float, optional) – Probability of a node feautre to be masked.

Example

>>> import dgl
>>> import torch
>>> from graph_augmentation import RandomMask
>>> transform = RandomMask(p=0.5)
>>> g = dgl.rand_graph(4,2)
>>> g.ndata['feat'] = torch.rand((4,5))
>>> print(g.ndata['feat'])
tensor([[0.6242, 0.5736, 0.0784, 0.7627, 0.0377],
        [0.1672, 0.7696, 0.5750, 0.6666, 0.4387],
        [0.4001, 0.4118, 0.6463, 0.9568, 0.3902],
        [0.9920, 0.9099, 0.5543, 0.6682, 0.2897]])
>>> g = transform(g)
>>> print(g.ndata['feat'])
tensor([[0.6242, 0.0000, 0.0000, 0.0000, 0.0377],
        [0.1672, 0.0000, 0.0000, 0.0000, 0.4387],
        [0.4001, 0.0000, 0.0000, 0.0000, 0.3902],
        [0.9920, 0.0000, 0.0000, 0.0000, 0.2897]])

Module contents

init