tfp.experimental.mcmc.VarianceReducer
Stay organized with collections
Save and categorize content based on your preferences.
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
.
Args |
event_ndims
|
A (possibly nested) structure of integers, or None . Defines
the number of inner-most dimensions that represent the event shape.
Specifying None returns all cross product terms (no batching)
and is the default.
|
transform_fn
|
A (possibly nested) structure of functions to evaluate the
incoming chain states on before covariance calculation. The default is
a single function that returns the chain state.
|
ddof
|
A (possibly nested) structure of integers that represent the
requested dynamic degrees of freedom. For example, use ddof=0
for population covariance and ddof=1 for sample covariance. Defaults
to the population covariance.
|
name
|
Python str name prefixed to Ops created by this function.
Default value: None (i.e., 'covariance_reducer').
|
Attributes |
ddof
|
|
event_ndims
|
|
name
|
|
parameters
|
|
transform_fn
|
|
Methods
finalize
View source
finalize(
final_reducer_state
)
Finalizes covariance calculation from the final_reducer_state
.
Args |
final_reducer_state
|
CovarianceReducerState s 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
View source
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 Tensor s or Python
list s of Tensor s 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 Tensor s
representing internal calculations made in a related TransitionKernel .
|
Returns |
state
|
CovarianceReducerState with cov_state field representing
a stream of no inputs.
|
one_step
View source
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
|
CovarianceReducerState s representing the current
state of the running covariance.
|
previous_kernel_results
|
A (possibly nested) structure of Tensor s
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 .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-11-21 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-11-21 UTC."],[],[],null,["# tfp.experimental.mcmc.VarianceReducer\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/probability/blob/v0.23.0/tensorflow_probability/python/experimental/mcmc/covariance_reducer.py#L281-L298) |\n\n`Reducer` that computes running variance.\n\nInherits From: [`CovarianceReducer`](../../../tfp/experimental/mcmc/CovarianceReducer), [`Reducer`](../../../tfp/experimental/mcmc/Reducer) \n\n tfp.experimental.mcmc.VarianceReducer(\n transform_fn=_get_sample, ddof=0, name=None\n )\n\nThis is a special case of `CovarianceReducer` with `event_ndims=0`, provided\nfor convenience. See `CovarianceReducer` for more information.\n\n`VarianceReducer` is also meant to fit into the larger streaming MCMC\nframework. For more generic streaming variance needs, see\n`RunningVariance` in [`tfp.experimental.stats`](../../../tfp/experimental/stats).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `event_ndims` | A (possibly nested) structure of integers, or `None`. Defines the number of inner-most dimensions that represent the event shape. Specifying `None` returns all cross product terms (no batching) and is the default. |\n| `transform_fn` | A (possibly nested) structure of functions to evaluate the incoming chain states on before covariance calculation. The default is a single function that returns the chain state. |\n| `ddof` | A (possibly nested) structure of integers that represent the requested dynamic degrees of freedom. For example, use `ddof=0` for population covariance and `ddof=1` for sample covariance. Defaults to the population covariance. |\n| `name` | Python `str` name prefixed to Ops created by this function. Default value: `None` (i.e., 'covariance_reducer'). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|----------------|---------------|\n| `ddof` | \u003cbr /\u003e \u003cbr /\u003e |\n| `event_ndims` | \u003cbr /\u003e \u003cbr /\u003e |\n| `name` | \u003cbr /\u003e \u003cbr /\u003e |\n| `parameters` | \u003cbr /\u003e \u003cbr /\u003e |\n| `transform_fn` | \u003cbr /\u003e \u003cbr /\u003e |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `finalize`\n\n[View source](https://github.com/tensorflow/probability/blob/v0.23.0/tensorflow_probability/python/experimental/mcmc/covariance_reducer.py#L243-L258) \n\n finalize(\n final_reducer_state\n )\n\nFinalizes covariance calculation from the `final_reducer_state`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-----------------------|------------------------------------------------------------------------------|\n| `final_reducer_state` | `CovarianceReducerState`s that represent the final running covariance state. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|--------------|-----------------------------------------------------------------------------------------------|\n| `covariance` | an estimate of the covariance with identical structure to the results of `self.transform_fn`. |\n\n\u003cbr /\u003e\n\n### `initialize`\n\n[View source](https://github.com/tensorflow/probability/blob/v0.23.0/tensorflow_probability/python/experimental/mcmc/covariance_reducer.py#L146-L183) \n\n initialize(\n initial_chain_state, initial_kernel_results=None\n )\n\nInitializes a `CovarianceReducerState` using previously defined metadata.\n\nFor calculation purposes, the `initial_chain_state` does not count as a\nsample. This is a deliberate decision that ensures consistency across\nsampling procedures (i.e. [`tfp.mcmc.sample_chain`](../../../tfp/mcmc/sample_chain) follows similar\nsemantics).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `initial_chain_state` | A (possibly nested) structure of `Tensor`s or Python `list`s of `Tensor`s representing the current state(s) of the Markov chain(s). It is used to infer the shape and dtype of future samples. |\n| `initial_kernel_results` | A (possibly nested) structure of `Tensor`s representing internal calculations made in a related `TransitionKernel`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---------|-------------------------------------------------------------------------------------|\n| `state` | `CovarianceReducerState` with `cov_state` field representing a stream of no inputs. |\n\n\u003cbr /\u003e\n\n### `one_step`\n\n[View source](https://github.com/tensorflow/probability/blob/v0.23.0/tensorflow_probability/python/experimental/mcmc/covariance_reducer.py#L185-L241) \n\n one_step(\n new_chain_state,\n current_reducer_state,\n previous_kernel_results=None,\n axis=None\n )\n\nUpdate the `current_reducer_state` with a new chain state.\n\nChunking semantics are similar to those of batching and are specified by the\n`axis` parameter. If chunking is enabled (axis is not `None`), all elements\nalong the specified `axis` will be treated as separate samples. If a\nsingle scalar value is provided for a non-scalar sample structure, that\nvalue will be used for all elements in the structure. If not, an identical\nstructure must be provided.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `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`. |\n| `current_reducer_state` | `CovarianceReducerState`s representing the current state of the running covariance. |\n| `previous_kernel_results` | A (possibly nested) structure of `Tensor`s representing internal calculations made in a related `TransitionKernel`. |\n| `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). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `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`. |\n\n\u003cbr /\u003e"]]