Skip to content

pytorch

TorchDataset(inputs, outputs=None)

Bases: Dataset[tuple[Tensor, Tensor]]

Dataset for PyTorch.

Initialize the TorchDataset.

Parameters:

Name Type Description Default
inputs DataFrame

The input data.

required
outputs DataFrame | None

The output data. Defaults to None.

None
Source code in src/flowcean/environments/pytorch.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
def __init__(
    self,
    inputs: pl.DataFrame,
    outputs: pl.DataFrame | None = None,
) -> None:
    """Initialize the TorchDataset.

    Args:
        inputs: The input data.
        outputs: The output data. Defaults to None.
    """
    super().__init__()
    self.inputs = inputs
    self.outputs = outputs

__len__()

Return the length of the dataset.

Source code in src/flowcean/environments/pytorch.py
24
25
26
def __len__(self) -> int:
    """Return the length of the dataset."""
    return len(self.inputs)

__getitem__(item)

Return the item at the given index.

Parameters:

Name Type Description Default
item int

The index of the item to return.

required

Returns:

Type Description
tuple[Tensor, Tensor]

The inputs and outputs at the given index.

Source code in src/flowcean/environments/pytorch.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def __getitem__(self, item: int) -> tuple[Tensor, Tensor]:
    """Return the item at the given index.

    Args:
        item: The index of the item to return.

    Returns:
        The inputs and outputs at the given index.
    """
    inputs = Tensor(self.inputs.row(item))
    if self.outputs is None:
        outputs = Tensor([])
    else:
        outputs = Tensor(self.outputs.row(item))
    return inputs, outputs