References

AddNoise([loc, scale, distr, kind, …])

Add random noise to time series.

Convolve([window, size, per_channel, …])

Convolve time series with a kernel window.

Crop(size[, resize, repeats, prob, seed])

Crop random sub-sequences from time series.

Drift([max_drift, n_drift_points, kind, …])

Drift the value of time series.

Dropout([p, size, fill, per_channel, …])

Dropout values of some random time points in time series.

Pool([kind, size, per_channel, repeats, …])

Reduce the temporal resolution without changing the length.

Quantize([n_levels, how, per_channel, …])

Quantize time series to a level set.

Resize(size[, repeats, prob, seed])

Change the temporal resolution of time series.

Reverse([repeats, prob, seed])

Reverse the time line of series.

TimeWarp([n_speed_change, max_speed_ratio, …])

Random time warping.

class tsaug.AddNoise(loc=0.0, scale=0.1, distr='gaussian', kind='additive', per_channel=True, normalize=True, repeats=1, prob=1.0, seed=None)[source]

Add random noise to time series.

The noise added to every time point of a time series is independent and identically distributed.

Parameters
  • loc (float, list, or tuple, optional) –

    Mean of the random noise.

    • If float, all noise value are sampled with the same mean.

    • If list, the noise added to a series (a channel if per_channel is True) is sampled from a distribution with a mean value that is randomly selected from the list.

    • If 2-tuple, the noise added to a series (a channel if per_channel is True) is sampled from a distribution with a mean value that is randomly selected from the interval.

    Default: 0.0.

  • scale (float, list, or tuple, optional) –

    Standard deviation of the random noise.

    • If float, all noise value are sampled with the same standard deviation.

    • If list, the noise added to a series (a channel if per_channel is True) is sampled from a distribution with a standard deviation that is randomly selected from the list.

    • If 2-tuple, the noise added to a series (a channel if per_channel is True) is sampled from a distribution with a standard deviation that is randomly selected from the interval.

    Default: 0.1.

  • distr (str, optional) – Distribution of the random noise. It must be one of ‘gaussian’, ‘laplace’, and ‘uniform’. Default: ‘gaussian’.

  • kind (str, optional) – How the noise is added to the original time series. It must be either ‘additive’ or ‘multiplicative’. Default: ‘additive’.

  • per_channel (bool, optional) – Whether to sample independent noise values for each channel in a time series or to use the same noise for all channels in a time series. Default: True.

  • normalize (bool, optional) – Whether the noise is added to the normalized time series. If True, each channel of a time series is normalized to [0, 1] first. Default: True.

  • repeats (int, optional) – The number of times a series is augmented. If greater than one, a series will be augmented so many times independently. This parameter can also be set by operator *. Default: 1.

  • prob (float, optional) – The probability of a series is augmented. It must be in (0.0, 1.0]. This parameter can also be set by operator @. Default: 1.0.

  • seed (int, optional) – The random seed. Default: None.

__add__(a)

Operator + connects this augmenter with another augmenter or an augmenter pipe to form a (new) augmenter pipe.

Parameters

a (augmenter or augmenter pipe) – The augmenter or augmenter pipe to be connected with this augmenter.

Returns

The output augmenter pipe.

Return type

augmenter pipe

__matmul__(p)

Operator @ creates an augmenter that is equivalent to running this augmenter with probability p.

Parameters

p (float) – The returned augmenter is equivalent to running this augmenter with probability p.

Returns

An augmenter that is equivalent to running this augmenter with probability p.

Return type

augmenter

__mul__(m)

Operator * creates an augmenter that is equivalent to running this augmenter for m times independently.

Parameters

m (int) – The returned augmenter is equivalent to running this augmenter for m times independently.

Returns

An augmenter that is equivalent to running this augmenter for m times independently.

Return type

augmenter

augment(X, Y=None)

Augment time series.

Parameters
  • X (numpy array) – Time series to be augmented. It must be a numpy array with shape (T,), (N, T), or (N, T, C), where T is the length of a series, N is the number of series, and C is the number of a channels in a series.

  • Y (numpy array, optional) – Segmentation mask of the original time series. It must be a binary numpy array with shape (T,), (N, T), or (N, T, L), where T is the length of a series, N is the number of series, and L is the number of a segmentation classes. Default: None.

