torchsig.utils.random.Seedable¶
- class torchsig.utils.random.Seedable(seed: int | None = None, parent: Seedable | None = None, **kwargs)[source]¶
Bases:
objectA class/interface representing objects capable of accessing random numbers and being seeded.
Stores an internal random number generator object. Can be seeded with the Seedable.seed(seed_value: int) function. Two Seedable objects with the same seed will always generate/access the same random values in the same order. Containing or composing Seedable objects are generally responsible for seeding contained or composed Seedable objects.
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.
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__(seed: int | None = None, parent: Seedable | None = None, **kwargs)[source]¶
Initializes seedable object with self.seed = seed.
If a parent Seedable object is passed in, they will share random number generators, and the seed argument will not be used.
- Parameters:
seed – Seed for use for number generators. Defaults to None.
parent – Parent Seedable responsible for seeding this object. Defaults to None.
**kwargs – Additional keyword arguments.
- add_parent(parent: Seedable, register: bool = True) None[source]¶
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.
- seed(seed: int) None[source]¶
Seed number generators with given seed.
- Parameters:
seed – Seed to use.
- get_second_seed(seed: int) int[source]¶
Gets second seed, usually used to seed both torch and numpy generators with slightly different seeds.
- Parameters:
seed – Seed to use.
- Returns:
New seed.
- __repr__() str[source]¶
Printable representation with seed and parent.
- Returns:
String representation of the object.
- get_distribution(params: list | tuple | float, scaling: str = 'linear') Distribution[source]¶
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: