Augmentation Functions¶
affine (X, Y, a, numpy.ndarray] = 1.0, b, …) 
Perform affine transformation to time series. 
random_affine (X, Y, max_a, min_a, max_b, …) 
Perform affine transformation to time series with random coefficients. 
crop (X, Y, crop_start, numpy.ndarray] = 0, …) 
Crop time series. 
random_crop (X, Y, crop_size, …) 
Crop time series randomly. 
cross_sum (X, Y, inds) 
Sum cross given time series. 
random_cross_sum (X, Y, max_sum_series, …) 
Sum cross given time series randomly. 
random_jitter (X, Y, dist, strength, random_seed) 
Add random noise to time series. 
resample (X, Y, n_new) 
Resample from time series with new length. 
reverse (X, Y) 
Reverse time series. 
random_sidetrack (X, Y, mode, …) 
Sidetrack time series from its original values. 
random_time_warp (X, Y, n_speed_change, …) 
Warp time line of time series randomly. 
trend (X, Y, anchors) 
Add trend to time series. 
random_trend (X, Y, num_anchors, min_anchor, …) 
Add random trend to time series. 
magnify (X, Y, start, numpy.ndarray] = 0, …) 
Magnify time intervels of time series. 
random_magnify (X, Y, max_zoom, min_zoom, …) 
Magnify random time intervels of time series. 

tsaug.
affine
(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, a: Union[float, numpy.ndarray] = 1.0, b: Union[float, numpy.ndarray] = 0.0) → Tuple[numpy.ndarray, Optional[numpy.ndarray]][source]¶ Perform affine transformation to time series.
A series x will be transformed to a*x+b, while binary label y will not be changed.
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.
 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.
Returns: Augmented time series and augmented labels (if argument Y exists).
Return type: tuple (numpy.ndarray, numpy.ndarray)

tsaug.
random_affine
(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, 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) → Tuple[numpy.ndarray, Optional[numpy.ndarray]][source]¶ Perform 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:  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.
 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 pseudorandom number generator. Default: None.
Returns: Augmented time series and augmented labels (if argument Y exists).
Return type: tuple (numpy.ndarray, numpy.ndarray)

tsaug.
crop
(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, crop_start: Union[int, numpy.ndarray] = 0, crop_size: Optional[int] = None) → Tuple[numpy.ndarray, Optional[numpy.ndarray]][source]¶ Crop time series.
Time series will be cropped based on given location and size of cropping window.
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.
 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.
Returns: Augmented time series and augmented labels (if argument Y exists).
Return type: tuple (numpy.ndarray, numpy.ndarray)

tsaug.
random_crop
(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, crop_size: Optional[int] = None, crops_per_series: int = 1, random_seed: Optional[int] = None) → Tuple[numpy.ndarray, Optional[numpy.ndarray]][source]¶ Crop time series randomly.
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.
 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 pseudorandom number generator. Default: None.
Returns: Augmented time series and augmented labels (if argument Y exists).
Return type: tuple (numpy.ndarray, numpy.ndarray)

tsaug.
cross_sum
(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, inds: Optional[numpy.ndarray] = None) → Tuple[numpy.ndarray, Optional[numpy.ndarray]][source]¶ 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:  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.
 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 ith output series is the sum of the ith 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.
Returns: Augmented time series and augmented labels (if argument Y exists).
Return type: tuple (numpy.ndarray, numpy.ndarray)

tsaug.
random_cross_sum
(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, max_sum_series: Optional[int] = 5, random_seed: Optional[int] = None) → Tuple[numpy.ndarray, Optional[numpy.ndarray]][source]¶ Sum 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:  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.
 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 pseudorandom number generator. Default: None.
Returns: Augmented time series and augmented labels (if argument Y exists).
Return type: tuple (numpy.ndarray, numpy.ndarray)

tsaug.
random_jitter
(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, dist: Optional[str] = 'normal', strength: Optional[float] = 0.05, random_seed: Optional[int] = None) → Tuple[numpy.ndarray, Optional[numpy.ndarray]][source]¶ Add random noise 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.
 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 pseudorandom number generator. Default: None.
