Browse Source

!9874 Add checking the threshold of anomaly detection

From: @zhangxinfeng3
Reviewed-by: @zichun_ye,@wang_zi_dong
Signed-off-by: @zichun_ye
tags/v1.1.0
mindspore-ci-bot Gitee 5 years ago
parent
commit
63fcab9d86
1 changed files with 3 additions and 1 deletions
  1. +3
    -1
      mindspore/nn/probability/toolbox/anomaly_detection.py

+ 3
- 1
mindspore/nn/probability/toolbox/anomaly_detection.py View File

@@ -15,6 +15,7 @@
"""Toolbox for anomaly detection by using VAE.""" """Toolbox for anomaly detection by using VAE."""
import numpy as np import numpy as np


from mindspore._checkparam import Validator
from ..dpn import VAE from ..dpn import VAE
from ..infer import ELBO, SVI from ..infer import ELBO, SVI
from ...optim import Adam from ...optim import Adam
@@ -26,7 +27,7 @@ class VAEAnomalyDetection:
Toolbox for anomaly detection by using VAE. Toolbox for anomaly detection by using VAE.


Variational Auto-Encoder(VAE) can be used for Unsupervised Anomaly Detection. The anomaly score is the error Variational Auto-Encoder(VAE) can be used for Unsupervised Anomaly Detection. The anomaly score is the error
between the X and the reconstruction. If the score is high, the X is mostly outlier.
between the X and the reconstruction of X. If the score is high, the X is mostly outlier.


Args: Args:
encoder(Cell): The Deep Neural Network (DNN) model defined as encoder. encoder(Cell): The Deep Neural Network (DNN) model defined as encoder.
@@ -84,6 +85,7 @@ class VAEAnomalyDetection:
Returns: Returns:
Bool, whether the sample is an outlier. Bool, whether the sample is an outlier.
""" """
threshold = Validator.check_positive_float(threshold)
score = self.predict_outlier_score(sample_x) score = self.predict_outlier_score(sample_x)
return score >= threshold return score >= threshold




Loading…
Cancel
Save