Returns

The augmented time series, and (optionally) the augmented segmentation mask.

Return type

2-tuple (numpy array, numpy array), or numpy array

class tsaug.Convolve(window='hann', size=7, per_channel=False, repeats=1, prob=1.0, seed=None)[source]

Convolve time series with a kernel window.

Parameters
  • window (str, tuple, or list, optional) –

    The type of kernal window used for the convolution.

    Default: “hann”.

  • size (int, list, tuple, optional) –

    Length of kernel windows.

    • If int, all series are convolved with windows of the same length.

    • If list, each series is convolved with a window with a size sampled from the list randomly.

    • If 2-tuple, each series is convolved with a window with a size sampled from the interval randomly.

    Default: 7.

  • per_channel (bool, optional) – Whether to sample a kernel window for each channel in a time series or to use the same window for all channels in a time series. Only used if the kernel window is not deterministic. Default: False.

  • repeats (int, optional) – The number of times a series is augmented. If greater than one, a series will be augmented so many times independently. This parameter can also be set by operator *. Default: 1.

  • prob (float, optional) – The probability of a series is augmented. It must be in (0.0, 1.0]. This parameter can also be set by operator @. Default: 1.0.

  • seed (int, optional) – The random seed. Default: None.

__add__(a)

Operator + connects this augmenter with another augmenter or an augmenter pipe to form a (new) augmenter pipe.

Parameters

a (augmenter or augmenter pipe) – The augmenter or augmenter pipe to be connected with this augmenter.

Returns

The output augmenter pipe.

Return type

augmenter pipe

__matmul__(p)

Operator @ creates an augmenter that is equivalent to running this augmenter with probability p.

Parameters

p (float) – The returned augmenter is equivalent to running this augmenter with probability p.

Returns

An augmenter that is equivalent to running this augmenter with probability p.

Return type

augmenter

__mul__(m)

Operator * creates an augmenter that is equivalent to running this augmenter for m times independently.

Parameters

m (int) – The returned augmenter is equivalent to running this augmenter for m times independently.

Returns

An augmenter that is equivalent to running this augmenter for m times independently.

Return type

augmenter

augment(X, Y=None)

Augment time series.

Parameters
  • X (numpy array) – Time series to be augmented. It must be a numpy array with shape (T,), (N, T), or (N, T, C), where T is the length of a series, N is the number of series, and C is the number of a channels in a series.

  • Y (numpy array, optional) – Segmentation mask of the original time series. It must be a binary numpy array with shape (T,), (N, T), or (N, T, L), where T is the length of a series, N is the number of series, and L is the number of a segmentation classes. Default: None.

Returns

The augmented time series, and (optionally) the augmented segmentation mask.

Return type

2-tuple (numpy array, numpy array), or numpy array

class tsaug.Crop(size, resize=None, repeats=1, prob=1.0, seed=None)[source]

Crop random sub-sequences from time series.

To guarantee all output series have the same length, if the crop size is not deterministic, all crops must be resize to a fixed length.

Parameters
  • size (int, tuple, list) –

    The length of random crops.

    • If int, all crops have the same length.

    • If list, a crop from a series has a length sampled from this list randomly.

    • If 2-tuple, a crop from a series has a length sampled from this interval randomly.

  • resize (int, optional) – The length that all crops are resized to. Only necessary if the crop size is not fixed.

  • repeats (int, optional) – The number of times a series is augmented. If greater than one, a series will be augmented so many times independently. This parameter can also be set by operator *. Default: 1.

  • prob (float, optional) – The probability of a series is augmented. It must be in (0.0, 1.0]. If multiple output is expected, this value must be 1.0, so that all output have the same length. This parameter can also be set by operator @. Default: 1.0.

  • seed (int, optional) – The random seed. Default: None.

__add__(a)

Operator + connects this augmenter with another augmenter or an augmenter pipe to form a (new) augmenter pipe.

Parameters

a (augmenter or augmenter pipe) – The augmenter or augmenter pipe to be connected with this augmenter.

Returns

The output augmenter pipe.

Return type

augmenter pipe

__matmul__(p)

