osl_dynamics.inference.initializers#

Initializers for TensorFlow layers.

Module Contents#

Classes#

WeightInitializer

Initialize weights to given value.

RandomWeightInitializer

Initialize weights to given value with random noise added.

IdentityCholeskyInitializer

Initialize weights to a flattened cholesky factor of identity

NormalIdentityCholeskyInitializer

Initialize weights to a flattened cholesky factor of identity

NormalCorrelationCholeskyInitializer

Initialize weights to a flattened cholesky factor of correlation

NormalDiagonalInitializer

Initializer for diagonal matrices with a normal error added.

CopyTensorInitializer

Initialize weights to another Tensor's value.

Functions#

reinitialize_layer_weights(layer)

Re-initializes the weights in a particular layer.

reinitialize_model_weights(model[, keep])

Re-initialize the weights in a model.

Attributes#

tfb

osl_dynamics.inference.initializers.tfb[source]#
class osl_dynamics.inference.initializers.WeightInitializer(initial_value)[source]#

Bases: tensorflow.keras.initializers.Initializer

Initialize weights to given value.

Parameters:

initial_value (np.ndarray) – Value to initialise weights to. Note, the shape is not checked.

__call__(shape, dtype=None)[source]#
class osl_dynamics.inference.initializers.RandomWeightInitializer(initial_value, std)[source]#

Bases: tensorflow.keras.initializers.Initializer

Initialize weights to given value with random noise added.

Parameters:
  • initial_value (np.ndarray) – Value to initialise weights to. Note, the shape is not checked.

  • std (float) – Standard deviation of the noise to add.

__call__(shape, dtype=None)[source]#
class osl_dynamics.inference.initializers.IdentityCholeskyInitializer[source]#

Bases: tensorflow.keras.initializers.Initializer

Initialize weights to a flattened cholesky factor of identity matrices.

__call__(shape, dtype=None)[source]#
class osl_dynamics.inference.initializers.NormalIdentityCholeskyInitializer(std)[source]#

Bases: tensorflow.keras.initializers.Initializer

Initialize weights to a flattened cholesky factor of identity matrices with a normal error added to the diagonal.

Parameters:

std (float) – Standard deviation of the error to add.

__call__(shape, dtype=None)[source]#
class osl_dynamics.inference.initializers.NormalCorrelationCholeskyInitializer(std)[source]#

Bases: tensorflow.keras.initializers.Initializer

Initialize weights to a flattened cholesky factor of correlation matrices with a normal error added to the flattened cholesky factor.

Parameters:
  • mean (float) – Mean of the error to add.

  • std (float) – Standard deviation of the error to add.

__call__(shape, dtype=None)[source]#
class osl_dynamics.inference.initializers.NormalDiagonalInitializer(std)[source]#

Bases: tensorflow.keras.initializers.Initializer

Initializer for diagonal matrices with a normal error added.

Parameters:

std (float) – Standard deviation of the error to add.

__call__(shape, dtype=None)[source]#
class osl_dynamics.inference.initializers.CopyTensorInitializer(tensor)[source]#

Bases: tensorflow.keras.initializers.Initializer

Initialize weights to another Tensor’s value.

Parameters:

tensor (tf.Tensor) – Tensor to copy.

__call__(shape, dtype=None)[source]#
osl_dynamics.inference.initializers.reinitialize_layer_weights(layer)[source]#

Re-initializes the weights in a particular layer.

Parameters:

layer (tf.keras.layers.Layer) – Layer to initialize weights for.

Note

This function relies on each layer having an attribute for the initializer. Standard TensorFlow layers have this. You must specify a self.*_initializer attribute in any custom layer, otherwise this function will break.

osl_dynamics.inference.initializers.reinitialize_model_weights(model, keep=None)[source]#

Re-initialize the weights in a model.

Parameters:
  • model (tf.keras.Model) – Model to re-initialize weights for.

  • keep (list, optional) – List of str containing names for layers to not reinitialize.