Skip to content

autora.theorist.darts.dataset

DARTSDataset

Bases: Dataset

A dataset for the DARTS algorithm.

Source code in temp_dir/darts/src/autora/theorist/darts/dataset.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class DARTSDataset(Dataset):
    """
    A dataset for the DARTS algorithm.
    """

    def __init__(self, input_data: torch.tensor, output_data: torch.tensor):
        """
        Initializes the dataset.

        Arguments:
            input_data: The input data to the dataset.
            output_data: The output data to the dataset.
        """
        assert input_data.shape[0] == output_data.shape[0]
        self.input_data = input_data
        self.output_data = output_data

    def __len__(self, experiment_id: Optional[int] = None) -> int:
        """
        Returns the length of the dataset.

        Arguments:
            experiment_id:

        Returns:
            The length of the dataset.
        """
        return self.input_data.shape[0]

    def __getitem__(self, idx: int) -> Tuple[torch.tensor, torch.tensor]:
        """
        Returns the item at the given index.

        Arguments:
            idx: The index of the item to return.

        Returns:
            The item at the given index.

        """
        input_tensor = self.input_data[idx]
        output_tensor = self.output_data[idx]
        return input_tensor, output_tensor

__getitem__(idx)

Returns the item at the given index.

Parameters:

Name Type Description Default
idx int

The index of the item to return.

required

Returns:

Type Description
Tuple[tensor, tensor]

The item at the given index.

Source code in temp_dir/darts/src/autora/theorist/darts/dataset.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def __getitem__(self, idx: int) -> Tuple[torch.tensor, torch.tensor]:
    """
    Returns the item at the given index.

    Arguments:
        idx: The index of the item to return.

    Returns:
        The item at the given index.

    """
    input_tensor = self.input_data[idx]
    output_tensor = self.output_data[idx]
    return input_tensor, output_tensor

__init__(input_data, output_data)

Initializes the dataset.

Parameters:

Name Type Description Default
input_data tensor

The input data to the dataset.

required
output_data tensor

The output data to the dataset.

required
Source code in temp_dir/darts/src/autora/theorist/darts/dataset.py
13
14
15
16
17
18
19
20
21
22
23
def __init__(self, input_data: torch.tensor, output_data: torch.tensor):
    """
    Initializes the dataset.

    Arguments:
        input_data: The input data to the dataset.
        output_data: The output data to the dataset.
    """
    assert input_data.shape[0] == output_data.shape[0]
    self.input_data = input_data
    self.output_data = output_data

__len__(experiment_id=None)

Returns the length of the dataset.

Parameters:

Name Type Description Default
experiment_id Optional[int]
None

Returns:

Type Description
int

The length of the dataset.

Source code in temp_dir/darts/src/autora/theorist/darts/dataset.py
25
26
27
28
29
30
31
32
33
34
35
def __len__(self, experiment_id: Optional[int] = None) -> int:
    """
    Returns the length of the dataset.

    Arguments:
        experiment_id:

    Returns:
        The length of the dataset.
    """
    return self.input_data.shape[0]

darts_dataset_from_ndarray(input_data, output_data)

A function to create a dataset from numpy arrays.

Parameters:

Name Type Description Default
input_data ndarray

The input data to the dataset.

required
output_data ndarray

The output data to the dataset.

required

Returns:

Type Description
DARTSDataset

The dataset.

Source code in temp_dir/darts/src/autora/theorist/darts/dataset.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def darts_dataset_from_ndarray(
    input_data: np.ndarray, output_data: np.ndarray
) -> DARTSDataset:
    """
    A function to create a dataset from numpy arrays.

    Arguments:
        input_data: The input data to the dataset.
        output_data: The output data to the dataset.

    Returns:
        The dataset.

    """

    obj = DARTSDataset(
        torch.tensor(input_data, dtype=torch.get_default_dtype()),
        torch.tensor(output_data, dtype=torch.get_default_dtype()),
    )
    return obj