alibi_detect.utils.perturbation module

alibi_detect.utils.perturbation.apply_mask(X, mask_size=(4, 4), n_masks=1, coord=None, channels=[0, 1, 2], mask_type='uniform', noise_distr=(0, 1), noise_rng=(0, 1), clip_rng=(0, 1))[source]

Mask images. Can zero out image patches or add normal or uniformly distributed noise.

Parameters
  • X (numpy.ndarray) – Batch of instances to be masked.

  • mask_size (tuple) – Tuple with the size of the mask.

  • n_masks (int) – Number of masks applied for each instance in the batch X.

  • coord (Optional[tuple]) – Upper left (x,y)-coordinates for the mask.

  • channels (list) – Channels of the image to apply the mask to.

  • mask_type (str) – Type of mask. One of ‘uniform’, ‘random’ (both additive noise) or ‘zero’ (zero values for mask).

  • noise_distr (tuple) – Mean and standard deviation for noise of ‘random’ mask type.

  • noise_rng (tuple) – Min and max value for noise of ‘uniform’ type.

  • clip_rng (tuple) – Min and max values for the masked instances.

Return type

Tuple[numpy.ndarray, numpy.ndarray]

Returns

Tuple with masked instances and the masks.

alibi_detect.utils.perturbation.inject_outlier_ts(X, perc_outlier, perc_window=10, n_std=2.0, min_std=1.0)[source]

Inject outliers in both univariate and multivariate time series data.

Parameters
  • X (numpy.ndarray) – Time series data to perturb (inject outliers).

  • perc_outlier (int) – Percentage of observations which are perturbed to outliers. For multivariate data, the percentage is evenly split across the individual time series.

  • perc_window (int) – Percentage of the observations used to compute the standard deviation used in the perturbation.

  • n_std (float) – Number of standard deviations in the window used to perturb the original data.

  • min_std (float) – Minimum number of standard deviations away from the current observation. This is included because of the stochastic nature of the perturbation which could lead to minimal perturbations without a floor.

Return type

Bunch

Returns

Bunch object with the perturbed time series and the outlier labels.