treeflow.model.approximation.cascading_flows module

treeflow.model.approximation.cascading_flows.build_highway_U(U_diag_inv_softplus: Tensor, U_offdiag: Tensor) Tensor
treeflow.model.approximation.cascading_flows.build_highway_L(L_offdiag: Tensor) Tensor
treeflow.model.approximation.cascading_flows.build_highway_lambd(lambd_logit: Tensor, k: int, aux_k: int | None = None)
class treeflow.model.approximation.cascading_flows.HighwayFlowParametersFromUnconstrained(U: Tensor | None = None, bias_U: Tensor | None = None, L: Tensor | None = None, bias_L: Tensor | None = None, lambd: Tensor | None = None, k: int | None = None, U_diag_inv_softplus: Tensor | None = None, U_offdiag: Tensor | None = None, L_offdiag: Tensor | None = None, lambd_logit: Tensor | None = None, name=None, defer=False)

Bases: HighwayFlowParameters, Module

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.

U: Tensor
bias_U: Tensor
L: Tensor
bias_L: Tensor
lambd: Tensor
treeflow.model.approximation.cascading_flows.get_trainable_highway_flow_parameters(k: int, batch_shape: Tensor = (), aux_k: int | None = None, prefix='', lambd_init=0.999999, dtype=tf.float64, kernel_initializer: Initializer | None = None, bias_initializer: Initializer | None = None, defer=True) HighwayFlowParameters
treeflow.model.approximation.cascading_flows.get_cascading_flows_tree_approximation(tree: ~treeflow.tree.rooted.tensorflow_rooted_tree.TensorflowRootedTree, name='tree', activation_functions=(<tfp.bijectors.Sigmoid 'sigmoid' batch_shape=[] forward_min_event_ndims=0 inverse_min_event_ndims=0 dtype_x=? dtype_y=?>, <tfp.bijectors.Identity 'identity' batch_shape=[] forward_min_event_ndims=0 inverse_min_event_ndims=0 dtype_x=? dtype_y=?>), parameter_kwargs: ~typing.Dict[str, object] | None = None, **highway_node_bijector_kwargs) Distribution