RandomJitter#
- class RandomJitter(sigma=0.01, clip=0.05, keys=('coord',), p=1.0)[source]#
Bases:
objectAdd clipped Gaussian noise to one or more point-aligned keys.
With probability
p, adds independent Gaussian noise (stdsigma, clamped to[-clip, clip]) to each listed key in place. The noise has the same shape as the target array, so by default it perturbscoordper point and per dimension. Requires each listed key to be present (raisesValueErrorotherwise). Registered asRandomJitter– use this string as thetypein atransform=[...]config list.- Parameters:
sigma (float) – standard deviation of the additive Gaussian noise. Defaults to
0.01.clip (float) – magnitude the noise is clamped to (must be
> 0). Defaults to0.05.keys (str | Sequence[str]) – keys to jitter. A bare string is wrapped into a single-element tuple. Defaults to
("coord",).p (float) – probability of applying the jitter. Defaults to
1.0.
Note
The noise is additive; for multiplicative scalar noise (e.g. on energy) use
MultiplicativeRandomJitter.Example
>>> import numpy as np >>> from pimm.datasets.transform import RandomJitter >>> np.random.seed(0) >>> data = {"coord": np.zeros((3, 3), dtype="f4")} >>> out = RandomJitter(sigma=0.01, clip=0.05, keys=("coord",), p=1.0)(data) >>> out["coord"].shape # one independent noise value per point per axis (3, 3) >>> bool(np.any(out["coord"] != 0)) and bool(np.abs(out["coord"]).max() <= 0.05) True