TrialSampler#
- class torch_brain.samplers.TrialSampler(*, sampling_intervals, shuffle=False, generator=None)[source]#
Bases:
torch.utils.data.sampler.SamplerSamples complete trial intervals without windowing.
Unlike
RandomFixedWindowSamplerandSequentialFixedWindowSampler, which slice continuous recordings into fixed-length windows,TrialSamplertreats each individual interval insampling_intervalsas a complete trial and yields oneDatasetIndexper trial. This is suited for trial-based experimental paradigms where each trial has a well-defined start and end time that should be preserved.- Parameters:
sampling_intervals (
Dict[str,Interval]) – Sampling intervals for each session. Each individual interval within the session’stemporaldata.Intervalobject is treated as one trial. Typically obtained fromget_sampling_intervals().shuffle (
bool) – IfFalse(default), trials are yielded in the order they appear insampling_intervals. IfTrue, trials are yielded in a randomly shuffled order.generator (
Optional[Generator]) – Optional RNG used whenshuffle=True. IfNone(default), uses the default global PyTorch generator.
Example:
>>> from temporaldata import Interval >>> import numpy as np >>> from torch_brain.samplers import TrialSampler >>> sampling_intervals = { ... "session_1": Interval( ... start=np.array([0.0, 5.0, 10.0]), ... end=np.array([2.0, 8.0, 15.0]), ... ), ... } >>> sampler = TrialSampler( ... sampling_intervals=sampling_intervals, ... shuffle=True, ... ) >>> len(sampler) 3