Skip to content

Commit

Permalink
Merge pull request #585 from RaymondY/development
Browse files Browse the repository at this point in the history
Add PyTorch Version of VAE, AE, SO_GAAL based on the DL base detector && Fix some bugs in DL base detector.
  • Loading branch information
yzhao062 authored Jun 17, 2024
2 parents 9115d29 + f7eba86 commit fe6c899
Show file tree
Hide file tree
Showing 16 changed files with 1,254 additions and 1,654 deletions.
5 changes: 3 additions & 2 deletions examples/auto_encoder_example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Example of using AutoEncoder for outlier detection
"""
# Author: Yue Zhao <zhaoy@cmu.edu>
# Author: Tiankai Yang <tiankaiy@usc.edu>
# License: BSD 2 clause

from __future__ import division
Expand All @@ -14,6 +14,7 @@
# if pyod is installed, no need to use the following line
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname("__file__"), '..')))
sys.path.append(os.path.abspath(os.path.dirname("__file__")))

from pyod.models.auto_encoder import AutoEncoder
from pyod.utils.data import generate_data
Expand All @@ -35,7 +36,7 @@

# train AutoEncoder detector
clf_name = 'AutoEncoder'
clf = AutoEncoder(epochs=30, contamination=contamination)
clf = AutoEncoder(epoch_num=30, contamination=contamination)
clf.fit(X_train)

# get the prediction labels and outlier scores of the training data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
"""Example of using Autoencoder for outlier detection (pytorch)
detection
"""Example of using Single-Objective Generative Adversarial Active
Learning (SO_GAAL) for outlier detection
"""
# Author: Yue Zhao <zhaoy@cmu.edu>
# Author: Tiankai Yang <tiankaiy@usc.edu>
# License: BSD 2 clause

from __future__ import division
Expand All @@ -15,16 +15,16 @@
# if pyod is installed, no need to use the following line
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname("__file__"), '..')))
sys.path.append(os.path.abspath(os.path.dirname("__file__")))

from pyod.models.auto_encoder_torch import AutoEncoder
from pyod.models.so_gaal_new import SO_GAAL
from pyod.utils.data import generate_data
from pyod.utils.data import evaluate_print


if __name__ == "__main__":
contamination = 0.1 # percentage of outliers
n_train = 20000 # number of training points
n_test = 2000 # number of testing points
n_train = 30000 # number of training points
n_test = 3000 # number of testing points
n_features = 300 # number of features

# Generate sample data
Expand All @@ -35,9 +35,9 @@
contamination=contamination,
random_state=42)

# train AutoEncoder detector
clf_name = 'AutoEncoder'
clf = AutoEncoder(epochs=10)
# train SO_GAAL detector
clf_name = 'SO_GAAL'
clf = SO_GAAL(epoch_num=6, contamination=contamination, verbose=2)
clf.fit(X_train)

# get the prediction labels and outlier scores of the training data
Expand Down
5 changes: 3 additions & 2 deletions examples/vae_example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Example of using Variational Auto Encoder for outlier detection
"""
# Author: Andrij Vasylenko <[email protected]>
# Author: Tiankai Yang <[email protected]>
# License: BSD 2 clause

from __future__ import division
Expand All @@ -14,6 +14,7 @@
# if pyod is installed, no need to use the following line
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname("__file__"), '..')))
sys.path.append(os.path.abspath(os.path.dirname("__file__")))

from pyod.models.vae import VAE
from pyod.utils.data import generate_data
Expand All @@ -35,7 +36,7 @@

# train VAE detector (Beta-VAE)
clf_name = 'VAE'
clf = VAE(epochs=30, contamination=contamination, gamma=0.8, capacity=0.2)
clf = VAE(epoch_num=30, contamination=contamination, beta=0.8, capacity=0.2)
clf.fit(X_train)

# get the prediction labels and outlier scores of the training data
Expand Down
Loading

0 comments on commit fe6c899

Please sign in to comment.