Operator @ creates an augmenter that is equivalent to running this augmenter with probability p.

Parameters

p (float) – The returned augmenter is equivalent to running this augmenter with probability p.

Returns

An augmenter that is equivalent to running this augmenter with probability p.

Return type

augmenter

__mul__(m)

Operator * creates an augmenter that is equivalent to running this augmenter for m times independently.

Parameters

m (int) – The returned augmenter is equivalent to running this augmenter for m times independently.

Returns

An augmenter that is equivalent to running this augmenter for m times independently.

Return type

augmenter

augment(X, Y=None)

Augment time series.

Parameters
  • X (numpy array) – Time series to be augmented. It must be a numpy array with shape (T,), (N, T), or (N, T, C), where T is the length of a series, N is the number of series, and C is the number of a channels in a series.

  • Y (numpy array, optional) – Segmentation mask of the original time series. It must be a binary numpy array with shape (T,), (N, T), or (N, T, L), where T is the length of a series, N is the number of series, and L is the number of a segmentation classes. Default: None.

Returns

The augmented time series, and (optionally) the augmented segmentation mask.

Return type

2-tuple (numpy array, numpy array), or numpy array

class tsaug.Drift(max_drift=0.5, n_drift_points=3, kind='additive', per_channel=True, normalize=True, repeats=1, prob=1.0, seed=None)[source]

Drift the value of time series.

The augmenter drifts the value of time series from its original values randomly and smoothly. The extent of drifting is controlled by the maximal drift and the number of drift points.

Parameters
  • max_drift (float or tuple, optional) –

    The maximal amount of drift added to a time series.

    • If float, all series (all channels if per_channel is True) are drifted with the same maximum.

    • If tuple, the maximal drift added to a time series (a channel if per_channel is True) is sampled from this interval randomly.

    Default: 0.5.

  • n_drift_points (int or list, optional) –

    The number of time points a new drifting trend is defined in a series.

    • If int, all series (all channels if per_channel is True) have the same number of drift points.

    • If list, the number of drift points defined in a series (a channel if per_channel is True) is sampled from this list randomly.

  • kind (str, optional) – How the noise is added to the original time series. It must be either ‘additive’ or ‘multiplicative’. Default: ‘additive’.

  • per_channel (bool, optional) – Whether to sample independent drifting trends for each channel in a time series or to use the same drifting trends for all channels in a time series. Default: True.

  • normalize (bool, optional) – Whether the drifting trend is added to the normalized time series. If True, each channel of a time series is normalized to [0, 1] first. Default: True.

  • repeats (int, optional) – The number of times a series is augmented. If greater than one, a series will be augmented so many times independently. This parameter can also be set by operator *. Default: 1.

  • prob (float, optional) – The probability of a series is augmented. It must be in (0.0, 1.0]. This parameter can also be set by operator @. Default: 1.0.

  • seed (int, optional) – The random seed. Default: None.

__add__(a)

Operator + connects this augmenter with another augmenter or an augmenter pipe to form a (new) augmenter pipe.

Parameters

a (augmenter or augmenter pipe) – The augmenter or augmenter pipe to be connected with this augmenter.

Returns

The output augmenter pipe.

Return type

augmenter pipe

__matmul__(p)

Operator @ creates an augmenter that is equivalent to running this augmenter with probability p.

Parameters

p (float) – The returned augmenter is equivalent to running this augmenter with probability p.

Returns

An augmenter that is equivalent to running this augmenter with probability p.

Return type

augmenter

__mul__(m)

Operator * creates an augmenter that is equivalent to running this augmenter for m times independently.

Parameters

m (int) – The returned augmenter is equivalent to running this augmenter for m times independently.

Returns

An augmenter that is equivalent to running this augmenter for m times independently.

Return type

augmenter

augment(X, Y=None)

Augment time series.

Parameters
  • X (numpy array) – Time series to be augmented. It must be a numpy array with shape (T,), (N, T), or (N, T, C), where T is the length of a series, N is the number of series, and C is the number of a channels in a series.

  • Y (numpy array, optional) – Segmentation mask of the original time series. It must be a binary numpy array with shape (T,), (N, T), or (N, T, L), where T is the length of a series, N is the number of series, and L is the number of a segmentation classes. Default: None.

