torchsig.transforms.base_transforms.RandomApply

class torchsig.transforms.base_transforms.RandomApply(transform, probability: float, **kwargs)[source]

Bases: Transform

Randomly applies transform with probability p.

This transform applies the specified transform with a given probability.

transform

Transform to randomly apply.

probability

Probability to apply transform in range [0., 1.].

Methods

add_parent

Add parent Seedable object and set up RNGs accordingly.

get_distribution

Create distribution function with proper seeding.

get_second_seed

Gets second seed, usually used to seed both torch and numpy generators with slightly different seeds.

seed

Seed number generators with given seed.

setup_rngs

Initialize torch and numpy number generators, and update its children.

update_from_parent

Update numpy and torch number generators with parent seed.

__init__(transform, probability: float, **kwargs)[source]

Initialize the RandomApply transform.

Parameters:
  • transform – Transform to randomly apply.

  • probability – Probability to apply transform in range [0., 1.].

  • **kwargs – Additional keyword arguments passed to the parent class.

__call__(signal: Signal) Signal[source]

Apply the transform with the specified probability.

Parameters:

signal – Signal to be transformed.

Returns:

Transformed signal if the random number is less than probability, otherwise the original signal.

__repr__() str

Transform string representation.

Should be able to recreate class from this string.

Returns:

Transform representation.

__str__() str

String representation of the transform.

Returns:

String representation of the transform.

add_parent(parent: Seedable, register: bool = True) None

Add parent Seedable object and set up RNGs accordingly.

Parameters:
  • parent – Parent Seedable object to add.

  • register – If True (default), add self to parent.children so that future seed propagation reaches this object. Pass False for transient objects (e.g. per-sample Signal instances) that only need the parent link for metadata/RNG access during their lifetime but must not accumulate in the parent’s child list, which would otherwise cause unbounded memory growth.

get_distribution(params: list | tuple | float, scaling: str = 'linear') Distribution

Create distribution function with proper seeding.

Parameters:
  • params – Parameters for distribution.

  • scaling – Scaling param for distribution. Defaults to ‘linear’.

Returns:

Distribution function, seeded.

Return type:

Distribution

get_second_seed(seed: int) int

Gets second seed, usually used to seed both torch and numpy generators with slightly different seeds.

Parameters:

seed – Seed to use.

Returns:

New seed.

seed(seed: int) None

Seed number generators with given seed.

Parameters:

seed – Seed to use.

setup_rngs() None

Initialize torch and numpy number generators, and update its children.

update_from_parent() None

Update numpy and torch number generators with parent seed.