aeppl.rewriting.PreserveRVMappings#

class aeppl.rewriting.PreserveRVMappings(rv_values)[source]#

Keeps track of random variables and their respective value variables during graph rewrites in rv_values

When a random variable is replaced in a rewrite, this Feature automatically updates the rv_values mapping, so that the new variable is linked to the original value variable.

In addition this Feature provides functionality to manually update a random and/or value variable. A mapping from the transformed value variables to the the original value variables is kept in original_values.

Likewise, a measurable_conversions map is maintained, which holds information about un-valued and un-measurable variables that were replaced with measurable variables. This information can be used to revert these rewrites.

Parameters

rv_values (Dict[TensorVariable, TensorVariable]) –

Methods

PreserveRVMappings.__init__(rv_values)

type rv_values

Dict[TensorVariable, TensorVariable]

PreserveRVMappings.clone()

Create a clone that can be attached to a new FunctionGraph.

PreserveRVMappings.on_attach(fgraph)

Called by FunctionGraph.attach_feature, the method that attaches the feature to the FunctionGraph.

PreserveRVMappings.on_change_input(fgraph, ...)

Whenever a node is replaced during rewrite, we check if it had a value variable associated with it and map it to the new node.

PreserveRVMappings.on_detach(fgraph)

Called by FunctionGraph.remove_feature.

PreserveRVMappings.on_import(fgraph, node, ...)

Called whenever a node is imported into fgraph, which is just before the node is actually connected to the graph.

PreserveRVMappings.on_prune(fgraph, node, reason)

Called whenever a node is pruned (removed) from the fgraph, after it is disconnected from the graph.

PreserveRVMappings.orderings(fgraph)

Called by FunctionGraph.toposort.

PreserveRVMappings.update_rv_maps(old_rv, ...)

Update mappings for a random variable.