SetRandomValue#
- class SetRandomValue(sigma=0.05, clip=0.05, keys=('energy',))[source]#
Bases:
objectOverwrite one or more keys with clipped Gaussian noise.
Replaces each listed key in place with freshly sampled Gaussian noise (std
sigma, clamped to[-clip, clip]) of the same shape – the original values are discarded entirely (unlike the additive/multiplicative jitter transforms). Useful as an ablation that destroys the information in a feature while preserving its shape. Always applies (no probability gate). Requires each listed key to be present (raisesValueErrorotherwise). Registered asSetRandomValue– use this string as thetypein atransform=[...]config list.- Parameters:
sigma (float) – standard deviation of the replacement noise. Defaults to
0.05.clip (float) – magnitude the noise is clamped to (must be
> 0). Defaults to0.05.keys (str | Sequence[str]) – keys to overwrite. A bare string is wrapped into a single-element tuple. Defaults to
("energy",).
Example
>>> import numpy as np >>> from pimm.datasets.transform import SetRandomValue >>> np.random.seed(0) >>> data = {"energy": np.array([[100.], [100.], [100.]], dtype="f4")} >>> out = SetRandomValue(sigma=0.05, keys=("energy",))(data) >>> out["energy"].shape # same shape, original values discarded (3, 1) >>> bool(np.abs(out["energy"]).max() <= 0.05) # overwritten with clipped noise True