Returns

The augmented time series, and (optionally) the augmented segmentation mask.

Return type

2-tuple (numpy array, numpy array), or numpy array

class tsaug.Dropout(p=0.05, size=1, fill='ffill', per_channel=False, repeats=1, prob=1.0, seed=None)[source]

Dropout values of some random time points in time series.

Single time points or sub-sequences could be dropped out.

Parameters
  • p (float, tuple, or list, optional) –

    Probablity of the value of a time point to be dropped out.

    • If float, all series (all channels if per_channel is True) have the same probability.

    • If list, a series (a channel if per_channel is True) has a probability sampled from this list randomly.

    • If 2-tuple, a series (a channel if per_channel is True) has a probability sampled from this interval randomly.

    Default: 0.05.

  • size (int, tuple, or list, optional) –

    Size of dropped out units.

    • If int, all dropped out units have the same size.

    • If list, a dropped out unit has size sampled from this list randomly.

    • If 2-tuple, a dropped out unit has size sampled from this interval randomly.

    Note that dropped out units could overlap which results in larger units effectively, though the probability is low if p is small.

    Default: 1.

  • fill (str or float, optional) –

    How a dropped out value is filled.

    • If ‘ffill’, fill with the last previous value that is not dropped.

    • If ‘bfill’, fill with the first next value that is not dropped.

    • If ‘mean’, fill with the mean value of this channel in this series.

    • If float, fill with this value.

    Default: ‘ffill’.

  • per_channel (bool, optional) – Whether to sample dropout units independently for each channel in a time series or to use the same dropout units for all channels in a time series. Default: False.

  • repeats (int, optional) – The number of times a series is augmented. If greater than one, a series will be augmented so many times independently. This parameter can also be set by operator *. Default: 1.

  • prob (float, optional) – The probability of a series is augmented. It must be in (0.0, 1.0]. This parameter can also be set by operator @. Default: 1.0.

  • seed (int, optional) – The random seed. Default: None.

__add__(a)

Operator + connects this augmenter with another augmenter or an augmenter pipe to form a (new) augmenter pipe.

Parameters

a (augmenter or augmenter pipe) – The augmenter or augmenter pipe to be connected with this augmenter.

Returns

The output augmenter pipe.

Return type

augmenter pipe

__matmul__(p)

Operator @ creates an augmenter that is equivalent to running this augmenter with probability p.

Parameters

p (float) – The returned augmenter is equivalent to running this augmenter with probability p.

Returns

An augmenter that is equivalent to running this augmenter with probability p.

Return type

augmenter

__mul__(m)

Operator * creates an augmenter that is equivalent to running this augmenter for m times independently.

Parameters

m (int) – The returned augmenter is equivalent to running this augmenter for m times independently.

Returns

An augmenter that is equivalent to running this augmenter for m times independently.

Return type

augmenter

augment(X, Y=None)

Augment time series.

Parameters
  • X (numpy array) – Time series to be augmented. It must be a numpy array with shape (T,), (N, T), or (N, T, C), where T is the length of a series, N is the number of series, and C is the number of a channels in a series.

  • Y (numpy array, optional) – Segmentation mask of the original time series. It must be a binary numpy array with shape (T,), (N, T), or (N, T, L), where T is the length of a series, N is the number of series, and L is the number of a segmentation classes. Default: None.

Returns

The augmented time series, and (optionally) the augmented segmentation mask.

Return type

2-tuple (numpy array, numpy array), or numpy array

class tsaug.Pool(kind='ave', size=2, per_channel=False, repeats=1, prob=1.0, seed=None)[source]

Reduce the temporal resolution without changing the length.

