torchsig.utils.random.Distribution

class torchsig.utils.random.Distribution(params: Any, **kwargs)[source]

Bases: Seedable

A class for representing random distributions.

Created by calling get_distribution(params) on a Seedable object. Distributions are callable, such that some_seedable.get_distribution(params)() should return a random number from the distribution.

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.

get_value

Samples from distribution function, returns a value.

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__(params: Any, **kwargs)[source]

Initialize distribution with given parameters.

Parameters:
  • params – Parameters for the distribution.

  • **kwargs – Additional keyword arguments.

__repr__() str[source]

Printable representation with params, seed, and parent.

Returns:

String representation of the object.

get_value() Any[source]

Samples from distribution function, returns a value.

Raises:

NotImplementedError – Subclasses must implement this method.

Returns:

Value(s) from distribution.

__call__(size: int | None = None) Any | ndarray[source]

Distribution can return single value or np array of values sampled.

Parameters:

size – Number of values to return. Defaults to None.

Returns:

Value(s) sampled from distribution.

add_parent(parent: Seedable) None

Add parent Seedable object and set up RNGs accordingly.

Parameters:

parent – Parent Seedable object to add.

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.