Augmentation Classes

Affine(a, numpy.ndarray] = 1.0, b, …) Augmentor that performs affine transformation to time series.
RandomAffine(max_a, min_a, max_b, min_b, …) Augmentor that performs affine transformation to time series with random coefficients.
Crop(crop_start, numpy.ndarray] = 0, crop_size) Augmentor that crops time series.
RandomCrop(crop_size, crops_per_series, …) Augmentor that crops time series randomly.
CrossSum(inds) Augmentor that sum cross given time series.
RandomCrossSum(max_sum_series, random_seed) Augmentor that sums cross given time series randomly.
RandomJitter(dist, strength, random_seed) Augmentor that adds random noise to time series.
Resample(n_new) Augmentor that resamples from time series with new length.
Reverse() Augmentor that reverses time series.
RandomSidetrack(mode, initial_sidetrack, …) Augmentor that sidetracks time series from its original values.
RandomTimeWarp(n_speed_change, random_seed) Augmentor that warps time line of time series randomly.
Trend(anchors) Augmentor that adds trend to time series.
RandomTrend(num_anchors, min_anchor, …) Augmentor to add random trend to time series.
Magnify(start, numpy.ndarray] = 0, end, …) Augmentor that magnifies time intervels of time series.
RandomMagnify(max_zoom, min_zoom, random_seed) Augmentor that magnifies random time intervels of time series.
class tsaug.Affine(a: Union[float, numpy.ndarray] = 1.0, b: Union[float, numpy.ndarray] = 0.0)[source]

Augmentor that performs affine transformation to time series.

A series x will be transformed to a*x+b, while binary label y will not be changed.

Parameters:
  • a (float, or numpy.ndarray, optional) – Slope coefficients of the affine transformation. An array with shape (N,) or (N, c), where N is the number of series and c is the number of channels, or a scalar. Default: 1.0.
  • b (float, or numpy.ndarray, optional) – Intercept coefficients of the affine transformation. An array with shape (N,) or (N, c), where N is the number of series and c is the number of channels, or a scalar. Default: 0.0.
copy() → Any

Create a copy of this augmentor.

run(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None) → Tuple[numpy.ndarray, numpy.ndarray]

Perform augmentation to time series.

Parameters:
  • X (numpy.ndarray) – Time series to be augmented. Matrix with shape (n,), (N, n) or (N, n, c), where n is the length of each series, N is the number of series, and c is the number of channels.
  • Y (numpy.ndarray, optional) – Binary labels of time series, where 0 represents a normal point and 1 represents an anomalous points. Matrix with shape (n,), (N, n) or (N, n, cl), where n is the length of each series, N is the number of series, and cl is the number of classes (i.e. types of anomaly). Default: None.
Returns:

Augmented time series and augmented labels (if argument Y exists).

Return type:

tuple (numpy.ndarray, numpy.ndarray)

summary() → None

Print summary of this augmentor.

class tsaug.RandomAffine(max_a: float = 10.0, min_a: float = -10.0, max_b: float = 100.0, min_b: float = -100.0, random_seed: Optional[int] = None)[source]

Augmentor that performs affine transformation to time series with random coefficients.

A series x will be transformed to a*x+b, while binary label y will not be changed. Coefficients a and b are randomly generated.

Parameters:
  • max_a (float, optional) – Maximal value of slope cofficients of the affine transformation. Default: 10.0.
  • min_a (float, optional) – Minimal value of slope cofficients of the affine transformation. Default: -10.0.
  • max_b (float, optional) – Maximal value of intercept cofficients of the affine transformation. Default: 100.0.
  • min_b (float, optional) – Minimal value of intercept cofficients of the affine transformation. Default: -100.0.
  • random_seed (int, optional) – Random seed used to initialize the pseudo-random number generator. Default: None.
copy() → Any

Create a copy of this augmentor.

run(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None) → Tuple[numpy.ndarray, numpy.ndarray]

Perform augmentation to time series.

Parameters:
  • X (numpy.ndarray) – Time series to be augmented. Matrix with shape (n,), (N, n) or (N, n, c), where n is the length of each series, N is the number of series, and c is the number of channels.
  • Y (numpy.ndarray, optional) – Binary labels of time series, where 0 represents a normal point and 1 represents an anomalous points. Matrix with shape (n,), (N, n) or (N, n, cl), where n is the length of each series, N is the number of series, and cl is the number of classes (i.e. types of anomaly). Default: None.
Returns:

Augmented time series and augmented labels (if argument Y exists).

