stable_learning_control.common.helpers
Contains several helper functions that are used throughout the SLC package.
Functions
|
Similar to |
|
Converts input into a tuple. |
|
Flatten a list with any nested iterable. |
|
Removes non-unique items from a list. |
|
Combines multiple tuples/ints/floats into one tuple. |
|
Updates a dictionary with values supplied in another |
|
Convert a value or values to a string which could go in a filepath. |
|
Check if list contains only strings. |
|
Recursive function that checks whether a input |
|
Returns the environment id of a given environment. |
|
Get the environment class. |
|
Replace environment objects (i.e. gym.Env) with their id and class path if they |
|
Converts a string from camel/pascal case to snake case. |
|
Add whitespace line to error message to make it more readable. |
|
Flattens a nested dictionary. |
|
Transform the config to a format that looks better on Weights & Biases. |
|
Transform the config to a format that looks better on TensorBoard. |
Module Contents
- stable_learning_control.common.helpers.atleast_2d(array, axis=1)[source]
Similar to
numpy.atleast_2d()
but with an additionalaxis
argument which can be used to specify where the extra dimension should be-added.- Parameters:
array (numpy.ndarray) – [description]
axis (int, optional) – Position in the expanded axes where the new axis (or axes) is placed if the dimension is smaller than 2. Defaults to
1
.
- Returns:
The 2D numpy array.
- Return type:
- stable_learning_control.common.helpers.convert_to_tuple(input_var)[source]
Converts input into a tuple.
- stable_learning_control.common.helpers.flatten(items)[source]
Flatten a list with any nested iterable.
- stable_learning_control.common.helpers.get_unique_list(input_list, trim=True)[source]
Removes non-unique items from a list.
- stable_learning_control.common.helpers.combine_shapes(*args, remove_none=False)[source]
Combines multiple tuples/ints/floats into one tuple.
- stable_learning_control.common.helpers.strict_dict_update(input_dict, update_obj)[source]
Updates a dictionary with values supplied in another
dict
or pythonobject
. This function performs a strict update, meaning it does not add new keys to the original dictionary.Additionally, if a Python object is supplied, it will be applied to all keys in the dictionary.
- stable_learning_control.common.helpers.valid_str(v)[source]
Convert a value or values to a string which could go in a filepath.
Note
Partly based on this gist.
- Parameters:
v (list) – List with values.
- stable_learning_control.common.helpers.all_bools(vals)[source]
Check if list contains only strings.
- stable_learning_control.common.helpers.is_scalar(obj)[source]
Recursive function that checks whether a input
- Parameters:
obj (object) – Object for which you want to check if it is a scalar.
- Returns:
Boolean specifying whether the object is a scalar.
- Return type:
boole
- stable_learning_control.common.helpers.get_env_id(env)[source]
Returns the environment id of a given environment.
- Parameters:
env (
gym.Env
) – The environment.- Returns:
The environment id.
- Return type:
- stable_learning_control.common.helpers.get_env_class(env)[source]
Get the environment class.
- Parameters:
env (
gym.Env
) – The environment.- Returns:
The environment class.
- Return type:
- stable_learning_control.common.helpers.parse_config_env_key(config)[source]
Replace environment objects (i.e. gym.Env) with their id and class path if they are present in the config. Also removes the ‘env_fn’ from the config.
- stable_learning_control.common.helpers.convert_to_snake_case(input_str)[source]
Converts a string from camel/pascal case to snake case.
- stable_learning_control.common.helpers.friendly_err(err_msg, prepend=True, append=True)[source]
Add whitespace line to error message to make it more readable.
- Parameters:
- Returns:
Error message with extra whitespace line.
- Return type:
- stable_learning_control.common.helpers.flatten_dict(d, parent_key='', sep='.')[source]
Flattens a nested dictionary.