Beispiel #1
0
def _convert_to_numpy(*args):
    r"""Convert a list of array to numpy if they are torch tensors"""
    for arr in args:
        if isinstance(arr, torch.Tensor):
            yield torch_to_numpy(arr)
        else:
            yield arr
Beispiel #2
0
    def __init__(self, base_callback, dataset, representations):
        """
        Constructor of the class.

        :param base_callback: The base callback.
        :param dataset: The dataset being used.
        :param representations: The representations to use.
        """
        representations = [
            representation.lower() for representation in representations
        ]
        assert all([
            representation in projections_list
            for representation in representations
        ])

        super().__init__()
        self.base_callback = base_callback
        self.dataset = dataset
        self.data = dataset.data
        self.targets = torch_to_numpy(dataset.targets)
        self.record = self.base_callback.record
        self.experiment = self.base_callback.experiment

        self.projections = {
            representation:
            projections_list[representation](n_components=self.data.shape[1])
            for representation in representations
        }
        self.representations = {
            representation: dict()
            for representation in representations
        }

        for representation, content in self.representations.items():
            X_plot = self._get_x_plot(torch_to_numpy(self.data),
                                      representation)
            grid_xy = self._get_mesh_grid(X_plot)
            content['X_plot'] = X_plot
            content['grid_xy'] = grid_xy
            content['grid'] = self._get_grid(grid_xy, representation)

        self.experiment['data'] = torch_to_numpy(dataset.data)
        self.experiment['targets'] = torch_to_numpy(dataset.targets)
        self.experiment['representations'] = self.representations
Beispiel #3
0
    def __init__(self, base_callback, dataset, batch_size):
        """
        Constructor of the class.

        :param base_callback: The base callback.
        :param dataset: The dataset being used.
        :param batch_size: The size of a batch.
        """
        super().__init__()
        self.base_callback = base_callback
        self.dataset = dataset
        self.data = dataset.data
        self.targets = torch_to_numpy(dataset.targets)
        self.record = self.base_callback.record
        self.experiment = self.base_callback.experiment

        self.experiment['data'] = torch_to_numpy(dataset.data)
        self.experiment['targets'] = torch_to_numpy(dataset.targets)
        self.experiment['feature_names'] = dataset.feature_names
        self.experiment['target_names'] = dataset.feature_names
        self.experiment['dataset_name'] = dataset.name
        self.experiment['batch_size'] = batch_size
Beispiel #4
0
 def forward(self, y_pred, y_true):
     self.preds.append(torch_to_numpy(y_pred))
     self.targets.append(torch_to_numpy(y_true))