Return type:

tuple (numpy.ndarray, numpy.ndarray)

summary() → None

Print summary of this augmentor.

class tsaug.Crop(crop_start: Union[int, numpy.ndarray] = 0, crop_size: Optional[int] = None)[source]

Augmentor that crops time series.

Time series will be cropped based on given location and size of cropping window.

Parameters:
  • crop_start (int, or numpy.ndarray, optional) – Indices of the start of cropping windows at each time series. If an array of shape (N, m) where N is the number of series, m croppings will be performed at each series. Default: 0.
  • crop_size (int, optional) – Size of cropping windows. If not given, n will be used. Default: None.
copy() → Any

Create a copy of this augmentor.

run(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None) → Tuple[numpy.ndarray, numpy.ndarray]

Perform augmentation to time series.

Parameters:
  • X (numpy.ndarray) – Time series to be augmented. Matrix with shape (n,), (N, n) or (N, n, c), where n is the length of each series, N is the number of series, and c is the number of channels.
  • Y (numpy.ndarray, optional) – Binary labels of time series, where 0 represents a normal point and 1 represents an anomalous points. Matrix with shape (n,), (N, n) or (N, n, cl), where n is the length of each series, N is the number of series, and cl is the number of classes (i.e. types of anomaly). Default: None.
Returns:

Augmented time series and augmented labels (if argument Y exists).

Return type:

tuple (numpy.ndarray, numpy.ndarray)

summary() → None

Print summary of this augmentor.

class tsaug.RandomCrop(crop_size: Optional[int] = None, crops_per_series: int = 1, random_seed: Optional[int] = None)[source]

Augmentor that crops time series randomly.

Parameters:
  • crop_size (int, optional) – Size of cropping windows. If not given, n will be used. Default: None.
  • crops_per_series (int, optional) – Number of croppings to be performed at each series. Default: 1.
  • random_seed (int, optional) – Random seed used to initialize the pseudo-random number generator. Default: None.
copy() → Any

Create a copy of this augmentor.

run(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None) → Tuple[numpy.ndarray, numpy.ndarray]

Perform augmentation to time series.

Parameters:
  • X (numpy.ndarray) – Time series to be augmented. Matrix with shape (n,), (N, n) or (N, n, c), where n is the length of each series, N is the number of series, and c is the number of channels.
  • Y (numpy.ndarray, optional) – Binary labels of time series, where 0 represents a normal point and 1 represents an anomalous points. Matrix with shape (n,), (N, n) or (N, n, cl), where n is the length of each series, N is the number of series, and cl is the number of classes (i.e. types of anomaly). Default: None.
Returns:

Augmented time series and augmented labels (if argument Y exists).

Return type:

tuple (numpy.ndarray, numpy.ndarray)

summary() → None

Print summary of this augmentor.

class tsaug.CrossSum(inds: numpy.ndarray = None)[source]

Augmentor that sum cross given time series.

Time series will be summed with others based on the given indices. Time points at which at least one time series of summation is anomalous will be marked as anomalous.

Parameters:inds (numpy.array, optional) – Indices of time series to sum with. Matrix with shape (N, m), where N is the number of series, and m is the maximal number of series to sum with each series. The i-th output series is the sum of the i-th input series and the ind[i][j]-th time series for all j. Values of ind[i][j] can be NaN for series to be summed with less than m series.
copy() → Any

Create a copy of this augmentor.

run(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None) → Tuple[numpy.ndarray, numpy.ndarray]

Perform augmentation to time series.

Parameters:
  • X (numpy.ndarray) – Time series to be augmented. Matrix with shape (n,), (N, n) or (N, n, c), where n is the length of each series, N is the number of series, and c is the number of channels.
  • Y (numpy.ndarray, optional) – Binary labels of time series, where 0 represents a normal point and 1 represents an anomalous points. Matrix with shape (n,), (N, n) or (N, n, cl), where n is the length of each series, N is the number of series, and cl is the number of classes (i.e. types of anomaly). Default: None.
Returns:

Augmented time series and augmented labels (if argument Y exists).

Return type:

tuple (numpy.ndarray, numpy.ndarray)

summary() → None

Print summary of this augmentor.

class tsaug.RandomCrossSum(max_sum_series: Optional[int] = 5, random_seed: Optional[int] = None)[source]

Augmentor that sums cross given time series randomly.

Time series will be summed with others randomly. Time points at which at least one time series of summation is anomalous will be marked as anomalous.

