Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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.):
self._targets += noise_std * np.random.randn(num_samples, 1)
def __getitem__(self, index):
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
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