SequentialFixedWindowSampler#

class torch_brain.samplers.SequentialFixedWindowSampler(*, sampling_intervals, window_length, step=None, drop_short=False)[source]#

Bases: torch.utils.data.sampler.Sampler

Samples fixed-length windows sequentially in a deterministic, reproducible order.

Given the sampling_intervals dictionary mapping session IDs to temporaldata.Interval objects, this sampler produces DatasetIndex objects in a fixed order. Windows are stepped through each interval using a configurable step size, 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 from get_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. If None (default), sets step to window_length (non-overlapping windows).

  • drop_short (bool) – If False (default), a ValueError is raised for any short interval. If True, intervals shorter than window_length are 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