Parameters:
  • max_sum_series (int, optional) – Maximal number of time series to cross sum. Default: 5.
  • random_seed (int, optional) – Random seed used to initialize the pseudo-random number generator. Default: None.
copy() → Any

Create a copy of this augmentor.

run(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None) → Tuple[numpy.ndarray, numpy.ndarray]

Perform augmentation to time series.

Parameters:
  • X (numpy.ndarray) – Time series to be augmented. Matrix with shape (n,), (N, n) or (N, n, c), where n is the length of each series, N is the number of series, and c is the number of channels.
  • Y (numpy.ndarray, optional) – Binary labels of time series, where 0 represents a normal point and 1 represents an anomalous points. Matrix with shape (n,), (N, n) or (N, n, cl), where n is the length of each series, N is the number of series, and cl is the number of classes (i.e. types of anomaly). Default: None.
Returns:

Augmented time series and augmented labels (if argument Y exists).

Return type:

tuple (numpy.ndarray, numpy.ndarray)

summary() → None

Print summary of this augmentor.

class tsaug.RandomJitter(dist: Optional[str] = 'normal', strength: Optional[float] = 0.05, random_seed: Optional[int] = None)[source]

Augmentor that adds random noise to time series.

Parameters:
  • dist (str, optional) – Distribution the random noise follows. Either ‘normal’ or ‘uniform’. Default: ‘normal’.
  • strength (float, optional) – Strength of noise. Default: 0.05.
  • random_seed (int, optional) – Random seed used to initialize the pseudo-random number generator. Default: None.
copy() → Any

Create a copy of this augmentor.

run(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None) → Tuple[numpy.ndarray, numpy.ndarray]

Perform augmentation to time series.

Parameters:
  • X (numpy.ndarray) – Time series to be augmented. Matrix with shape (n,), (N, n) or (N, n, c), where n is the length of each series, N is the number of series, and c is the number of channels.
  • Y (numpy.ndarray, optional) – Binary labels of time series, where 0 represents a normal point and 1 represents an anomalous points. Matrix with shape (n,), (N, n) or (N, n, cl), where n is the length of each series, N is the number of series, and cl is the number of classes (i.e. types of anomaly). Default: None.
Returns:

Augmented time series and augmented labels (if argument Y exists).

Return type:

tuple (numpy.ndarray, numpy.ndarray)

summary() → None

Print summary of this augmentor.

class tsaug.Resample(n_new: Optional[int] = None)[source]

Augmentor that resamples from time series with new length.

Time series will be transformed into new length. Values of time series is determined by linear interpolation.

Parameters:n_new (int, optional) – New length of time series. Default: n.
copy() → Any

Create a copy of this augmentor.

run(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None) → Tuple[numpy.ndarray, numpy.ndarray]

Perform augmentation to time series.

Parameters:
  • X (numpy.ndarray) – Time series to be augmented. Matrix with shape (n,), (N, n) or (N, n, c), where n is the length of each series, N is the number of series, and c is the number of channels.
  • Y (numpy.ndarray, optional) – Binary labels of time series, where 0 represents a normal point and 1 represents an anomalous points. Matrix with shape (n,), (N, n) or (N, n, cl), where n is the length of each series, N is the number of series, and cl is the number of classes (i.e. types of anomaly). Default: None.
Returns:

Augmented time series and augmented labels (if argument Y exists).

Return type:

tuple (numpy.ndarray, numpy.ndarray)

summary() → None

Print summary of this augmentor.

class tsaug.Reverse[source]

Augmentor that reverses time series.

copy() → Any

Create a copy of this augmentor.

run(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None) → Tuple[numpy.ndarray, numpy.ndarray]

Perform augmentation to time series.

Parameters:
  • X (numpy.ndarray) – Time series to be augmented. Matrix with shape (n,), (N, n) or (N, n, c), where n is the length of each series, N is the number of series, and c is the number of channels.
  • Y (numpy.ndarray, optional) – Binary labels of time series, where 0 represents a normal point and 1 represents an anomalous points. Matrix with shape (n,), (N, n) or (N, n, cl), where n is the length of each series, N is the number of series, and cl is the number of classes (i.e. types of anomaly). Default: None.
Returns:

Augmented time series and augmented labels (if argument Y exists).

Return type:

tuple (numpy.ndarray, numpy.ndarray)

summary() → None

Print summary of this augmentor.

class tsaug.RandomSidetrack(mode: Optional[str] = 'multiplicative', initial_sidetrack: Optional[float] = None, max_sidetrack: Optional[float] = None, min_sidetrack: Optional[float] = None, step_mu: Optional[float] = 0, step_sigma: Optional[float] = 0.1, random_seed: Optional[int] = None)[source]

