torchsig.signals.builder.ConcatSignalGenerator¶
- class torchsig.signals.builder.ConcatSignalGenerator(signal_generators: list[BaseSignalGenerator], **kwargs: dict[str, Any])[source]¶
Bases:
BaseSignalGeneratorA Signal Generator that wraps other signal generators and returns one of their outputs at random when called.
This generator randomly selects one of the provided signal generators and returns its output. Each wrapped signal generator must be a valid BaseSignalGenerator instance.
- signal_generators¶
List of BaseSignalGenerator instances to choose from.
- random_generator¶
Random number generator used to select a signal generator.
Methods
Add parent Seedable object and set up RNGs accordingly.
Creates a deep copy of the ConcatSignalGenerator with copied signal generators.
Generates a signal by randomly selecting one of the wrapped generators.
Create distribution function with proper seeding.
Function for modifying and returning a new metadata with all the fields in parent or child, with child overriding parent in conflicts.
Gets second seed, usually used to seed both torch and numpy generators with slightly different seeds.
Lookup a metadata key with enhanced error reporting.
Get all metadata keys.
Seed number generators with given seed.
Sets the class_name to name if there wasn't already a class name set.
Initialize torch and numpy number generators, and update its children.
Update numpy and torch number generators with parent seed.
Validates metadata fields for all wrapped signal generators.
- __init__(signal_generators: list[BaseSignalGenerator], **kwargs: dict[str, Any]) None[source]¶
Initializes the ConcatSignalGenerator.
- Parameters:
signal_generators – List of BaseSignalGenerator instances to wrap.
**kwargs – Additional keyword arguments to pass to the parent class.
- Raises:
TypeError – If any of the signal_generators are not BaseSignalGenerator instances.
- copy() ConcatSignalGenerator[source]¶
Creates a deep copy of the ConcatSignalGenerator with copied signal generators.
- Returns:
A new instance of ConcatSignalGenerator with copied metadata and signal generators.
- validate_metadata_fields() bool[source]¶
Validates metadata fields for all wrapped signal generators.
Calls validate_metadata_fields() on each wrapped signal generator.
- Returns:
True if all validations pass.
- Return type:
- Raises:
ValueError – If any of the wrapped signal generators are missing required metadata fields.
- __repr__() str[source]¶
Returns a string representation of the ConcatSignalGenerator.
- Returns:
A string representation showing the class name, metadata, and signal generators.
- generate() Signal[source]¶
Generates a signal by randomly selecting one of the wrapped generators.
- Returns:
The output of a randomly selected signal generator.
- Return type:
- __call__() Signal¶
Generates a new signal and applies all transforms.
- Returns:
The generated signal after applying all transforms.
- 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:
- get_full_metadata() dict[str, Any]¶
Function for modifying and returning a new metadata with all the fields in parent or child, with child overriding parent in conflicts.
- Returns:
Dictionary containing all metadata from parent and child, with child values overriding parent values in case of conflicts.
Example
>>> parent = HierarchicalMetadataObject(metadata={"field_1": 4, "field_2": 5}) >>> child = HierarchicalMetadataObject(parent=parent, metadata={"field_2": 6}) >>> child.get_full_metadata() {'field_1': 4, 'field_2': 6}
- 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.
- key_lookup(key: str) Any¶
Lookup a metadata key with enhanced error reporting.
- Parameters:
key – The metadata key to lookup.
- Returns:
The value associated with the key.
- Raises:
MetadataAttributeError – If the key is not found in the metadata or parent metadata.
Example
>>> obj = HierarchicalMetadataObject(metadata={"key": "value"}) >>> obj.key_lookup("key") 'value'
- keys() list[str]¶
Get all metadata keys.
- Returns:
List of all metadata keys.
Example
>>> obj = HierarchicalMetadataObject(metadata={"key1": 1, "key2": 2}) >>> list(obj.keys()) ['key1', 'key2']