yzhao062/Pyod

View on GitHub
pyod/models/anogan.py

Summary

Maintainability
F
5 days
Test Coverage

File anogan.py has 313 lines of code (exceeds 250 allowed). Consider refactoring.
Wontfix

# -*- coding: utf-8 -*-
"""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
"""
Severity: Minor
Found in pyod/models/anogan.py - About 3 hrs to fix

    Function __init__ has 15 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, activation_hidden='tanh',
    Severity: Major
    Found in pyod/models/anogan.py - About 1 hr to fix

      Function fit has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def fit(self, X, y=None):
              """Fit detector. y is ignored in unsupervised methods.
      
              Parameters
              ----------
      Severity: Minor
      Found in pyod/models/anogan.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          def plot_learning_curves(self, start_ind=0,
                                   window_smoothening=10):  # pragma: no cover
              fig = plt.figure(figsize=(12, 5))
      
              l_gen = pd.Series(self.hist_loss_generator[start_ind:]).rolling(
      Severity: Major
      Found in pyod/models/anogan.py and 1 other location - About 1 day to fix
      pyod/models/alad.py on lines 445..465

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 208.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

              for i in range(X_norm.shape[0]):
                  if (self.verbose == 1):
                      print('query sample {} / {}'.format(i + 1, X_norm.shape[0]))
      
                  sample = X_norm[[i],]
      Severity: Major
      Found in pyod/models/anogan.py and 1 other location - About 5 hrs to fix
      pyod/models/anogan.py on lines 427..433

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 89.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

              for i in range(X_norm.shape[0]):
                  if (self.verbose == 1):
                      print('query sample {} / {}'.format(i + 1, X_norm.shape[0]))
      
                  sample = X_norm[[i],]
      Severity: Major
      Found in pyod/models/anogan.py and 1 other location - About 5 hrs to fix
      pyod/models/anogan.py on lines 386..392

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 89.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

              for i, l_dim in enumerate(self.G_layers):
                  layer_name = 'hl_{}'.format(i)
                  G_hl_dict[layer_name] = Dropout(self.dropout_rate)(
                      Dense(l_dim, activation=self.activation_hidden)(last_layer))
                  last_layer = G_hl_dict[layer_name]
      Severity: Major
      Found in pyod/models/anogan.py and 3 other locations - About 3 hrs to fix
      pyod/models/alad.py on lines 204..209
      pyod/models/alad.py on lines 224..229
      pyod/models/anogan.py on lines 187..191

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 72.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

              for i, l_dim in enumerate(self.D_layers):
                  layer_name = 'hl_{}'.format(i)
                  D_hl_dict[layer_name] = Dropout(self.dropout_rate)(
                      Dense(l_dim, activation=self.activation_hidden)(last_layer))
                  last_layer = D_hl_dict[layer_name]
      Severity: Major
      Found in pyod/models/anogan.py and 3 other locations - About 3 hrs to fix
      pyod/models/alad.py on lines 204..209
      pyod/models/alad.py on lines 224..229
      pyod/models/anogan.py on lines 169..173

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 72.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

      if _get_tensorflow_version() < 200:
          raise NotImplementedError('Model not implemented for Tensorflow version 1')
      
      elif 200 <= _get_tensorflow_version() <= 209:
          import tensorflow as tf
      Severity: Major
      Found in pyod/models/anogan.py and 1 other location - About 3 hrs to fix
      pyod/models/alad.py on lines 21..32

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 63.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 5 locations. Consider refactoring.
      Open

              if self.preprocessing:
                  self.scaler_ = StandardScaler()
                  X_norm = self.scaler_.fit_transform(X)
              else:
                  X_norm = np.copy(X)
      Severity: Major
      Found in pyod/models/anogan.py and 4 other locations - About 1 hr to fix
      pyod/models/alad.py on lines 489..493
      pyod/models/auto_encoder.py on lines 223..227
      pyod/models/deep_svdd.py on lines 254..258
      pyod/models/vae.py on lines 322..326

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 40.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      There are no issues that match your filters.

      Category
      Status