deeplearning4j/deeplearning4j

View on GitHub
deeplearning4j/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/utils/KerasInitilizationUtils.java

Summary

Maintainability
F
4 days
Test Coverage

Method mapWeightInitialization has a Cognitive Complexity of 104 (exceeds 5 allowed). Consider refactoring.
Open

    public static IWeightInit mapWeightInitialization(String kerasInit,
                                                      KerasLayerConfiguration conf,
                                                      Map<String, Object> initConfig,
                                                      int kerasMajorVersion)
            throws UnsupportedKerasConfigurationException, InvalidKerasConfigurationException {

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

Method mapWeightInitialization has 135 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static IWeightInit mapWeightInitialization(String kerasInit,
                                                      KerasLayerConfiguration conf,
                                                      Map<String, Object> initConfig,
                                                      int kerasMajorVersion)
            throws UnsupportedKerasConfigurationException, InvalidKerasConfigurationException {

    Method getWeightInitFromConfig has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static IWeightInit getWeightInitFromConfig(Map<String, Object> layerConfig, String initField,
                                                                             boolean enforceTrainingConfig,
                                                                             KerasLayerConfiguration conf,
                                                                             int kerasMajorVersion)
                throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException {

      Method getWeightInitFromConfig has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          public static IWeightInit getWeightInitFromConfig(Map<String, Object> layerConfig, String initField,
                                                                               boolean enforceTrainingConfig,
                                                                               KerasLayerConfiguration conf,
                                                                               int kerasMajorVersion)
                  throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException {

      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

      Method getWeightInitFromConfig has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          public static IWeightInit getWeightInitFromConfig(Map<String, Object> layerConfig, String initField,
                                                                               boolean enforceTrainingConfig,
                                                                               KerasLayerConfiguration conf,
                                                                               int kerasMajorVersion)

        Avoid too many return statements within this method.
        Open

                                return new WeightInitIdentity();

          Avoid too many return statements within this method.
          Open

                          return WeightInit.RELU.getWeightInitFunction();

            Avoid too many return statements within this method.
            Open

                                        return new WeightInitVarScalingNormalFanAvg(scale);

              Avoid too many return statements within this method.
              Open

                              return new WeightInitDistribution(new TruncatedNormalDistribution(mean, stdDev));

                Avoid too many return statements within this method.
                Open

                                        return new WeightInitIdentity(scale);

                  Avoid too many return statements within this method.
                  Open

                                      return new WeightInitDistribution(new UniformDistribution(minVal, maxVal));

                    Avoid too many return statements within this method.
                    Open

                                        return new WeightInitDistribution(new NormalDistribution(0, scale));

                      Avoid too many return statements within this method.
                      Open

                                      return WeightInit.XAVIER_UNIFORM.getWeightInitFunction();

                        Avoid too many return statements within this method.
                        Open

                                            return new WeightInitDistribution(new NormalDistribution(mean, stdDev));

                          Avoid too many return statements within this method.
                          Open

                                              return new WeightInitDistribution(new UniformDistribution(-scale, scale));

                            Avoid too many return statements within this method.
                            Open

                                                return new WeightInitDistribution(new OrthogonalDistribution(gain));

                              Avoid too many return statements within this method.
                              Open

                                              return WeightInit.ONES.getWeightInitFunction();

                                Avoid too many return statements within this method.
                                Open

                                                return WeightInit.LECUN_UNIFORM.getWeightInitFunction();

                                  Avoid too many return statements within this method.
                                  Open

                                                          return new WeightInitIdentity();

                                    Avoid too many return statements within this method.
                                    Open

                                                        return new WeightInitDistribution(new OrthogonalDistribution(scale));

                                      Avoid too many return statements within this method.
                                      Open

                                                      return new WeightInitDistribution(new ConstantDistribution(value));

                                        Avoid too many return statements within this method.
                                        Open

                                                        return WeightInit.LECUN_NORMAL.getWeightInitFunction();

                                          Avoid too many return statements within this method.
                                          Open

                                                                      return new WeightInitVarScalingUniformFanAvg(scale);

                                            Avoid too many return statements within this method.
                                            Open

                                                            return WeightInit.RELU_UNIFORM.getWeightInitFunction();

                                              Avoid too many return statements within this method.
                                              Open

                                                                      return new WeightInitIdentity(gain);

                                                Avoid too many return statements within this method.
                                                Open

                                                                return WeightInit.ZERO.getWeightInitFunction();

                                                  Avoid too many return statements within this method.
                                                  Open

                                                                  return WeightInit.XAVIER.getWeightInitFunction();

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

                                                                    if (kerasMajorVersion == 2) {
                                                                        double mean = (double) initConfig.get(conf.getLAYER_FIELD_INIT_MEAN());
                                                                        double stdDev = (double) initConfig.get(conf.getLAYER_FIELD_INIT_STDDEV());
                                                                        return new WeightInitDistribution(new NormalDistribution(mean, stdDev));
                                                                    } else {
                                                    deeplearning4j/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/utils/KerasInitilizationUtils.java on lines 125..129
                                                    deeplearning4j/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/utils/KerasInitilizationUtils.java on lines 81..85

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

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

                                                                    if (kerasMajorVersion == 2) {
                                                                        double minVal = (double) initConfig.get(conf.getLAYER_FIELD_INIT_MINVAL());
                                                                        double maxVal = (double) initConfig.get(conf.getLAYER_FIELD_INIT_MAXVAL());
                                                                        return new WeightInitDistribution(new UniformDistribution(minVal, maxVal));
                                                                    } else {
                                                    deeplearning4j/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/utils/KerasInitilizationUtils.java on lines 125..129
                                                    deeplearning4j/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/utils/KerasInitilizationUtils.java on lines 94..98

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

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

                                                                        kerasInit.equals(conf.getINIT_TRUNCATED_NORMAL_ALIAS())) {
                                                                    double mean = (double) initConfig.get(conf.getLAYER_FIELD_INIT_MEAN());
                                                                    double stdDev = (double) initConfig.get(conf.getLAYER_FIELD_INIT_STDDEV());
                                                                    return new WeightInitDistribution(new TruncatedNormalDistribution(mean, stdDev));
                                                                } else if (kerasInit.equals(conf.getINIT_IDENTITY()) ||
                                                    deeplearning4j/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/utils/KerasInitilizationUtils.java on lines 94..98
                                                    deeplearning4j/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/utils/KerasInitilizationUtils.java on lines 81..85

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

                                                    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

                                                                        try {
                                                                            gain = (double) initConfig.get(conf.getLAYER_FIELD_INIT_GAIN());
                                                                        } catch (Exception e) {
                                                                            gain = (int) initConfig.get(conf.getLAYER_FIELD_INIT_GAIN());
                                                                        }
                                                    deeplearning4j/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/utils/KerasInitilizationUtils.java on lines 151..155

                                                    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

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

                                                                    try {
                                                                        scale = (double) initConfig.get(conf.getLAYER_FIELD_INIT_SCALE());
                                                                    } catch (Exception e) {
                                                                        scale = (int) initConfig.get(conf.getLAYER_FIELD_INIT_SCALE());
                                                                    }
                                                    deeplearning4j/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/utils/KerasInitilizationUtils.java on lines 112..116

                                                    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