View source on GitHub |
Reducer that computes running variance.
Inherits From: CovarianceReducer, Reducer
tfp.experimental.mcmc.VarianceReducer( transform_fn=_get_sample, ddof=0, name=None ) This is a special case of CovarianceReducer with event_ndims=0, provided for convenience. See CovarianceReducer for more information.
VarianceReducer is also meant to fit into the larger streaming MCMC framework. For more generic streaming variance needs, see RunningVariance in tfp.experimental.stats.
Attributes | |
|---|---|
ddof | |
event_ndims | |
name | |
parameters | |
transform_fn | |
Methods
finalize
finalize( final_reducer_state ) Finalizes covariance calculation from the final_reducer_state.
| Args | |
|---|---|
final_reducer_state | CovarianceReducerStates that represent the final running covariance state. |
| Returns | |
|---|---|
covariance | an estimate of the covariance with identical structure to the results of self.transform_fn. |
initialize
initialize( initial_chain_state, initial_kernel_results=None ) Initializes a CovarianceReducerState using previously defined metadata.
For calculation purposes, the initial_chain_state does not count as a sample. This is a deliberate decision that ensures consistency across sampling procedures (i.e. tfp.mcmc.sample_chain follows similar semantics).
| Args | |
|---|---|
initial_chain_state | A (possibly nested) structure of Tensors or Python lists of Tensors representing the current state(s) of the Markov chain(s). It is used to infer the shape and dtype of future samples. |
initial_kernel_results | A (possibly nested) structure of Tensors representing internal calculations made in a related TransitionKernel. |
| Returns | |
|---|---|
state | CovarianceReducerState with cov_state field representing a stream of no inputs. |
one_step
one_step( new_chain_state, current_reducer_state, previous_kernel_results=None, axis=None ) Update the current_reducer_state with a new chain state.
Chunking semantics are similar to those of batching and are specified by the axis parameter. If chunking is enabled (axis is not None), all elements along the specified axis will be treated as separate samples. If a single scalar value is provided for a non-scalar sample structure, that value will be used for all elements in the structure. If not, an identical structure must be provided.
| Args | |
|---|---|
new_chain_state | A (possibly nested) structure of incoming chain state(s) with shape and dtype compatible with those used to initialize the current_reducer_state. |
current_reducer_state | CovarianceReducerStates representing the current state of the running covariance. |
previous_kernel_results | A (possibly nested) structure of Tensors representing internal calculations made in a related TransitionKernel. |
axis | If chunking is desired, this is a (possibly nested) structure of integers that specifies the axis with chunked samples. For individual samples, set this to None. By default, samples are not chunked (axis is None). |
| Returns | |
|---|---|
new_reducer_state | CovarianceReducerState with updated running statistics. Its cov_state field has an identical structure to the results of self.transform_fn. Each of the individual values in that structure subsequently mimics the structure of current_reducer_state. |
View source on GitHub