Skip to content

gaussian_xyz_noise

AddGaussianXYZNoise

Bases: BaseTransform

Applies independent Gaussian multiplicative noise to the x-, y-, and z-coordinate of each node.

Parameters:

Name Type Description Default
std float

The standard deviation of the noise coefficient.

0.1
Example

transform = AddGaussianXYZNoise(std=0.1) data = transform(data)

Source code in src/torch_structure/transforms/gaussian_xyz_noise.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class AddGaussianXYZNoise(BaseTransform):
    r"""
    Applies independent Gaussian multiplicative noise to the x-, y-, and z-coordinate of each node.

    Args:
        std (float): The standard deviation of the noise coefficient.

    Example:
        >>> transform = AddGaussianXYZNoise(std=0.1)
        >>> data = transform(data)
    """

    def __init__(self, std=0.1):
        super().__init__()
        self.std = std

    def forward(self, data):
        """Apply the multiplicative Gaussian xyz-noise to ``data.coords`` in place."""
        if not hasattr(data, "coords"):
            raise AttributeError("Data object has no attribute 'coords'.")

        device = data.coords.device

        x_noise = torch.randn(data.num_nodes, device=device) * self.std
        y_noise = torch.randn(data.num_nodes, device=device) * self.std
        z_noise = torch.randn(data.num_nodes, device=device) * self.std
        data.coords[:, 0] = (1 + x_noise) * data.coords[:, 0]
        data.coords[:, 1] = (1 + y_noise) * data.coords[:, 1]
        data.coords[:, 2] = (1 + z_noise) * data.coords[:, 2]

        return data

    def __repr__(self):
        return (
            f"{self.__class__.__name__}(max_noise={self.max_noise}, "
            f"n_eigenvectors={self.n_eigenvectors})"
        )

forward(data)

Apply the multiplicative Gaussian xyz-noise to data.coords in place.

Source code in src/torch_structure/transforms/gaussian_xyz_noise.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def forward(self, data):
    """Apply the multiplicative Gaussian xyz-noise to ``data.coords`` in place."""
    if not hasattr(data, "coords"):
        raise AttributeError("Data object has no attribute 'coords'.")

    device = data.coords.device

    x_noise = torch.randn(data.num_nodes, device=device) * self.std
    y_noise = torch.randn(data.num_nodes, device=device) * self.std
    z_noise = torch.randn(data.num_nodes, device=device) * self.std
    data.coords[:, 0] = (1 + x_noise) * data.coords[:, 0]
    data.coords[:, 1] = (1 + y_noise) * data.coords[:, 1]
    data.coords[:, 2] = (1 + z_noise) * data.coords[:, 2]

    return data