romcomma.gpf.base.Variance§
- class Variance(value, name='Variance', cholesky_diagonal_lower_bound=0.001)[source]§
Bases:
Module
A non-diagonal Variance Matrix.
- Parameters:
name (str) –
cholesky_diagonal_lower_bound (float) –
- __init__(value, name='Variance', cholesky_diagonal_lower_bound=0.001)[source]§
Construct a non-diagonal covariance matrix. Mutable only through it’s properties cholesky_diagonal and cholesky_lower_triangle.
- Parameters:
value – A symmetric, positive definite matrix, expressed in tensorflow or numpy.
cholesky_diagonal_lower_bound (float) – Lower bound on the diagonal of the Cholesky decomposition.
name (str) –
Methods
__init__
(value[, name, ...])Construct a non-diagonal covariance matrix.
The cartesian product variance[:L, :L] * eye[:N, :N], transposed.
with_name_scope
(method)Decorator to automatically enter the module name scope.
Attributes
CHOLESKY_DIAGONAL_LOWER_BOUND
The (lower triangular) Cholesky decomposition of the covariance matrix.
Returns the name of this module as passed or determined in the ctor.
Returns a tf.name_scope instance for this class.
Sequence of non-trainable variables owned by this module and its submodules.
parameters
Returns (L,L), which is the shape of self.value and self.cholesky.
Sequence of all sub-modules.
trainable_parameters
Sequence of trainable variables owned by this module and its submodules.
The covariance matrix, shape (L,L).
The covariance matrix, shape (L,1,L,1) ready to broadcast.
Sequence of variables owned by this module and its submodules.
- property shape: Tuple[int, int]§
Returns (L,L), which is the shape of self.value and self.cholesky.
- property value§
The covariance matrix, shape (L,L).
- property value_to_broadcast§
The covariance matrix, shape (L,1,L,1) ready to broadcast.
- value_times_eye(N)[source]§
The cartesian product variance[:L, :L] * eye[:N, :N], transposed.
- Parameters:
N (int) – The dimension of the identity matrix we are multiplying by.
- Return type:
Returns: An [:L, :N, :L, :N] Tensor, after transposition.
- property name§
Returns the name of this module as passed or determined in the ctor.
NOTE: This is not the same as the self.name_scope.name which includes parent module names.
- property name_scope§
Returns a tf.name_scope instance for this class.
- property non_trainable_variables§
Sequence of non-trainable variables owned by this module and its submodules.
Note: this method uses reflection to find variables on the current instance and submodules. For performance reasons you may wish to cache the result of calling this method if you don’t expect the return value to change.
- Returns:
A sequence of variables for the current module (sorted by attribute name) followed by variables from all submodules recursively (breadth first).
- property submodules§
Sequence of all sub-modules.
Submodules are modules which are properties of this module, or found as properties of modules which are properties of this module (and so on).
>>> a = tf.Module() >>> b = tf.Module() >>> c = tf.Module() >>> a.b = b >>> b.c = c >>> list(a.submodules) == [b, c] True >>> list(b.submodules) == [c] True >>> list(c.submodules) == [] True
- Returns:
A sequence of all submodules.
- property trainable_variables§
Sequence of trainable variables owned by this module and its submodules.
Note: this method uses reflection to find variables on the current instance and submodules. For performance reasons you may wish to cache the result of calling this method if you don’t expect the return value to change.
- Returns:
A sequence of variables for the current module (sorted by attribute name) followed by variables from all submodules recursively (breadth first).
- property variables§
Sequence of variables owned by this module and its submodules.
Note: this method uses reflection to find variables on the current instance and submodules. For performance reasons you may wish to cache the result of calling this method if you don’t expect the return value to change.
- Returns:
A sequence of variables for the current module (sorted by attribute name) followed by variables from all submodules recursively (breadth first).
- classmethod with_name_scope(method)§
Decorator to automatically enter the module name scope.
>>> class MyModule(tf.Module): ... @tf.Module.with_name_scope ... def __call__(self, x): ... if not hasattr(self, 'w'): ... self.w = tf.Variable(tf.random.normal([x.shape[1], 3])) ... return tf.matmul(x, self.w)
Using the above module would produce `tf.Variable`s and `tf.Tensor`s whose names included the module name:
>>> mod = MyModule() >>> mod(tf.ones([1, 2])) <tf.Tensor: shape=(1, 3), dtype=float32, numpy=..., dtype=float32)> >>> mod.w <tf.Variable 'my_module/Variable:0' shape=(2, 3) dtype=float32, numpy=..., dtype=float32)>
- Parameters:
method – The method to wrap.
- Returns:
The original method wrapped such that it enters the module’s name scope.