torchsig.datasets.datasets.TorchSigIterableDataset¶
- class torchsig.datasets.datasets.TorchSigIterableDataset(signal_generators: str | ConcatSignalGenerator | list = 'all', transforms: list[Transform | callable] = [], component_transforms: list[Transform | callable] = [], target_labels: list | None = None, validate_init: bool = True, **kwargs)[source]¶
Bases:
HierarchicalMetadataObject,IterableDatasetBase class for generating signals.
The dataset will continue to generate samples infinitely.
- signal_generators¶
The signal generators to use. Can be a string, ConcatSignalGenerator, or list.
- transforms¶
List of transforms to apply to the entire signal.
- component_transforms¶
List of transforms to apply to individual signal components.
- target_labels¶
Labels to extract from the signal.
- validate_init¶
Whether to validate metadata during initialization.
Methods
Add parent Seedable object and set up RNGs accordingly.
Adds a signal generator to this dataset.
Create a copy of the object.
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.
Initializes the signal generator.
Lookup a metadata key with enhanced error reporting.
Get all metadata keys.
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.
Validates signal metadata for each signal generators.
- __init__(signal_generators: str | ConcatSignalGenerator | list = 'all', transforms: list[Transform | callable] = [], component_transforms: list[Transform | callable] = [], target_labels: list | None = None, validate_init: bool = True, **kwargs)[source]¶
Initializes the dataset.
- Parameters:
signal_generators – The signal generators to use. Can be a string, ConcatSignalGenerator, or list.
transforms – List of transforms to apply to the entire signal.
component_transforms – List of transforms to apply to individual signal components.
target_labels – Labels to extract from the signal.
validate_init – Whether to validate metadata during initialization.
**kwargs – Additional keyword arguments passed to the parent class.
- init_signal_generator(signal_generator: str | callable) None[source]¶
Initializes the signal generator.
- Parameters:
signal_generator – The signal generator to be initialized. If a string, it is first looked up to retrieve the corresponding signal generator function.
- Raises:
TypeError – If the signal_generator is neither a string nor a callable.
- add_signal_generator(signal_generator: callable, class_name: str | None = None, class_index: int | None = None, likelihood: int = 1) None[source]¶
Adds a signal generator to this dataset.
- Parameters:
signal_generator – A callable object which takes no arguments and returns a Signal.
class_name – (optional) A name for this signal class in the dataset. If None, the signal will be generated and added to the data, but no labels will be made for the signal.
likelihood – (optional) The relative likelihood of this signal type in the dataset. Doubling the likelihood will make this signal twice as likely to be placed in the data.
- validate_metadata_fields() bool[source]¶
Validates signal metadata for each signal generators.
- Returns:
Whether Signal metadata is valid.
- __call__() Signal | ndarray | tuple[source]¶
Same as next(); returns the next item in the dataset.
Allows datasets to be treated as signal generators for other datasets.
- __repr__() str[source]¶
Returns a string representation of the dataset.
- Returns:
String representation of the dataset.
- 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.
- copy() HierarchicalMetadataObject¶
Create a copy of the object.
- Returns:
A new instance of the same class with the same metadata and parent.
Example
>>> obj = HierarchicalMetadataObject(metadata={"key": "value"}) >>> copy_obj = obj.copy() >>> copy_obj["key"] 'value'
- 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'