How to use the torchmeta.utils.data.Task function in torchmeta

To help you get started, we’ve selected a few torchmeta examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tristandeleu / pytorch-meta / torchmeta / datasets / tcga.py View on Github external
os.remove(rawpath)

    def close(self):
        if self.preloaded:
            self.gene_expression_file.close()
            self.gene_expression_data = None
            self.gene_expression_file = None
            self.preloaded = False

    def open(self):
        if self.preloaded:
            self._preload_gene_expression_data()
            self.preloaded = True


class TCGATask(Task):
    @classmethod
    def from_id(cls, root, task_id, transform=None, target_transform=None):
        import pandas as pd
        root = os.path.join(os.path.expanduser(root), TCGA.folder)
        gene_filepath = os.path.join(root, TCGA.gene_expression_filename)
        if not os.path.isfile(gene_filepath):
            raise IOError()

        label, cancer = task_id

        processed_folder = os.path.join(root, 'clinicalMatrices', 'processed')
        filename = '{0}.tsv'.format(TCGA.clinical_matrix_filename.format(cancer))
        filepath = os.path.join(processed_folder, filename)
        if not os.path.isfile(filepath):
            raise IOError()
github tristandeleu / pytorch-meta / torchmeta / toy / sinusoid_line.py View on Github external
if self._is_sinusoid[index]:
            amplitude, phase = self._amplitudes[index], self._phases[index]
            task = SinusoidTask(amplitude, phase, self._input_range, self.noise_std,
                self.num_samples_per_task, self.transform, self.target_transform)
        else:
            slope, intercept = self._slopes[index], self._intercepts[index]
            task = LinearTask(slope, intercept, self._input_range, self.noise_std,
                self.num_samples_per_task, self.transform, self.target_transform)

        if self.dataset_transform is not None:
            task = self.dataset_transform(task)

        return task


class LinearTask(Task):
    def __init__(self, slope, intercept, input_range, noise_std, num_samples,
        transform=None, target_transform=None):
        super(LinearTask, self).__init__(None) # Regression task
        self.slope = slope
        self.intercept = intercept
        self.input_range = input_range
        self.num_samples = num_samples
        self.noise_std = noise_std

        self.transform = transform
        self.target_transform = target_transform

        self._inputs = np.random.uniform(input_range[0], input_range[1],
            size=(num_samples, 1))
        self._targets = intercept + slope * self._inputs
        if (noise_std is not None) and (noise_std > 0.):
github tristandeleu / pytorch-meta / torchmeta / toy / sinusoid.py View on Github external
def __len__(self):
        return self.num_tasks

    def __getitem__(self, index):
        amplitude, phase = self._amplitudes[index], self._phases[index]
        task = SinusoidTask(amplitude, phase, self._input_range, self.noise_std,
            self.num_samples_per_task, self.transform, self.target_transform)

        if self.dataset_transform is not None:
            task = self.dataset_transform(task)

        return task


class SinusoidTask(Task):
    def __init__(self, amplitude, phase, input_range, noise_std, num_samples,
                 transform=None, target_transform=None):
        super(SinusoidTask, self).__init__(None) # Regression task
        self.amplitude = amplitude
        self.phase = phase
        self.input_range = input_range
        self.num_samples = num_samples
        self.noise_std = noise_std

        self.transform = transform
        self.target_transform = target_transform

        self._inputs = np.random.uniform(input_range[0], input_range[1],
            size=(num_samples, 1))
        self._targets = amplitude * np.sin(self._inputs - phase)
        if (noise_std is not None) and (noise_std > 0.):
github tristandeleu / pytorch-meta / torchmeta / toy / harmonic.py View on Github external
domain = self._domains[index]
        frequency = self._frequencies[index]
        phases = self._phases[index]
        amplitudes = self._amplitudes[index]

        task = HarmonicTask(domain, frequency, phases, amplitudes,
            self.noise_std, self.num_samples_per_task, self.transform,
            self.target_transform)

        if self.dataset_transform is not None:
            task = self.dataset_transform(task)

        return task


class HarmonicTask(Task):
    def __init__(self, domain, frequency, phases, amplitudes, noise_std,
                 num_samples, transform=None, target_transform=None):
        super(HarmonicTask, self).__init__(None) # Regression task
        self.domain = domain
        self.frequency = frequency
        self.phases = phases
        self.amplitudes = amplitudes
        self.noise_std = noise_std
        self.num_samples = num_samples

        self.transform = transform
        self.target_transform = target_transform

        a_1, a_2 = self.amplitudes
        b_1, b_2 = self.phases