Showing 29 of 61 total issues
File reward_function.py
has 320 lines of code (exceeds 250 allowed). Consider refactoring. Open
"""Module containing reward functions to be used for IRL."""
from abc import ABC, abstractmethod
from copy import copy
from typing import NamedTuple, Union
Function train
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
def train(self, no_irl_iterations: int,
no_rl_episodes_per_irl_iteration: int,
no_irl_episodes_per_irl_iteration: int
) -> Tuple[BaseRewardFunction, BaseRLAlgorithm]:
"""Train the apprenticeship learning IRL algorithm.
- Read upRead up
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 collect_trajs
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def collect_trajs(env: gym.Env,
agent: BaseRLAlgorithm,
no_trajectories: int,
max_steps_per_episode: Union[int, None] = None,
store_to: Union[str, None] = None,
- Read upRead up
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 preprocess_config
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def preprocess_config(config_for: object, domains: dict, config: dict) -> dict:
""" Pre-processes a config dictionary.
This is based on the values specified for each IRL algorithm in
IRL_CONFIG_DOMAINS. The following steps are performed:
- Read upRead up
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
File feature_wrapper.py
has 255 lines of code (exceeds 250 allowed). Consider refactoring. Open
"""Module for feature wrappers providing features for different environments."""
from abc import abstractmethod
import functools
from typing import Union, Tuple
Function _domain_to_features
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def _domain_to_features(
self, domain_batch: Union[State, StateAction, StateActionState]
) -> np.ndarray:
"""Convert elements of the domain to features.
- Read upRead up
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 occupancy_measure
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def occupancy_measure(self,
policy,
initial_state_dist,
t_max=None,
threshold=1e-6):
- Read upRead up
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 get_transition_array
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def get_transition_array(self):
env = unwrap_env(self.env, DiscreteEnv)
# adding +1 to account for absorbing state
# (reached whenever game ended)
- Read upRead up
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 step
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def step(self, action):
"""Do a step with the provided action."""
state = np.copy(self.current_state)
assert len(state) == self.num_rewards * 2
assert action < self.num_rewards
- Read upRead up
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 expected_svf
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def expected_svf(self, policy: np.ndarray) -> np.ndarray:
"""Calculate the expected state visitation frequency for the trajectories
under the given policy. Returns vector of state visitation frequencies.
Uses self.transition_matrix.
- Read upRead up
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 __init__
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(self, env_id: str, expert_trajs_path: str,
Function collect_trajs
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def collect_trajs(env: gym.Env,
Avoid deeply nested control flow statements. Open
if reward_wrapper is None:
rewards[s, a] = REWARD_MOVE
if state[num_rewards + a] != 0:
rews_where = self.maze_env.rews_where
rewards[s, a] += float(
Function make_wrapped_env
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def make_wrapped_env(env_id: str,
with_feature_wrapper: bool = False,
reward_function_factory: Callable = None,
with_model_wrapper: bool = False):
"""Make an environment, potentially wrapped in FeatureWrapper, RewardWrapper,
- Read upRead up
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 get_reward_input_for
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def get_reward_input_for(self, state: Union[np.ndarray, int, float],
action: Union[np.ndarray, int, float],
next_state: Union[np.ndarray, int, float]
) -> Union[State, StateAction, StateActionState]:
"""
- Read upRead up
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 features
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def features(self, current_state: np.ndarray, action: int,
next_state: None) -> np.ndarray:
"""Return features to be saved in step method's info dictionary.
There are four feature variables: expected walking distance,
- Read upRead up
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
Avoid deeply nested control flow statements. Open
if state[num_rewards + a] == 0:
# if reward is already collected at this field:
rew_value = 0
else:
rews_where = self.maze_env.rews_where
Avoid deeply nested control flow statements. Open
if reward_wrapper is None:
rewards[s, a] = 0
else:
rewards[s, a] = wrapped_reward
continue
Function __init__
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(self, env: gym.Env, expert_trajs: List[Dict[str, list]],
Function __init__
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(self, env: gym.Env, expert_trajs: List[Dict[str, list]],