tensorflow/models

View on GitHub
research/efficient-hrl/agent.py

Summary

Maintainability
F
5 days
Test Coverage

File agent.py has 661 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2018 The TensorFlow Authors All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Severity: Major
Found in research/efficient-hrl/agent.py - About 1 day to fix

    UvfAgentCore has 25 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class UvfAgentCore(object):
      """Defines basic functions for UVF agent. Must be inherited with an RL agent.
    
      Used as lower-level agent.
      """
    Severity: Minor
    Found in research/efficient-hrl/agent.py - About 2 hrs to fix

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

        def __init__(self,
      Severity: Major
      Found in research/efficient-hrl/agent.py - About 1 hr to fix

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

          def __init__(self,
        Severity: Major
        Found in research/efficient-hrl/agent.py - About 1 hr to fix

          Function action_embed_net has 8 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def action_embed_net(
          Severity: Major
          Found in research/efficient-hrl/agent.py - About 1 hr to fix

            Function state_preprocess_net has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def state_preprocess_net(
            Severity: Major
            Found in research/efficient-hrl/agent.py - About 50 mins to fix

              Function action_embed_net has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              def action_embed_net(
                  actions,
                  states=None,
                  num_output_dims=2,
                  hidden_layers=(400, 300),
              Severity: Minor
              Found in research/efficient-hrl/agent.py - About 45 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 sample has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                def sample(self, states, next_states, num_samples, orig_goals, sc=0.5):
              Severity: Minor
              Found in research/efficient-hrl/agent.py - About 35 mins to fix

                Function add_noise_fn has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                  def add_noise_fn(self, action_fn, stddev=1.0, debug=False,
                Severity: Minor
                Found in research/efficient-hrl/agent.py - About 35 mins to fix

                  Function actor_loss has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                    def actor_loss(self, states, actions, rewards, discounts,
                  Severity: Minor
                  Found in research/efficient-hrl/agent.py - About 35 mins to fix

                    Function actor_loss has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                      def actor_loss(self, states, actions, rewards, discounts,
                    Severity: Minor
                    Found in research/efficient-hrl/agent.py - About 35 mins to fix

                      Function add_noise_fn has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def add_noise_fn(self, action_fn, stddev=1.0, debug=False,
                                         clip=True, global_step=None):
                          """Returns the action_fn with additive Gaussian noise.
                      
                          Args:
                      Severity: Minor
                      Found in research/efficient-hrl/agent.py - About 35 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

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

                          if images:  # Zero-out x-y
                            states *= tf.constant([0.] * 2 + [1.] * (states.shape[-1] - 2), dtype=states.dtype)
                      Severity: Major
                      Found in research/efficient-hrl/agent.py and 1 other location - About 2 hrs to fix
                      research/efficient-hrl/agent.py on lines 646..647

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

                      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 images:  # Zero-out x-y
                              states *= tf.constant([0.] * 2 + [1.] * (states.shape[-1] - 2), dtype=states.dtype)
                      Severity: Major
                      Found in research/efficient-hrl/agent.py and 1 other location - About 2 hrs to fix
                      research/efficient-hrl/agent.py on lines 601..602

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

                      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

                          with slim.arg_scope([slim.fully_connected],
                                              weights_regularizer=None,
                                              weights_initializer=tf.random_uniform_initializer(
                                                  minval=-0.003, maxval=0.003)):
                            embed = slim.fully_connected(embed, num_output_dims,
                      Severity: Major
                      Found in research/efficient-hrl/agent.py and 1 other location - About 2 hrs to fix
                      research/efficient-hrl/agents/ddpg_networks.py on lines 87..91

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

                      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 zero_time:
                              states *= tf.constant([1.] * (states.shape[-1] - 1) + [0.], dtype=states.dtype)
                      Severity: Major
                      Found in research/efficient-hrl/agent.py and 1 other location - About 2 hrs to fix
                      research/efficient-hrl/agent.py on lines 603..604

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

                      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 zero_time:
                            states *= tf.constant([1.] * (states.shape[-1] - 1) + [0.], dtype=states.dtype)
                      Severity: Major
                      Found in research/efficient-hrl/agent.py and 1 other location - About 2 hrs to fix
                      research/efficient-hrl/agent.py on lines 648..649

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

                      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

                      @gin.configurable
                      class UvfAgent(UvfAgentCore, ddpg_agent.TD3Agent):
                        """A DDPG agent with UVF.
                        """
                        BASE_AGENT_CLASS = ddpg_agent.TD3Agent
                      Severity: Major
                      Found in research/efficient-hrl/agent.py and 1 other location - About 1 hr to fix
                      research/efficient-hrl/agent.py on lines 569..577

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

                      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

                      @gin.configurable
                      class MetaAgent(MetaAgentCore, ddpg_agent.TD3Agent):
                        """A DDPG meta-agent.
                        """
                        BASE_AGENT_CLASS = ddpg_agent.TD3Agent
                      Severity: Major
                      Found in research/efficient-hrl/agent.py and 1 other location - About 1 hr to fix
                      research/efficient-hrl/agent.py on lines 558..566

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

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

                        with slim.arg_scope(
                            [slim.fully_connected],
                            activation_fn=activation_fn,
                            normalizer_fn=normalizer_fn,
                            weights_initializer=slim.variance_scaling_initializer(
                      Severity: Major
                      Found in research/efficient-hrl/agent.py and 2 other locations - About 1 hr to fix
                      research/efficient-hrl/agent.py on lines 637..642
                      research/efficient-hrl/agents/ddpg_networks.py on lines 124..129

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

                        with slim.arg_scope(
                            [slim.fully_connected],
                            activation_fn=activation_fn,
                            normalizer_fn=normalizer_fn,
                            weights_initializer=slim.variance_scaling_initializer(
                      Severity: Major
                      Found in research/efficient-hrl/agent.py and 2 other locations - About 1 hr to fix
                      research/efficient-hrl/agent.py on lines 591..596
                      research/efficient-hrl/agents/ddpg_networks.py on lines 124..129

                      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

                        def action(self, state, context=None):
                          """Returns the next action for the state.
                      
                          Args:
                            state: A [num_state_dims] tensor representing a state.
                      Severity: Minor
                      Found in research/efficient-hrl/agent.py and 1 other location - About 55 mins to fix
                      research/efficient-hrl/agent.py on lines 123..133

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

                      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

                        def actions(self, state, context=None):
                          """Returns the next action for the state.
                      
                          Args:
                            state: A [-1, num_state_dims] tensor representing a state.
                      Severity: Minor
                      Found in research/efficient-hrl/agent.py and 1 other location - About 55 mins to fix
                      research/efficient-hrl/agent.py on lines 111..121

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

                      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

                          batch_dims = [tf.shape(states)[0], tf.shape(states)[1]]
                      Severity: Minor
                      Found in research/efficient-hrl/agent.py and 1 other location - About 30 mins to fix
                      research/deeplab/model.py on lines 581..582

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

                      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