Skip to content

scale

RandomizedScaleX

Bases: BaseTransform

Applies ScaleX with a scaling factor sampled uniformly from [min_scale, max_scale].

Parameters:

Name Type Description Default
min_scale float

Lower bound of the sampled scaling factor.

required
max_scale float

Upper bound of the sampled scaling factor.

required
Example

transform = RandomizedScaleX(min_scale=0.5, max_scale=2.0) data = transform(data)

Source code in src/torch_structure/transforms/scale.py
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
class RandomizedScaleX(BaseTransform):
    r"""
    Applies [ScaleX][torch_structure.transforms.scale.ScaleX] with a scaling factor sampled uniformly from
    ``[min_scale, max_scale]``.

    Args:
        min_scale (float): Lower bound of the sampled scaling factor.
        max_scale (float): Upper bound of the sampled scaling factor.

    Example:
        >>> transform = RandomizedScaleX(min_scale=0.5, max_scale=2.0)
        >>> data = transform(data)
    """

    def __init__(self, min_scale, max_scale):
        super().__init__()
        self.min_scale = min_scale
        self.max_scale = max_scale

    def forward(self, data):
        """Sample a scaling factor and apply [ScaleX][torch_structure.transforms.scale.ScaleX] with it."""
        scaling_factor = (
            torch.rand(1).item() * (self.max_scale - self.min_scale) + self.min_scale
        )
        scale_transform = ScaleX(scaling_factor=scaling_factor)
        return scale_transform(data)

forward(data)

Sample a scaling factor and apply ScaleX with it.

Source code in src/torch_structure/transforms/scale.py
93
94
95
96
97
98
99
def forward(self, data):
    """Sample a scaling factor and apply [ScaleX][torch_structure.transforms.scale.ScaleX] with it."""
    scaling_factor = (
        torch.rand(1).item() * (self.max_scale - self.min_scale) + self.min_scale
    )
    scale_transform = ScaleX(scaling_factor=scaling_factor)
    return scale_transform(data)

ScaleX

Bases: BaseTransform

Applies a scaling transformation along the x-axis of the coordinates. Args: scaling_factor (float): The factor by which to scale the x-coordinates.

Example

transform = ScaleX(scaling_factor=2.0) data = transform(data)

Source code in src/torch_structure/transforms/scale.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class ScaleX(BaseTransform):  # ToDo: Generalize to structures with non-vertical loads
    r"""
    Applies a scaling transformation along the x-axis of the coordinates.
    Args:
        scaling_factor (float): The factor by which to scale the x-coordinates.

    Example:
        >>> transform = ScaleX(scaling_factor=2.0)
        >>> data = transform(data)
    """

    def __init__(self, scaling_factor):
        super().__init__()
        self.scaling_factor = scaling_factor

    def forward(self, data):
        """Scale ``data.coords`` along x and recompute ``length``/``force`` to compensate, in place."""
        if not hasattr(data, "coords"):
            raise AttributeError("Data object has no attribute 'coords'.")
        if not hasattr(data, "force_density"):
            raise AttributeError("Data object has no attribute 'force_density'.")
        if not hasattr(data, "force"):
            raise AttributeError("Data object has no attribute 'force'.")

        data.coords[:, 0] *= self.scaling_factor
        data.length = data.length_from_coords
        data.force = data.length * data.force_density

        return data

    def __repr__(self):
        return f"{self.__class__.__name__}(scaling_factor={self.scaling_factor})"

forward(data)

Scale data.coords along x and recompute length/force to compensate, in place.

Source code in src/torch_structure/transforms/scale.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def forward(self, data):
    """Scale ``data.coords`` along x and recompute ``length``/``force`` to compensate, in place."""
    if not hasattr(data, "coords"):
        raise AttributeError("Data object has no attribute 'coords'.")
    if not hasattr(data, "force_density"):
        raise AttributeError("Data object has no attribute 'force_density'.")
    if not hasattr(data, "force"):
        raise AttributeError("Data object has no attribute 'force'.")

    data.coords[:, 0] *= self.scaling_factor
    data.length = data.length_from_coords
    data.force = data.length * data.force_density

    return data

ScaleZ

Bases: BaseTransform

Applies a scaling transformation along the z-axis of the coordinates. Args: scaling_factor (float): The factor by which to scale the z-coordinates.

Example

transform = ScaleZ(scaling_factor=2.0) data = transform(data)

Source code in src/torch_structure/transforms/scale.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
class ScaleZ(BaseTransform):  # ToDo: Generalize to structures with non-vertical loads
    r"""
    Applies a scaling transformation along the z-axis of the coordinates.
    Args:
        scaling_factor (float): The factor by which to scale the z-coordinates.

    Example:
        >>> transform = ScaleZ(scaling_factor=2.0)
        >>> data = transform(data)
    """

    def __init__(self, scaling_factor):
        super().__init__()
        self.scaling_factor = scaling_factor

    def forward(self, data):
        """Scale ``data.coords`` along z and rescale ``force_density``/``force`` to compensate, in place."""
        if not hasattr(data, "coords"):
            raise AttributeError("Data object has no attribute 'coords'.")
        if not hasattr(data, "force_density"):
            raise AttributeError("Data object has no attribute 'force_density'.")
        if not hasattr(data, "force"):
            raise AttributeError("Data object has no attribute 'force'.")

        data.coords[:, 2] *= self.scaling_factor
        data.force_density *= 1 / self.scaling_factor
        data.length = data.length_from_coords
        data.force = data.length * data.force_density

        return data

    def __repr__(self):
        return f"{self.__class__.__name__}(scaling_factor={self.scaling_factor})"

forward(data)

Scale data.coords along z and rescale force_density/force to compensate, in place.

Source code in src/torch_structure/transforms/scale.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def forward(self, data):
    """Scale ``data.coords`` along z and rescale ``force_density``/``force`` to compensate, in place."""
    if not hasattr(data, "coords"):
        raise AttributeError("Data object has no attribute 'coords'.")
    if not hasattr(data, "force_density"):
        raise AttributeError("Data object has no attribute 'force_density'.")
    if not hasattr(data, "force"):
        raise AttributeError("Data object has no attribute 'force'.")

    data.coords[:, 2] *= self.scaling_factor
    data.force_density *= 1 / self.scaling_factor
    data.length = data.length_from_coords
    data.force = data.length * data.force_density

    return data