Returns: Augmented time series and augmented labels (if argument Y exists).
Return type: tuple (numpy.ndarray, numpy.ndarray)

tsaug.
resample
(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, n_new: Optional[int] = None) → Tuple[numpy.ndarray, Optional[numpy.ndarray]][source]¶ Resample from time series with new length.
Time series will be transformed into new length. Values of time series is determined by linear interpolation.
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.
 n_new (int, optional) – New length of time series. Default: n.
Returns: Augmented time series and augmented labels (if argument Y exists).
Return type: tuple (numpy.ndarray, numpy.ndarray)

tsaug.
reverse
(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None) → Tuple[numpy.ndarray, Optional[numpy.ndarray]][source]¶ Reverse 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)

tsaug.
random_sidetrack
(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, mode: Optional[str] = 'multiplicative', initial_sidetrack: Optional[float] = None, max_sidetrack: Optional[float] = None, min_sidetrack: Optional[float] = None, step_mu: Optional[float] = 0.0, step_sigma: Optional[float] = 0.1, random_seed: Optional[float] = None) → Tuple[numpy.ndarray, Optional[numpy.ndarray]][source]¶ Sidetrack time series from its original values.
This augmentor has two modes: multiplicative mode sidetracks a time series by multiplying its values with randomwalking multipliers, and additive mode sidetracks a time series by adding its values with randomwalking additives.
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.
 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.0
 step_sigma (float, optional) – Standard deviation of step size in random walk. Default: 0.1.
Returns: Augmented time series and augmented labels (if argument Y exists).
Return type: tuple (numpy.ndarray, numpy.ndarray)

tsaug.
random_time_warp
(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, n_speed_change: int = 3, random_seed: Optional[int] = None) → Tuple[numpy.ndarray, Optional[numpy.ndarray]][source]¶ Warp 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:  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.
 n_speed_change (int, optional) – Number of speed changes. Default: 3.
 random_seed (int, optional) – Random seed used to initialize the pseudorandom number generator. Default: None.
Returns: Augmented time series and augmented labels (if argument Y exists).
Return type: tuple (numpy.ndarray, numpy.ndarray)

tsaug.
trend
(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, anchors: Optional[numpy.ndarray] = None) → Tuple[numpy.ndarray, Optional[numpy.ndarray]][source]¶ Add 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:  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.
 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.
Returns: Augmented time series and augmented labels (if argument Y exists).
Return type: tuple (numpy.ndarray, numpy.ndarray)

tsaug.
random_trend
(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, num_anchors: int = 5, min_anchor: float = 0.0, max_anchor: float = 100.0, random_seed: Optional[int] = None) → Tuple[numpy.ndarray, Optional[numpy.ndarray]][source]¶ 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:  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.
 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 pseudorandom number generator. Default: None.
Returns: Augmented time series and augmented labels (if argument Y exists).
Return type: tuple (numpy.ndarray, numpy.ndarray)

tsaug.
magnify
(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, start: Union[int, numpy.ndarray] = 0, end: Union[int, numpy.ndarray, None] = None, size: Optional[int] = None) → Tuple[numpy.ndarray, Optional[numpy.ndarray]][source]¶ Magnify time intervels of time series.
This transformation does not change the number of time points in a 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.
 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
Returns: Augmented time series and augmented labels (if argument Y exists).
Return type: tuple (numpy.ndarray, numpy.ndarray)

tsaug.
random_magnify
(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, max_zoom: float = 2.0, min_zoom: float = 1.0, random_seed: Optional[int] = None) → Tuple[numpy.ndarray, Optional[numpy.ndarray]][source]¶ Magnify random time intervels of time series.
This transformation does not change the number of time points in a 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.
 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 pseudorandom number generator. Default: None.
Returns: Augmented time series and augmented labels (if argument Y exists).
Return type: tuple (numpy.ndarray, numpy.ndarray)