Parameters
  • kind (str, optional) – Pooling function, one of ‘max’, ‘min’, and ‘ave’. Default: ‘ave’.

  • size (str, tuple, or list, optional) –

    Size of pooling window.

    • If int, all series (all channels if per_channel is True) are pooled with the same pooling size.

    • If list, a series (a channel if per_channel is True) is pooled with a pooling size sampled from this list randomly.

    • If 2-tuple, a series (a channel if per_channel is True) is pooled with a pooling size sampled from this interval randomly.

    Default: 2.

  • per_channel (bool, optional) – Whether to sample a pooling window for each channel in a time series or to use the same window for all channels in a time series. Only used if the pooling window is not deterministic. Default: False.

  • repeats (int, optional) – The number of times a series is augmented. If greater than one, a series will be augmented so many times independently. This parameter can also be set by operator *. Default: 1.

  • prob (float, optional) – The probability of a series is augmented. It must be in (0.0, 1.0]. This parameter can also be set by operator @. Default: 1.0.

  • seed (int, optional) – The random seed. Default: None.

__add__(a)

Operator + connects this augmenter with another augmenter or an augmenter pipe to form a (new) augmenter pipe.

Parameters

a (augmenter or augmenter pipe) – The augmenter or augmenter pipe to be connected with this augmenter.

Returns

The output augmenter pipe.

Return type

augmenter pipe

__matmul__(p)

Operator @ creates an augmenter that is equivalent to running this augmenter with probability p.

Parameters

p (float) – The returned augmenter is equivalent to running this augmenter with probability p.

Returns

An augmenter that is equivalent to running this augmenter with probability p.

Return type

augmenter

__mul__(m)

Operator * creates an augmenter that is equivalent to running this augmenter for m times independently.

Parameters

m (int) – The returned augmenter is equivalent to running this augmenter for m times independently.

Returns

An augmenter that is equivalent to running this augmenter for m times independently.

Return type

augmenter

augment(X, Y=None)

Augment time series.

Parameters
  • X (numpy array) – Time series to be augmented. It must be a numpy array with shape (T,), (N, T), or (N, T, C), where T is the length of a series, N is the number of series, and C is the number of a channels in a series.

  • Y (numpy array, optional) – Segmentation mask of the original time series. It must be a binary numpy array with shape (T,), (N, T), or (N, T, L), where T is the length of a series, N is the number of series, and L is the number of a segmentation classes. Default: None.

Returns

The augmented time series, and (optionally) the augmented segmentation mask.

Return type

2-tuple (numpy array, numpy array), or numpy array

class tsaug.Quantize(n_levels=10, how='uniform', per_channel=False, repeats=1, prob=1.0, seed=None)[source]

Quantize time series to a level set.

Values in a time series are rounded to the nearest level in the level set.

Parameters
  • n_levels (int, tuple, or list, optional) –

    The number levels in a level set.

    • If int, all series (all channels if per_channel is True) are quantized to a level set of this size.

    • If list, a series (a channel if per_channel is True) is quantized to a level set whose size is sampled from this list randomly.

    • If 2-tuple, a series (a channel if per_channel is True) is quantized to a level set whose size is sampled from this interval randomly.

    Default: 10.

  • how (str, optional) –

    The method that a level set is defined.

    • If ‘uniform’, a level set is defined by uniformly discretizing the range of this channel in this series.

    • If ‘quantile’, a level set is defined by the quantiles of values in this channel in this series.

    • If ‘kmeans’, a level set is defined by k-means clustering of values in this channel in this series. Note that this method could be slow.

    Default: ‘uniform’.

  • per_channel (bool, optional) – Whether to sample a level set size for each channel in a time series or to use the same size for all channels in a time series. Only used if the level set size is not deterministic. Default: False.

  • repeats (int, optional) – The number of times a series is augmented. If greater than one, a series will be augmented so many times independently. This parameter can also be set by operator *. Default: 1.

  • prob (float, optional) – The probability of a series is augmented. It must be in (0.0, 1.0]. This parameter can also be set by operator @. Default: 1.0.

  • seed (int, optional) – The random seed. Default: None.

__add__(a)

Operator + connects this augmenter with another augmenter or an augmenter pipe to form a (new) augmenter pipe.

Parameters

a (augmenter or augmenter pipe) – The augmenter or augmenter pipe to be connected with this augmenter.

Returns

The output augmenter pipe.

Return type

augmenter pipe

__matmul__(p)

Operator @ creates an augmenter that is equivalent to running this augmenter with probability p.

Parameters

p (float) – The returned augmenter is equivalent to running this augmenter with probability p.

Returns

An augmenter that is equivalent to running this augmenter with probability p.

Return type

augmenter

