Label
Functions to label synthetic data.
- ecgan.utils.label.count_nonzero(input, dim=None) Tensor
Counts the number of non-zero values in the tensor
input
along the givendim
. If no dim is specified then all non-zeros in the tensor are counted.- Parameters
input (Tensor) -- the input tensor.
dim (int or tuple of ints, optional) -- Dim or tuple of dims along which to count non-zeros.
Example:
>>> x = torch.zeros(3,3) >>> x[torch.randn(3,3) > 0.5] = 1 >>> x tensor([[0., 1., 1.], [0., 0., 0.], [0., 0., 1.]]) >>> torch.count_nonzero(x) tensor(3) >>> torch.count_nonzero(x, dim=0) tensor([0, 1, 2])
- ecgan.utils.label.label_generated_data_pointwise(anomaly_scores, tau)[source]
Labeling of generated data depending on some tau.
- Parameters
anomaly_scores (
Tensor
) -- Pointwise anomaly scorestau (
float
) -- Anomaly threshold.
- Return type
Tensor
- Returns
The labels of generated series/data points.
- ecgan.utils.label.label_data_by_summation(anomaly_scores, tau, channelwise=True)[source]
Calculate one label per channel (or series if channelwise=False).
Utilizes the sum of pointwise anomaly scores and checks if the average anomaly score is below tau.
- Parameters
anomaly_scores (
Tensor
) -- Pointwise anomaly scores.tau -- (Pointwise) anomaly threshold.
channelwise (
bool
) -- Flag to indicate if the data should be labeled channelwise.
- Return type
Tensor
- Returns
One label for each series or channel, meaning anomaly_scores.shape[0] labels for serieswise scoring and respectively anomaly_score.shape[0] * anomaly_score.shape[2] labels for channelwise detection will be returned.
- ecgan.utils.label.label_data_by_variance(anomaly_scores, tau, channelwise=True)[source]
Calculate one label per channel (or series if channelwise=False).
Utilizes the variance of pointwise anomaly scores and checks if the anomaly score is below the given tau.
- Parameters
anomaly_scores (
Tensor
) -- Pointwise anomaly scores.tau (
float
) -- (Pointwise) anomaly threshold.channelwise (
bool
) -- Flag indicating if you want to return channelwise or serieswise anomaly scores.
- Return type
Tensor
- Returns
One label for each series or channel, meaning anomaly_scores.shape[0] labels for serieswise scoring and respectively anomaly_score.shape[0] * anomaly_score.shape[2] labels for channelwise detection will be returned.
- ecgan.utils.label.label_absolute(anomaly_scores, tau=0.2, anomaly_lower_bound=None)[source]
Label channels based on the absolute amount of pointwise anomalies.
A channel is labeled as anomalous if more than anomaly_lower_bound samples are labeled during the pointwise detection.
- Return type
Tensor
- ecgan.utils.label.label(anomaly_scores, strategy=LabelingStrategy.POINTWISE, tau=0.2)[source]
Label synthetic data based on the respective anomaly scores.
- Parameters
anomaly_scores (
Tensor
) -- Series of pointwise anomaly scores.strategy (
LabelingStrategy
) -- Labeling strategy: either pointwise, channelwise or serieswise.tau (
float
) -- Anomaly threshold.
- Return type
Tensor
- Returns
Labels for each data point, channel or series. User has to ensure the correct format.