Augmentor that sidetracks time series from its original values.

This augmentor has two modes: multiplicative mode sidetracks a time series by multiplying its values with random-walking multipliers, and additive mode sidetracks a time series by adding its values with random-walking additives.

Parameters:
  • mode (str, optional) – Either “multiplicative” or “additive”. Default: “multiplicative”.
  • initial_sidetrack (float, optional) – Sidetrack at the start of time series. If not given, 1.0 for multiplicative mode and 0.0 for additive mode. Default: None.
  • max_sidetrack (float, optional) – Maximal sidetrack. The random walk will reflect downwards if it hits this limit. Default: None.
  • min_sidetrack (float, optional) – Minimal sidetrack. The random walk will reflect upwards if it hits this limit. Default: None.
  • step_mu (float, optional) – Mean of step size in random walk. Default: 0.
  • step_sigma (float, optional) – Standard deviation of step size in random walk. Default: 0.1.
  • random_seed (int, optional) – Random seed used to initialize the pseudo-random number generator. Default: None.
copy() → Any

Create a copy of this augmentor.

run(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None) → Tuple[numpy.ndarray, numpy.ndarray]

Perform augmentation to time series.

Parameters:
  • X (numpy.ndarray) – Time series to be augmented. Matrix with shape (n,), (N, n) or (N, n, c), where n is the length of each series, N is the number of series, and c is the number of channels.
  • Y (numpy.ndarray, optional) – Binary labels of time series, where 0 represents a normal point and 1 represents an anomalous points. Matrix with shape (n,), (N, n) or (N, n, cl), where n is the length of each series, N is the number of series, and cl is the number of classes (i.e. types of anomaly). Default: None.
Returns:

Augmented time series and augmented labels (if argument Y exists).

Return type:

tuple (numpy.ndarray, numpy.ndarray)

summary() → None

Print summary of this augmentor.

class tsaug.RandomTimeWarp(n_speed_change: int = 3, random_seed: Optional[int] = None)[source]

Augmentor that warps time line of time series randomly.

The speed at which the time line advances is a random smooth curve with a few speed changes.

Parameters:
  • n_speed_change (int, optional) – Number of speed changes. Default: 3.
  • random_seed (int, optional) – Random seed used to initialize the pseudo-random number generator. Default: None.
copy() → Any

Create a copy of this augmentor.

run(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None) → Tuple[numpy.ndarray, numpy.ndarray]

Perform augmentation to time series.

Parameters:
  • X (numpy.ndarray) – Time series to be augmented. Matrix with shape (n,), (N, n) or (N, n, c), where n is the length of each series, N is the number of series, and c is the number of channels.
  • Y (numpy.ndarray, optional) – Binary labels of time series, where 0 represents a normal point and 1 represents an anomalous points. Matrix with shape (n,), (N, n) or (N, n, cl), where n is the length of each series, N is the number of series, and cl is the number of classes (i.e. types of anomaly). Default: None.
Returns:

Augmented time series and augmented labels (if argument Y exists).

Return type:

tuple (numpy.ndarray, numpy.ndarray)

summary() → None

Print summary of this augmentor.

class tsaug.Trend(anchors: Optional[numpy.ndarray] = None)[source]

Augmentor that adds trend to time series.

Given m anchors, the trend of a series is generated by cublic spline interpolation over all anchors that are uniformly distributed.

Parameters:anchors (numpy.ndarray) – Anchor points from which trend is interpolated. An array with shape (m,), (N, m), or (N, m, c), where m is the number of anchor points of each series, N is the number of series, and c is the number of channels. Default: None, i.e. no trend added.
copy() → Any

Create a copy of this augmentor.

run(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None) → Tuple[numpy.ndarray, numpy.ndarray]

Perform augmentation to time series.

Parameters:
  • X (numpy.ndarray) – Time series to be augmented. Matrix with shape (n,), (N, n) or (N, n, c), where n is the length of each series, N is the number of series, and c is the number of channels.
  • Y (numpy.ndarray, optional) – Binary labels of time series, where 0 represents a normal point and 1 represents an anomalous points. Matrix with shape (n,), (N, n) or (N, n, cl), where n is the length of each series, N is the number of series, and cl is the number of classes (i.e. types of anomaly). Default: None.
Returns:

Augmented time series and augmented labels (if argument Y exists).

Return type:

tuple (numpy.ndarray, numpy.ndarray)