__mul__(m)

Operator * creates an augmenter that is equivalent to running this augmenter for m times independently.

Parameters

m (int) – The returned augmenter is equivalent to running this augmenter for m times independently.

Returns

An augmenter that is equivalent to running this augmenter for m times independently.

Return type

augmenter

augment(X, Y=None)

Augment time series.

Parameters
  • X (numpy array) – Time series to be augmented. It must be a numpy array with shape (T,), (N, T), or (N, T, C), where T is the length of a series, N is the number of series, and C is the number of a channels in a series.

  • Y (numpy array, optional) – Segmentation mask of the original time series. It must be a binary numpy array with shape (T,), (N, T), or (N, T, L), where T is the length of a series, N is the number of series, and L is the number of a segmentation classes. Default: None.

Returns

The augmented time series, and (optionally) the augmented segmentation mask.

Return type

2-tuple (numpy array, numpy array), or numpy array

class tsaug.Resize(size, repeats=1, prob=1.0, seed=None)[source]

Change the temporal resolution of time series.

The resized time series is obtained by linear interpolation of the original time series.

Parameters
  • size (int) – Length of the output series.

  • repeats (int, optional) – The number of times a series is augmented. If greater than one, a series will be augmented so many times independently. This parameter can also be set by operator *. Default: 1.

  • prob (float, optional) – The probability of a series is augmented. It must be in (0.0, 1.0]. If multiple output is expected, this value must be 1.0, so that all output have the same length. This parameter can also be set by operator @. Default: 1.0.

  • seed (int, optional) – The random seed. Default: None.

__add__(a)

Operator + connects this augmenter with another augmenter or an augmenter pipe to form a (new) augmenter pipe.

Parameters

a (augmenter or augmenter pipe) – The augmenter or augmenter pipe to be connected with this augmenter.

Returns

The output augmenter pipe.

Return type

augmenter pipe

__matmul__(p)

Operator @ creates an augmenter that is equivalent to running this augmenter with probability p.

Parameters

p (float) – The returned augmenter is equivalent to running this augmenter with probability p.

Returns

An augmenter that is equivalent to running this augmenter with probability p.

Return type

augmenter

__mul__(m)

Operator * creates an augmenter that is equivalent to running this augmenter for m times independently.

Parameters

m (int) – The returned augmenter is equivalent to running this augmenter for m times independently.

Returns

An augmenter that is equivalent to running this augmenter for m times independently.

Return type

augmenter

augment(X, Y=None)

Augment time series.

Parameters
  • X (numpy array) – Time series to be augmented. It must be a numpy array with shape (T,), (N, T), or (N, T, C), where T is the length of a series, N is the number of series, and C is the number of a channels in a series.

  • Y (numpy array, optional) – Segmentation mask of the original time series. It must be a binary numpy array with shape (T,), (N, T), or (N, T, L), where T is the length of a series, N is the number of series, and L is the number of a segmentation classes. Default: None.

Returns

The augmented time series, and (optionally) the augmented segmentation mask.

Return type

2-tuple (numpy array, numpy array), or numpy array

class tsaug.Reverse(repeats=1, prob=1.0, seed=None)[source]

Reverse the time line of series.

Parameters
  • repeats (int, optional) – The number of times a series is augmented. If greater than one, a series will be augmented so many times independently. This parameter can also be set by operator *. Default: 1.

  • prob (float, optional) – The probability of a series is augmented. It must be in (0.0, 1.0]. This parameter can also be set by operator @. Default: 1.0.

  • seed (int, optional) – The random seed. Default: None.

__add__(a)

Operator + connects this augmenter with another augmenter or an augmenter pipe to form a (new) augmenter pipe.

Parameters

a (augmenter or augmenter pipe) – The augmenter or augmenter pipe to be connected with this augmenter.

Returns

The output augmenter pipe.

Return type

augmenter pipe

__matmul__(p)

Operator @ creates an augmenter that is equivalent to running this augmenter with probability p.

Parameters

p (float) – The returned augmenter is equivalent to running this augmenter with probability p.

Returns

An augmenter that is equivalent to running this augmenter with probability p.

Return type

augmenter

__mul__(m)

