yzhao062/Pyod

View on GitHub
pyod/models/alad.py

Summary

Maintainability
F
3 days
Test Coverage

File alad.py has 454 lines of code (exceeds 250 allowed). Consider refactoring.
Wontfix

# -*- coding: utf-8 -*-
"""Using Adversarially Learned Anomaly Detection
"""
# Author: Michiel Bongaerts (but not author of the ALAD method)

Severity: Minor
Found in pyod/models/alad.py - About 6 hrs to fix

    Function __init__ has 21 arguments (exceeds 4 allowed). Consider refactoring.
    Wontfix

        def __init__(self, activation_hidden_gen='tanh',
    Severity: Major
    Found in pyod/models/alad.py - About 2 hrs to fix

      Function _build_model has 52 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def _build_model(self):
      
              #### Decoder #####
              dec_in = Input(shape=(self.latent_dim,), name='I1')
              dec_1 = Dropout(self.dropout_rate)(dec_in)
      Severity: Major
      Found in pyod/models/alad.py - About 2 hrs to fix

        Function _build_model has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            def _build_model(self):
        
                #### Decoder #####
                dec_in = Input(shape=(self.latent_dim,), name='I1')
                dec_1 = Dropout(self.dropout_rate)(dec_in)
        Severity: Minor
        Found in pyod/models/alad.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

        Function train_step has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def train_step(self, data):
                cross_entropy = tf.keras.losses.BinaryCrossentropy(from_logits=False)
        
                x_real, z_real = data
        
        
        Severity: Minor
        Found in pyod/models/alad.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

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

            def fit(self, X, y=None, noise_std=0.1):
                """Fit detector. y is ignored in unsupervised methods.
                Parameters
                ----------
                X : numpy array of shape (n_samples, n_features)
        Severity: Minor
        Found in pyod/models/alad.py - About 55 mins 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

        Function train_more has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def train_more(self, X, epochs=100, noise_std=0.1):
                """This function allows the researcher to perform extra training instead of the fixed number determined
                by the fit() function.
                """
        
        
        Severity: Minor
        Found in pyod/models/alad.py - About 55 mins 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):
                fig = plt.figure(figsize=(12, 5))
        
                l_gen = pd.Series(self.hist_loss_gen[start_ind:]).rolling(
                    window_smoothening).mean()
        Severity: Major
        Found in pyod/models/alad.py and 1 other location - About 1 day to fix
        pyod/models/anogan.py on lines 206..227

        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

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

                for n in range(self.epochs):
                    if ((n % 50 == 0) and (n != 0) and (self.verbose == 1)):
                        print('Train iter:{}'.format(n))
        
                    # Shuffle train 
        Severity: Major
        Found in pyod/models/alad.py and 1 other location - About 1 day to fix
        pyod/models/alad.py on lines 536..549

        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 160.

        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.
        Invalid

                for n in range(epochs):
                    if ((n % 50 == 0) and (n != 0) and (self.verbose == 1)):
                        print('Train iter:{}'.format(n))
        
                    # Shuffle train 
        Severity: Major
        Found in pyod/models/alad.py and 1 other location - About 1 day to fix
        pyod/models/alad.py on lines 495..508

        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 160.

        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 3 locations. Consider refactoring.
        Invalid

                for i, l_dim in enumerate(self.disc_xz_layers):
                    layer_name = 'hl_{}'.format(i)
        
                    if (self.spectral_normalization == True):
                        disc_xz_hl_dict[layer_name] = Dropout(self.dropout_rate)(
        Severity: Major
        Found in pyod/models/alad.py and 2 other locations - About 1 day to fix
        pyod/models/alad.py on lines 278..291
        pyod/models/alad.py on lines 309..322

        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 128.

        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 3 locations. Consider refactoring.
        Invalid

                for i, l_dim in enumerate(self.disc_xx_layers):
                    layer_name = 'hl_{}'.format(i)
        
                    if (self.spectral_normalization == True):
                        disc_xx_hl_dict[layer_name] = Dropout(self.dropout_rate)(
        Severity: Major
        Found in pyod/models/alad.py and 2 other locations - About 1 day to fix
        pyod/models/alad.py on lines 247..260
        pyod/models/alad.py on lines 309..322

        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 128.

        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 3 locations. Consider refactoring.
        Invalid

                for i, l_dim in enumerate(self.disc_zz_layers):
                    layer_name = 'hl_{}'.format(i)
        
                    if (self.spectral_normalization == True):
                        disc_zz_hl_dict[layer_name] = Dropout(self.dropout_rate)(
        Severity: Major
        Found in pyod/models/alad.py and 2 other locations - About 1 day to fix
        pyod/models/alad.py on lines 247..260
        pyod/models/alad.py on lines 278..291

        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 128.

        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.
        Invalid

                for i, l_dim in enumerate(self.enc_layers):
                    layer_name = 'hl_{}'.format(i)
                    enc_hl_dict[layer_name] = Dropout(self.dropout_rate)(
                        Dense(l_dim, activation=self.activation_hidden_gen)(
                            last_layer))
        Severity: Major
        Found in pyod/models/alad.py and 3 other locations - About 3 hrs to fix
        pyod/models/alad.py on lines 204..209
        pyod/models/anogan.py on lines 169..173
        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.
        Invalid

                for i, l_dim in enumerate(self.dec_layers):
                    layer_name = 'hl_{}'.format(i)
                    dec_hl_dict[layer_name] = Dropout(self.dropout_rate)(
                        Dense(l_dim, activation=self.activation_hidden_gen)(
                            last_layer))
        Severity: Major
        Found in pyod/models/alad.py and 3 other locations - About 3 hrs to fix
        pyod/models/alad.py on lines 224..229
        pyod/models/anogan.py on lines 169..173
        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

        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
            from tensorflow.keras.models import Model
        Severity: Major
        Found in pyod/models/alad.py and 1 other location - About 3 hrs to fix
        pyod/models/anogan.py on lines 22..34

        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

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

                    out_fakexx, _ = self.disc_xx({'I1': x_real, 'I2': self.dec(
                        {'I1': self.enc({'I1': x_real}, training=True)})},
        Severity: Major
        Found in pyod/models/alad.py and 1 other location - About 1 hr to fix
        pyod/models/alad.py on lines 367..368

        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 41.

        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

                        out_fakezz = self.disc_zz({'I1': z_real, 'I2': self.enc(
                            {'I1': self.dec({'I1': z_real}, training=True)})},
        Severity: Major
        Found in pyod/models/alad.py and 1 other location - About 1 hr to fix
        pyod/models/alad.py on lines 374..375

        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 41.

        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/alad.py and 4 other locations - About 1 hr to fix
        pyod/models/anogan.py on lines 356..360
        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