RandomJitter#

class RandomJitter(sigma=0.01, clip=0.05, keys=('coord',), p=1.0)[source]#

Bases: object

Add clipped Gaussian noise to one or more point-aligned keys.

With probability p, adds independent Gaussian noise (std sigma, clamped to [-clip, clip]) to each listed key in place. The noise has the same shape as the target array, so by default it perturbs coord per point and per dimension. Requires each listed key to be present (raises ValueError otherwise). Registered as RandomJitter – use this string as the type in a transform=[...] 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 to 0.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