tsgm.models.augmentations¶
Module Contents¶
- class GaussianNoise(per_feature: bool = True)[source]¶
Bases:
BaseAugmenterApply noise to the input time series. Args:
- variance ((float, float) or float): variance range for noise. If var_limit is a single float, the range
will be (0, var_limit). Default: (10.0, 50.0).
mean (float): mean of the noise. Default: 0 per_feature (bool): if set to True, noise will be sampled for each feature independently.
Otherwise, the noise will be sampled once for all features. Default: True
- generate(X: tensorflow.python.types.core.TensorLike, y: tensorflow.python.types.core.TensorLike | None = None, n_samples: int = 1, mean: float = 0, variance: float = 1.0) AugmentationOutput[source]¶
Generate synthetic data with Gaussian noise.
- Parameters:
X (TensorLike) – Input data tensor of shape (n_data, n_timesteps, n_features).
y (Optional[TensorLike]) – Optional labels tensor. If provided, labels will also be returned
n_samples (int) – Number of augmented samples to generate. Default is 1.
mean (float) – The mean of the noise. Default is 0.
variance (float) – The variance of the noise. Default is 1.0.
- Returns:
Augmented data tensor of shape (n_samples, n_timesteps, n_features) and optionally augmented labels if ‘y’ is provided.
- Return type:
Union[TensorLike, Tuple[TensorLike, TensorLike]]
- class SliceAndShuffle(per_feature: bool = False)[source]¶
Bases:
BaseAugmenterSlice the time series in k pieces and create a new time series by shuffling. Args:
- per_feature (bool): if set to True, each time series is sliced independently.
Otherwise, all features are sliced in the same way. Default: True
- generate(X: tensorflow.python.types.core.TensorLike, y: tensorflow.python.types.core.TensorLike | None = None, n_samples: int = 1, n_segments: int = 2) AugmentationOutput[source]¶
Generate synthetic data using Slice-And-Shuffle strategy. Slices are randomly selected.
- Parameters:
- Returns:
Augmented data tensor of shape (n_samples, n_timesteps, n_features) and optionally augmented labels if ‘y’ is provided.
- Return type:
Union[TensorLike, Tuple[TensorLike, TensorLike]]
- class Shuffle[source]¶
Bases:
BaseAugmenterShuffles time series features. Shuffling is beneficial when each feature corresponds to interchangeable sensors.
- generate(X: tensorflow.python.types.core.TensorLike, y: tensorflow.python.types.core.TensorLike | None = None, n_samples: int = 1) AugmentationOutput[source]¶
Generate synthetic data using Shuffle strategy. Features are randomly shuffled to generate novel samples.
- Parameters:
X (TensorLike) – Input data tensor of shape (n_data, n_timesteps, n_features).
y (Optional[TensorLike]) – Optional labels tensor. If provided, labels will also be returned
n_samples (int) – Number of augmented samples to generate. Default is 1.
- Returns:
Augmented data tensor of shape (n_samples, n_timesteps, n_features) and optionally augmented labels if ‘y’ is provided.
- Return type:
Union[TensorLike, Tuple[TensorLike, TensorLike]]
- class MagnitudeWarping[source]¶
Bases:
BaseAugmenterMagnitude warping changes the magnitude of each sample by convolving the data window with a smooth curve varying around one https://dl.acm.org/doi/pdf/10.1145/3136755.3136817
- generate(X: tensorflow.python.types.core.TensorLike, y: tensorflow.python.types.core.TensorLike | None = None, n_samples: int = 1, sigma: float = 0.2, n_knots: int = 4) AugmentationOutput[source]¶
Generates augmented samples via MagnitudeWarping for (X, y)
- Parameters:
X (TensorLike) – Input data tensor of shape (n_data, n_timesteps, n_features).
y (Optional[TensorLike]) – Optional labels tensor. If provided, labels will also be returned
n_samples (int) – Number of augmented samples to generate. Default is 1.
sigma (float) – Standard deviation for the random warping. Default is 0.2.
n_knots (int) – Number of knots used for warping curve. Default is 4.
- Returns:
Augmented data tensor of shape (n_samples, n_timesteps, n_features) and optionally augmented labels if ‘y’ is provided.
- Return type:
Union[TensorLike, Tuple[TensorLike, TensorLike]]
- class WindowWarping[source]¶
Bases:
BaseAugmenterhttps://halshs.archives-ouvertes.fr/halshs-01357973/document
- generate(X: tensorflow.python.types.core.TensorLike, y: tensorflow.python.types.core.TensorLike | None = None, window_ratio: float = 0.2, scales: Tuple = (0.25, 1.0), n_samples: int = 1) AugmentationOutput[source]¶
Generates augmented samples via MagnitudeWarping for (X, y)
- Parameters:
X (TensorLike) – Input data tensor of shape (n_data, n_timesteps, n_features).
y (Optional[TensorLike]) – Optional labels tensor. If provided, labels will also be returned
window_ratio (float) – The ratio of the window size relative to the total number of timesteps. Default is 0.2.
scale (tuple) – A tuple specifying the scale range for warping. Default is (0.25, 1.0).
n_samples (int) – Number of augmented samples to generate. Default is 1.
- Returns:
Augmented data tensor of shape (n_samples, n_timesteps, n_features) and optionally augmented labels if ‘y’ is provided.
- Return type:
Union[TensorLike, Tuple[TensorLike, TensorLike]]
- class DTWBarycentricAveraging[source]¶
Bases:
BaseAugmenter- DTW Barycenter Averaging (DBA) [1] method estimated through
Expectation-Maximization algorithm [2] as in https://github.com/tslearn-team/tslearn/
References¶
- generate(X: tensorflow.python.types.core.TensorLike, y: tensorflow.python.types.core.TensorLike | None = None, n_samples: int = 1, num_initial_samples: int | None = None, initial_timeseries: List[tensorflow.python.types.core.TensorLike] | None = None, initial_labels: List[int] | None = None, **kwargs) AugmentationOutput[source]¶
Parameters¶
X : TensorLike, the timeseries dataset y : TensorLike or None, the classes n_samples : int, number of samples to generate (per class, if y is given) num_initial_samples : int or None (default: None)
The number of timeseries to draw (per class) from the dataset before computing DTW_BA. If None, use the entire set (per class).
- initial_timeseriesarray or None (default: None)
Initial timesteries to start from for the optimization process, with shape (original_size, d). In case y is given, the shape of initial_timeseries is assumed to be (n_classes, original_size, d)
- initial_labels: array or None (default: None)
Labels for samples from
initial_timeseries
Returns¶
- np.array of shape (n_samples, original_size, d) if y is None
or (n_classes * n_samples, original_size, d), and np.array of labels (or None)