stable_learning_control.algos.common.helpers

Functions that are used in multiple Pytorch and TensorFlow algorithms.

Module Contents

Functions

heuristic_target_entropy(action_space)

Returns a heuristic target entropy for a given action space using the method

get_activation_function(activation_fn_name[, backend])

Get a given torch activation function.

discount_cumsum(x, discount)

Calculate the discounted cumsum.

Attributes

tf

tensorflow

stable_learning_control.algos.common.helpers.tf[source]
stable_learning_control.algos.common.helpers.tensorflow[source]
stable_learning_control.algos.common.helpers.heuristic_target_entropy(action_space)[source]

Returns a heuristic target entropy for a given action space using the method explained in Haarnoja et al. 2019.

Parameters:

action_space (:obj:`gym.spaces`) – The action space.

Raises:

NotImplementedError – If no heuristic target entropy has yet been implemented for the given action space.

Returns:

The target entropy.

Return type:

numpy.int64

stable_learning_control.algos.common.helpers.get_activation_function(activation_fn_name, backend='torch')[source]

Get a given torch activation function.

Parameters:
  • activation_fn_name (str) – The name of the activation function you want to retrieve.

  • backend (str) – The machine learning backend you want to use. Options are torch or tf2. By default torch.

Raises:

ValueError – Thrown if the activation function does not exist within the backend.

Returns:

The torch activation function.

Return type:

torch.nn.modules.activation

stable_learning_control.algos.common.helpers.discount_cumsum(x, discount)[source]

Calculate the discounted cumsum.

See also

Magic from rllab for computing discounted cumulative sums of vectors.

Input:

vector x: [x0, x1, x2]

Output:

[x0 + discount * x1 + discount^2 * x2, x1 + discount * x2, x2]