torchsig.utils.random.Distribution¶
- class torchsig.utils.random.Distribution(params: Any, **kwargs)[source]¶
Bases:
SeedableA 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 Seedable object and set up RNGs accordingly.
Create distribution function with proper seeding.
Gets second seed, usually used to seed both torch and numpy generators with slightly different seeds.
Samples from distribution function, returns a value.
Seed number generators with given seed.
Initialize torch and numpy number generators, and update its children.
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, 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: