SequentialFixedWindowSampler#
- class torch_brain.samplers.SequentialFixedWindowSampler(*, sampling_intervals, window_length, step=None, drop_short=False)[source]#
Bases:
torch.utils.data.sampler.SamplerSamples fixed-length windows sequentially in a deterministic, reproducible order.
Given the
sampling_intervalsdictionary mapping session IDs totemporaldata.Intervalobjects, this sampler producesDatasetIndexobjects in a fixed order. Windows are stepped through each interval using a configurablestepsize, making this sampler well-suited for evaluation where full coverage and reproducibility are required.If an interval’s length is not an exact multiple of
step, a final overlapping window is appended to ensure the entire interval is covered.- Parameters:
sampling_intervals (
Dict[str,Interval]) – Sampling intervals for each session. Typically obtained fromget_sampling_intervals().window_length (
float) – Duration of each sampled window in seconds.step (
Optional[float]) – Step size between the start of consecutive windows in seconds. IfNone(default), setssteptowindow_length(non-overlapping windows).drop_short (
bool) – IfFalse(default), aValueErroris raised for any short interval. IfTrue, intervals shorter thanwindow_lengthare silently skipped with a warning logged.
Example:
>>> import numpy as np >>> from temporaldata import Interval >>> from torch_brain.samplers import SequentialFixedWindowSampler >>> sampling_intervals = { ... "session_1": Interval(0.0, 100.0), ... "session_2": Interval(0.0, 100.0), ... } >>> sampler = SequentialFixedWindowSampler( ... sampling_intervals=sampling_intervals, ... window_length=10.0, ... step=5.0, ... ) >>> len(sampler) 38