Operator * creates an augmenter that is equivalent to running this augmenter for m times independently.

Parameters

m (int) – The returned augmenter is equivalent to running this augmenter for m times independently.

Returns

An augmenter that is equivalent to running this augmenter for m times independently.

Return type

augmenter

augment(X, Y=None)

Augment time series.

Parameters
  • X (numpy array) – Time series to be augmented. It must be a numpy array with shape (T,), (N, T), or (N, T, C), where T is the length of a series, N is the number of series, and C is the number of a channels in a series.

  • Y (numpy array, optional) – Segmentation mask of the original time series. It must be a binary numpy array with shape (T,), (N, T), or (N, T, L), where T is the length of a series, N is the number of series, and L is the number of a segmentation classes. Default: None.

Returns

The augmented time series, and (optionally) the augmented segmentation mask.

Return type

2-tuple (numpy array, numpy array), or numpy array

class tsaug.TimeWarp(n_speed_change=3, max_speed_ratio=3.0, repeats=1, prob=1.0, seed=None)[source]

Random time warping.

The augmenter random changed the speed of timeline. The time warping is controlled by the number of speed changes and the maximal ratio of max/min speed.

Parameters
  • n_speed_change (int, optional) – The number of speed changes in each series. Default: 3.

  • max_speed_ratio (float, tuple, or list, optional) –

    The maximal ratio of max/min speed in the warpped time line. The time line of a series is more likely to be significantly warpeped if this value is greater.

    • If float, all series are warpped with the same ratio.

    • If list, each series is warpped with a ratio that is randomly sampled from the list.

    • If 2-tuple, each series is warpped with a ratio that is randomly sampled from the interval.

    Default: 3.0.

  • repeats (int, optional) – The number of times a series is augmented. If greater than one, a series will be augmented so many times independently. This parameter can also be set by operator *. Default: 1.

  • prob (float, optional) – The probability of a series is augmented. It must be in (0.0, 1.0]. This parameter can also be set by operator @. Default: 1.0.

  • seed (int, optional) – The random seed. Default: None.

__add__(a)

Operator + connects this augmenter with another augmenter or an augmenter pipe to form a (new) augmenter pipe.

Parameters

a (augmenter or augmenter pipe) – The augmenter or augmenter pipe to be connected with this augmenter.

Returns

The output augmenter pipe.

Return type

augmenter pipe

__matmul__(p)

Operator @ creates an augmenter that is equivalent to running this augmenter with probability p.

Parameters

p (float) – The returned augmenter is equivalent to running this augmenter with probability p.

Returns

An augmenter that is equivalent to running this augmenter with probability p.

Return type

augmenter

__mul__(m)

Operator * creates an augmenter that is equivalent to running this augmenter for m times independently.

Parameters

m (int) – The returned augmenter is equivalent to running this augmenter for m times independently.

Returns

An augmenter that is equivalent to running this augmenter for m times independently.

Return type

augmenter

augment(X, Y=None)

Augment time series.

Parameters
  • X (numpy array) – Time series to be augmented. It must be a numpy array with shape (T,), (N, T), or (N, T, C), where T is the length of a series, N is the number of series, and C is the number of a channels in a series.

  • Y (numpy array, optional) – Segmentation mask of the original time series. It must be a binary numpy array with shape (T,), (N, T), or (N, T, L), where T is the length of a series, N is the number of series, and L is the number of a segmentation classes. Default: None.

Returns

The augmented time series, and (optionally) the augmented segmentation mask.

Return type

2-tuple (numpy array, numpy array), or numpy array

tsaug.visualization.plot(X, Y=None)[source]

Plot time series and segmentation mask.

This function requires matplotlib>=3.0.

Parameters
  • X (numpy array) – Time series to be augmented. It must be a numpy array with shape (T,), (N, T), or (N, T, C), where T is the length of a series, N is the number of series, and C is the number of a channels in a series.

  • Y (numpy array, optional) – Segmentation mask of the original time series. It must be a binary numpy array with shape (T,), (N, T), or (N, T, L), where T is the length of a series, N is the number of series, and L is the number of a segmentation classes. Default: None.

Returns

Figure and axes object of the plot.

Return type

tuple (matplotlib Figure, matplotlib Axes)