Utilities¶
Logger¶
-
class
genrl.utils.logger.
CSVLogger
(logdir: str)[source]¶ Bases:
object
CSV Logging class
Parameters: logdir (string) – Directory to save log at
-
class
genrl.utils.logger.
HumanOutputFormat
(logdir: str)[source]¶ Bases:
object
Output from a log file in a human readable format
Parameters: logdir (string) – Directory at which log is present -
max_key_len
(kvs: Dict[str, Any]) → None[source]¶ Finds max key length
Parameters: kvs (dict) – Entries to be logged
-
round
(num: float) → float[source]¶ Returns a rounded float value depending on self.maxlen
Parameters: num (float) – Value to round
-
-
class
genrl.utils.logger.
Logger
(logdir: str = None, formats: List[str] = ['csv'])[source]¶ Bases:
object
Logger class to log important information
Parameters: - logdir (string) – Directory to save log at
- formats (list) – Formatting of each log [‘csv’, ‘stdout’, ‘tensorboard’]
-
formats
¶ Return save format(s)
-
logdir
¶ Return log directory
Utilities¶
-
genrl.utils.utils.
cnn
(channels: Tuple = (4, 16, 32), kernel_sizes: Tuple = (8, 4), strides: Tuple = (4, 2), **kwargs) → Tuple[source]¶ - (Generates a CNN model given input dimensions, channels, kernel_sizes and
strides)
param channels: Input output channels before and after each convolution param kernel_sizes: Kernel sizes for each convolution param strides: Strides for each convolution param in_size: Input dimensions (assuming square input) type channels: tuple type kernel_sizes: tuple type strides: tuple type in_size: int returns: (Convolutional Neural Network with convolutional layers and activation layers)
-
genrl.utils.utils.
get_env_properties
(env: Union[gym.core.Env, genrl.environments.vec_env.vector_envs.VecEnv], network: Union[str, Any] = 'mlp') → Tuple[int][source]¶ Finds important properties of environment
param env: Environment that the agent is interacting with type env: Gym Environment param network: Type of network architecture, eg. “mlp”, “cnn” type network: str returns: (State space dimensions, Action space dimensions, - discreteness of action space and action limit (highest action value)
rtype: int, float, …; int, float, …; bool; int, float, …
-
genrl.utils.utils.
get_model
(type_: str, name_: str) → Union[source]¶ - Eg. “mlp” or “cnn”)
type type_: string returns: Required class. Eg. MlpActorCritic
-
genrl.utils.utils.
mlp
(sizes: Tuple, activation: str = 'relu', sac: bool = False)[source]¶ Generates an MLP model given sizes of each layer
param sizes: Sizes of hidden layers param sac: True if Soft Actor Critic is being used, else False type sizes: tuple or list type sac: bool returns: (Neural Network with fully-connected linear layers and activation layers)
-
genrl.utils.utils.
noisy_mlp
(fc_layers: List[int], noisy_layers: List[int], activation='relu')[source]¶ Noisy MLP generating helper function
Parameters: - fc_layers (
list
ofint
) – List of fully connected layers - noisy_layers (
list
ofint
) – :ist of noisy layers - activation (str) – Activation function to be used. [“tanh”, “relu”]
Returns: Noisy MLP model
- fc_layers (
Models¶
-
class
genrl.utils.models.
TabularModel
(s_dim: int, a_dim: int)[source]¶ Bases:
object
Sample-based tabular model class for deterministic, discrete environments
Parameters: - s_dim (int) – environment state dimension
- a_dim (int) – environment action dimension
-
add
(state: numpy.ndarray, action: numpy.ndarray, reward: float, next_state: numpy.ndarray) → None[source]¶ add transition to model :param state: state :param action: action :param reward: reward :param next_state: next state :type state: float array :type action: int :type reward: int :type next_state: float array
-
is_empty
() → bool[source]¶ Check if the model has been updated or not
Returns: True if model not updated yet Return type: bool