Anomaly Manager

Anomaly manager containing the loading, execution and saving logic.

class ecgan.anomaly_detection.anomaly_manager.AnomalyManager(cfg, seq_len, tracker, num_channels)[source]

Bases: object

Load and set model, delegate work to anomaly detector and trigger visualization/evaluation logic.

Parameters
  • cfg (AnomalyDetectionConfig) -- Configuration used for anomaly detection, including reference to existing model.

  • seq_len (int) -- Sequence length used by the module.

  • tracker (BaseTracker) -- Tracker to save evaluation.

  • num_channels -- Amount of channels used by the module.

start_detection(train_x, train_y, test_x, test_y, vali_x, vali_y)[source]

Triggers the anomaly detection and contains the relevant logic.

Expects the same train and test data and labels as during training.

Parameters
  • train_x (Tensor) -- Train dataset from model fitting.

  • train_y (Tensor) -- Train labels from model fitting.

  • test_x (Tensor) -- Test dataset from model fitting.

  • test_y (Tensor) -- Test labels from model fitting.

  • vali_x (Tensor) -- Validation dataset from model fitting.

  • vali_y (Tensor) -- Validation labels from model fitting.

Return type

None

evaluate_performance(test_y, predicted_labels)[source]

Evaluate the anomaly detection performance.

Calculate the F1 and MCC score and log them using the tracker. If the detector is an interpolation reconstructor: also visualize the distribution of the norm of the latent vectors.

Parameters
  • test_y (ndarray) -- Real test labels.

  • predicted_labels (ndarray) -- Predicted test labels.

Return type

None

create_embedding(train_x, test_x, vali_x, train_y, test_y, vali_y)[source]

Create an embedding trained on train and validation data with embedded test data and save the embedding.

Return type

None