Skip to content

Commit

Permalink
Merge pull request #422 from yzhao062/development
Browse files Browse the repository at this point in the history
v1.0.3
  • Loading branch information
yzhao062 authored Jul 5, 2022
2 parents 3a0a55a + 3cdc6de commit c2839e0
Show file tree
Hide file tree
Showing 84 changed files with 766 additions and 143 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,6 @@ v<1.0.1>, <04/27/2022> -- Add INNE (#396).
v<1.0.1>, <05/13/2022> -- Urgent fix for iForest (#406).
v<1.0.2>, <06/21/2022> -- Add GMM detector (#402).
v<1.0.2>, <06/23/2022> -- Add ADBench Benchmark.
v<1.0.3>, <06/27/2022> -- Change default generation to new behaviors (#409).
v<1.0.3>, <07/04/2022> -- Add AnoGAN (#412).

3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ Neural Networks Beta-VAE Variational AutoEncoder (all customized
Neural Networks SO_GAAL Single-Objective Generative Adversarial Active Learning 2019 [#Liu2019Generative]_
Neural Networks MO_GAAL Multiple-Objective Generative Adversarial Active Learning 2019 [#Liu2019Generative]_
Neural Networks DeepSVDD Deep One-Class Classification 2018 [#Ruff2018Deep]_
Neural Networks AnoGAN Anomaly Detection with Generative Adversarial Networks 2017 [#Schlegl2017Unsupervised]_
=================== ================== ====================================================================================================== ===== ========================================


Expand Down Expand Up @@ -620,6 +621,8 @@ Reference
.. [#Ruff2018Deep] Ruff, L., Vandermeulen, R., Goernitz, N., Deecke, L., Siddiqui, S.A., Binder, A., Müller, E. and Kloft, M., 2018, July. Deep one-class classification. In *International conference on machine learning* (pp. 4393-4402). PMLR.
.. [#Schlegl2017Unsupervised] Schlegl, T., Seeböck, P., Waldstein, S.M., Schmidt-Erfurth, U. and Langs, G., 2017, June. Unsupervised anomaly detection with generative adversarial networks to guide marker discovery. In International conference on information processing in medical imaging (pp. 146-157). Springer, Cham.
.. [#Scholkopf2001Estimating] Scholkopf, B., Platt, J.C., Shawe-Taylor, J., Smola, A.J. and Williamson, R.C., 2001. Estimating the support of a high-dimensional distribution. *Neural Computation*, 13(7), pp.1443-1471.
.. [#Shyu2003A] Shyu, M.L., Chen, S.C., Sarinnapakorn, K. and Chang, L., 2003. A novel anomaly detection scheme based on principal component classifier. *MIAMI UNIV CORAL GABLES FL DEPT OF ELECTRICAL AND COMPUTER ENGINEERING*.
Expand Down
14 changes: 12 additions & 2 deletions docs/about.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,19 @@ Roel Bouman (Ph.D. Student @ Radboud University):
Rafał Bodziony (Data Scientist):

- Joined in 2021 (implemented DeepSVDD)
- `LinkedIn (Roel Bouman) <https://pl.linkedin.com/in/rafalbodziony>`_
- `LinkedIn (Rafał Bodziony) <https://pl.linkedin.com/in/rafalbodziony>`_

Dr Akira Tamamori (Associate Professor @ Aichi Institute of Technology):

- Joined in 2022 (implemented multiple OD algorithms such as KDE, sampling, and more)
- `Homepage (Dr Akira Tamamori) <https://researchmap.jp/tamamori?lang=en>`_
- `Homepage (Dr Akira Tamamori) <https://researchmap.jp/tamamori?lang=en>`_

Michiel Bongaerts (PhD student @ Erasmus Medical Centre Metabolomics & Genetics):

- Joined in 2022 (implemented AnoGAN and more)
- `GitHub (Michiel Bongaerts) <https://github.com/mbongaerts>`_

Adam Goodge (PhD Researcher @ National University of Singapore):

- Joined in 2022 (implemented LUNAR)
- `LinkedIn (Adam Goodge) <https://www.linkedin.com/in/adam-goodge-33908691/>`_
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ Neural Networks Beta-VAE Variational AutoEncoder (all customized l
Neural Networks SO_GAAL Single-Objective Generative Adversarial Active Learning 2019 :class:`pyod.models.so_gaal.SO_GAAL` :cite:`a-liu2019generative`
Neural Networks MO_GAAL Multiple-Objective Generative Adversarial Active Learning 2019 :class:`pyod.models.mo_gaal.MO_GAAL` :cite:`a-liu2019generative`
Neural Networks DeepSVDD Deep One-Class Classification 2018 :class:`pyod.models.deep_svdd.DeepSVDD` :cite:`a-ruff2018deepsvdd`
Neural Networks AnoGAN Anomaly Detection with Generative Adversarial Networks 2017 :class:`pyod.models.anogan.AnoGAN` :cite:`a-schlegl2017unsupervised`
=================== ================ ====================================================================================================== ===== =================================================== ======================================================


Expand Down
9 changes: 9 additions & 0 deletions docs/pyod.models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ pyod.models.abod module
:show-inheritance:
:inherited-members:

pyod.models.anogan module
-------------------------

.. automodule:: pyod.models.anogan
:members:
:undoc-members:
:show-inheritance:
:inherited-members:

pyod.models.auto\_encoder module
--------------------------------

Expand Down
9 changes: 9 additions & 0 deletions docs/zreferences.bib
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,13 @@ @article{bandaragoda2018isolation
pages={968--998},
year={2018},
publisher={Wiley Online Library}
}

@inproceedings{schlegl2017unsupervised,
title={Unsupervised anomaly detection with generative adversarial networks to guide marker discovery},
author={Schlegl, Thomas and Seeb{\"o}ck, Philipp and Waldstein, Sebastian M and Schmidt-Erfurth, Ursula and Langs, Georg},
booktitle={International conference on information processing in medical imaging},
pages={146--157},
year={2017},
organization={Springer}
}
2 changes: 1 addition & 1 deletion examples/abod_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
n_test = 100 # number of testing points

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=2,
Expand Down
67 changes: 67 additions & 0 deletions examples/anogan_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
"""Example for Anomaly Detection with Generative Adversarial Networks (AnoGAN)
Paper: https://arxiv.org/pdf/1703.05921.pdf
Note, that this is another implementation of AnoGAN as the one from https://github.com/fuchami/ANOGAN
"""
# Author: Michiel Bongaerts (but not author of the AnoGAN method)
# License: BSD 2 clause


from __future__ import division
from __future__ import print_function

import os
import sys

# temporary solution for relative imports in case pyod is not installed
# if pyod is installed, no need to use the following line
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname("__file__"), '..')))

from pyod.models.anogan import AnoGAN
from pyod.utils.data import generate_data
from pyod.utils.data import evaluate_print
from pyod.utils.example import visualize

if __name__ == "__main__":
contamination = 0.1 # percentage of outliers
n_train = 200 # number of training points
n_test = 100 # number of testing points

# Generate sample data
X_train, X_test, y_train, y_test = generate_data(
n_train=n_train,
n_test=n_test,
n_features=2,
contamination=contamination,
behaviour="new",
random_state=42,
)

# train AutoEncoder detector
clf_name = 'AnoGAN'
clf = AnoGAN(G_layers=[10, 20], D_layers=[20, 2],
preprocessing=True, index_D_layer_for_recon_error=1,
epochs=200, contamination=contamination, verbose=1)

clf.fit(X_train)

# get the prediction labels and outlier scores of the training data
y_train_pred = clf.labels_ # binary labels (0: inliers, 1: outliers)
y_train_scores = clf.decision_scores_ # raw outlier scores

# get the prediction on the test data
y_test_pred = clf.predict(X_test) # outlier labels (0 or 1)
y_test_scores = clf.decision_function(X_test) # outlier scores

# evaluate and print the results
print("\nOn Training Data:")
evaluate_print(clf_name, y_train, y_train_scores)
print("\nOn Test Data:")
evaluate_print(clf_name, y_test, y_test_scores)

# visualize the results
visualize(clf_name, X_train, y_train, X_test, y_test, y_train_pred,
y_test_pred, show_figure=True, save_figure=False)

clf.plot_learning_curves(window_smoothening=30)
2 changes: 1 addition & 1 deletion examples/auto_encoder_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
n_features = 300 # number of features

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=n_features,
Expand Down
2 changes: 1 addition & 1 deletion examples/auto_encoder_torch_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
n_features = 300 # number of features

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=n_features,
Expand Down
2 changes: 1 addition & 1 deletion examples/cblof_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
n_test = 100 # number of testing points

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=2,
Expand Down
2 changes: 1 addition & 1 deletion examples/cd_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
n_test = 100 # number of testing points

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=2,
Expand Down
2 changes: 1 addition & 1 deletion examples/cof_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
n_test = 100 # number of testing points

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=2,
Expand Down
4 changes: 0 additions & 4 deletions examples/compare_all_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,10 @@
from pyod.models.iforest import IForest
from pyod.models.knn import KNN
from pyod.models.lof import LOF
from pyod.models.loci import LOCI
from pyod.models.mcd import MCD
from pyod.models.ocsvm import OCSVM
from pyod.models.pca import PCA
from pyod.models.sos import SOS
from pyod.models.lscp import LSCP
from pyod.models.cof import COF
from pyod.models.sod import SOD

# TODO: add neural networks, LOCI, SOS, COF, SOD

Expand Down
2 changes: 1 addition & 1 deletion examples/copod_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
n_test = 100 # number of testing points

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=2,
Expand Down
4 changes: 2 additions & 2 deletions examples/copod_parallel_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
n_test = 100 # number of testing points

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=10,
n_features=2,
contamination=contamination,
random_state=42)

Expand Down
7 changes: 4 additions & 3 deletions examples/deepsvdd_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
n_train = 20000 # number of training points
n_test = 2000 # number of testing points
n_features = 300 # number of features
use_ae = False # hyperparameter for use ae architecture instead of simple NN
random_state = 10 # if C is set to None use random_state
use_ae = False # hyperparameter for use ae architecture instead of simple NN
random_state = 10 # if C is set to None use random_state

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=n_features,
Expand Down
2 changes: 1 addition & 1 deletion examples/ecod_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
n_test = 100 # number of testing points

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=2,
Expand Down
2 changes: 1 addition & 1 deletion examples/feature_bagging_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
n_test = 100 # number of testing points

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=2,
Expand Down
2 changes: 1 addition & 1 deletion examples/hbos_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
n_test = 100 # number of testing points

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=2,
Expand Down
2 changes: 1 addition & 1 deletion examples/iforest_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
n_test = 100 # number of testing points

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=2,
Expand Down
2 changes: 1 addition & 1 deletion examples/inne_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
n_test = 100 # number of testing points

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=2,
Expand Down
14 changes: 6 additions & 8 deletions examples/kde_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@
n_test = 100 # number of testing points

# Generate sample data
X_train, X_test, y_train, y_test = generate_data(
n_train=n_train,
n_test=n_test,
n_features=2,
contamination=contamination,
behaviour="new",
random_state=42,
)
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=2,
contamination=contamination,
random_state=42)

# train kNN detector
clf_name = "KDE"
Expand Down
2 changes: 1 addition & 1 deletion examples/knn_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
n_test = 100 # number of testing points

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=2,
Expand Down
2 changes: 1 addition & 1 deletion examples/knn_mahalanobis_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
n_test = 100 # number of testing points

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=2,
Expand Down
2 changes: 1 addition & 1 deletion examples/lmdd_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
n_test = 100 # number of testing points

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=2,
Expand Down
2 changes: 1 addition & 1 deletion examples/loci_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
n_test = 100 # number of testing points

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=2,
Expand Down
2 changes: 1 addition & 1 deletion examples/loda_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
n_test = 100 # number of testing points

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=2,
Expand Down
2 changes: 1 addition & 1 deletion examples/lof_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
n_test = 100 # number of testing points

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=2,
Expand Down
4 changes: 2 additions & 2 deletions examples/lscp_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
n_test = 100 # number of testing points

# Generate sample data
X_train, y_train, X_test, y_test = \
X_train, X_test, y_train, y_test = \
generate_data(n_train=n_train,
n_test=n_test,
n_features=2,
contamination=contamination,
random_state=42)
X_train, X_test = standardizer(X_train, X_test)

# train lscp
clf_name = 'LSCP'
Expand Down
Loading

0 comments on commit c2839e0

Please sign in to comment.