summary() → None

Print summary of this augmentor.

class tsaug.RandomTrend(num_anchors: int = 5, min_anchor: float = 0.0, max_anchor: float = 100.0, random_seed: Optional[int] = None)[source]

Augmentor to add random trend to time series.

Given m anchors, the trend of a series is generated by cublic spline interpolation over all anchors that are uniformly distributed. Anchors are randomly sampled between given bounds.

Parameters:
  • num_anchors (int, optional) – Number of anchors to sample for each series. Default: 5.
  • min_anchor (float, optional) – Minimal value of anchors. Default: 0.0.
  • max_anchor (float, optional) – Maximal value of anchors. Default: 100.0.
  • random_seed (int, optional) – Random seed used to initialize the pseudo-random number generator. Default: None.
copy() → Any

Create a copy of this augmentor.

run(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None) → Tuple[numpy.ndarray, numpy.ndarray]

Perform augmentation to time series.

Parameters:
  • X (numpy.ndarray) – Time series to be augmented. Matrix with shape (n,), (N, n) or (N, n, c), where n is the length of each series, N is the number of series, and c is the number of channels.
  • Y (numpy.ndarray, optional) – Binary labels of time series, where 0 represents a normal point and 1 represents an anomalous points. Matrix with shape (n,), (N, n) or (N, n, cl), where n is the length of each series, N is the number of series, and cl is the number of classes (i.e. types of anomaly). Default: None.
Returns:

Augmented time series and augmented labels (if argument Y exists).

Return type:

tuple (numpy.ndarray, numpy.ndarray)

summary() → None

Print summary of this augmentor.

class tsaug.Magnify(start: Union[int, numpy.ndarray] = 0, end: Union[int, numpy.ndarray, None] = None, size: Optional[int] = None)[source]

Augmentor that magnifies time intervels of time series.

This transformation does not change the number of time points in a series.

Parameters:
  • start (int or numpy.ndarray, optional) – Indices of the starting positions of time windows to be magnified. If an integer, all series use the same value. Default: 0.
  • end (int or numpy.ndarray, optional) – Indices of the ending positions of time windows to be magnified. If an integer, all series use the same value. Only used when argument size is not given. Default: n.
  • size (int, optional) – Length of time windows to be magnified. If given, argument end will be ignored. Default: None
copy() → Any

Create a copy of this augmentor.

run(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None) → Tuple[numpy.ndarray, numpy.ndarray]

Perform augmentation to time series.

Parameters:
  • X (numpy.ndarray) – Time series to be augmented. Matrix with shape (n,), (N, n) or (N, n, c), where n is the length of each series, N is the number of series, and c is the number of channels.
  • Y (numpy.ndarray, optional) – Binary labels of time series, where 0 represents a normal point and 1 represents an anomalous points. Matrix with shape (n,), (N, n) or (N, n, cl), where n is the length of each series, N is the number of series, and cl is the number of classes (i.e. types of anomaly). Default: None.
Returns:

Augmented time series and augmented labels (if argument Y exists).

Return type:

tuple (numpy.ndarray, numpy.ndarray)

summary() → None

Print summary of this augmentor.

class tsaug.RandomMagnify(max_zoom: float = 2.0, min_zoom: float = 1.0, random_seed: Optional[int] = None)[source]

Augmentor that magnifies random time intervels of time series.

This transformation does not change the number of time points in a series.

Parameters:
  • max_zoom (float, optional) – Maximal zooming factor. Default: 2.0.
  • min_zoom (float, optional) – Minimal zooming factor. Default: 1.0.
  • random_seed (int, optional) – Random seed used to initialize the pseudo-random number generator. Default: None.
copy() → Any

Create a copy of this augmentor.

run(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None) → Tuple[numpy.ndarray, numpy.ndarray]

Perform augmentation to time series.

Parameters:
  • X (numpy.ndarray) – Time series to be augmented. Matrix with shape (n,), (N, n) or (N, n, c), where n is the length of each series, N is the number of series, and c is the number of channels.
  • Y (numpy.ndarray, optional) – Binary labels of time series, where 0 represents a normal point and 1 represents an anomalous points. Matrix with shape (n,), (N, n) or (N, n, cl), where n is the length of each series, N is the number of series, and cl is the number of classes (i.e. types of anomaly). Default: None.
Returns:

Augmented time series and augmented labels (if argument Y exists).

Return type:

tuple (numpy.ndarray, numpy.ndarray)

summary() → None

Print summary of this augmentor.