RandomDrop#

class RandomDrop(key: str, p_apply: float = 0.5, p_drop: float = 0.2, value: float = 0.0)[source]#

Bases: object

Randomly overwrite a fraction of one key’s rows with a constant.

With probability p_apply (and only if key is present), selects a random p_drop fraction of the rows of data_dict[key] and sets them to value – a feature-masking augmentation that keeps the point count unchanged. Registered as RandomDrop – use this string as the type in a transform=[...] config list.

Parameters:
  • key (str) – the per-point key whose rows may be overwritten.

  • p_apply (float) – probability of applying the transform to a sample. Defaults to 0.5.

  • p_drop (float) – fraction of rows to overwrite when applied. Defaults to 0.2.

  • value (float) – constant written into the selected rows. Defaults to 0.0.

Note

Operates on a single named key only; it does not touch coord or other point-aligned arrays, so the cloud geometry is preserved.

Example

>>> import numpy as np
>>> from pimm.datasets.transform import RandomDrop
>>> np.random.seed(0)
>>> data = {"energy": np.array([[1.], [2.], [3.], [4.]], dtype="f4")}
>>> out = RandomDrop(key="energy", p_apply=1.0, p_drop=0.5, value=0.0)(data)
>>> # NOTE: the write uses data[key][idx][:] = value, which assigns into a
>>> # fancy-index COPY -- so as written the rows are left unchanged:
>>> out["energy"].ravel()
array([1., 2., 3., 4.], dtype=float32)