quantlab.model.torch_data.CrossSectionDataset#

class quantlab.model.torch_data.CrossSectionDataset(panel, bars, window_bars, training)[source]#

Bases: Dataset

One item per bar: the bar’s whole cross-section with its windows.

Item i is a Batch for one bar t: every symbol present at t, each with its last window_bars bars, so x is [S_t, N, F]. Symbols without a valid training target stay in x as context and are only masked out of the loss. In training the dataset holds the given bars with at least one valid target; in evaluation it holds every given bar with at least one present symbol, so prediction covers every present cell.

Items vary in size, so batch them with batch_size=None (the TorchModel default): one bar per step.

Parameters:
panelTrainingPanel

The panel to read.

barsarray-like of int

Positions of the bars on the panel’s time axis.

window_barsint

N, bars per window; at least 1.

trainingbool

Whether the dataset feeds training steps.

Raises:
ValueError

If window_bars is below 1.

Examples

>>> dataset = CrossSectionDataset(panel, bars=[1, 2], window_bars=2, training=False)
>>> len(dataset), dataset[0].x.shape, dataset[0].where[0].tolist()
(2, torch.Size([2, 2, 1]), [1, 1])