stable_learning_control.algos.tf2.common.helpers

Several TensorFlow helper functions.

Module Contents

Functions

set_device([device_type])

Sets the computational device given a device type.

mlp(sizes, activation[, output_activation, name])

Create a multi-layered perceptron using TensorFlow.

count_vars(module)

Returns the total number of parameters of a TensorFlow module.

rescale(data, min_bound, max_bound)

Rescale normalized data (i.e. between -1 and 1) to a desired range.

full_model_summary(model)

Prints a full summary of all the layers of a TensorFlow model.

stable_learning_control.algos.tf2.common.helpers.set_device(device_type='cpu')[source]

Sets the computational device given a device type.

Parameters:

device_type (str) – The device type (options: cpu, gpu, gpu:0, gpu:1, etc.). Defaults to cpu.

Returns:

The type of device that is used.

Return type:

str

stable_learning_control.algos.tf2.common.helpers.mlp(sizes, activation, output_activation=None, name='')[source]

Create a multi-layered perceptron using TensorFlow.

Parameters:
  • sizes (list) – The size of each of the layers.

  • activation (union[tf.keras.activations, str]) – The activation function used for the hidden layers.

  • output_activation (union[tf.keras.activations, str], optional) – The activation function used for the output layers. Defaults to None.

  • name (str, optional) – A nameprefix that is added before the layer name. Defaults to an empty string.

Returns:

The multi-layered perceptron.

Return type:

tf.keras.Sequential

stable_learning_control.algos.tf2.common.helpers.count_vars(module)[source]

Returns the total number of parameters of a TensorFlow module.

Parameters:

module (Union[tf.keras.Model, tf.module]) – The TensorFlow model.

Returns:

The total number of parameters inside the module.

Return type:

numpy.int64

stable_learning_control.algos.tf2.common.helpers.rescale(data, min_bound, max_bound)[source]

Rescale normalized data (i.e. between -1 and 1) to a desired range.

Parameters:
  • data (Union[numpy.ndarray, list]) – Normalized input data.

  • min_bound (Union[numpy.ndarray, list]) – Array containing the minimum value of the desired range.

  • max_bound (Union[numpy.ndarray, list]) – Array containing the maximum value of the desired range.

Returns:

Array which has it values scaled between the min and max

boundaries.

Return type:

numpy.ndarray

stable_learning_control.algos.tf2.common.helpers.full_model_summary(model)[source]

Prints a full summary of all the layers of a TensorFlow model.

Parameters:

layer (tf.keras.layers) – The model to print the full summary of.