tfp.experimental.mcmc.PotentialScaleReductionReducer
Stay organized with collections
Save and categorize content based on your preferences.
Reducer
that computes a running R-hat diagnostic statistic.
Inherits From: Reducer
tfp.experimental.mcmc.PotentialScaleReductionReducer(
independent_chain_ndims=1, name=None
)
PotentialScaleReductionReducer
assumes that all provided chain states
include samples from multiple independent Markov chains, and that all of
these chains are to be included in the same calculation.
PotentialScaleReductionReducer
also assumes that incoming samples have
shape [Ci1, Ci2,...,CiD] + A
. Dimensions 0
through D - 1
index the
Ci1 x ... x CiD
independent chains to be tested for convergence to the
same target. The remaining dimensions, A
, represent the event shape and
hence, can have any shape (even empty, which implies scalar samples). The
number of independent chain dimensions is defined by the
independent_chain_ndims
parameter at initialization.
As with all reducers, PotentialScaleReductionReducer does not hold state
information; rather, it stores supplied metadata. Intermediate calculations
are held in a state object, which is returned via initialize
and one_step
method calls.
PotentialScaleReductionReducer
is meant to fit into the larger Streaming
MCMC framework. RunningPotentialScaleReduction
in tfp.experimental.stats
is better suited for more generic streaming R-hat needs. More precise
algorithmic details can also be found by referencing
RunningPotentialScaleReduction
.
Args |
independent_chain_ndims
|
Integer type Tensor with value >= 1 giving
the number of dimensions, from dim = 1 to dim = D , holding
independent chain results to be tested for convergence.
|
name
|
Python str name prefixed to Ops created by this function.
Default value: None (i.e., 'potential_scale_reduction_reducer').
|
Raises |
ValueError
|
if independent_chain_ndims < 1 . This results in undefined
intermediate variance calculations.
|
Attributes |
independent_chain_ndims
|
|
name
|
|
parameters
|
|
Methods
finalize
View source
finalize(
final_reducer_state
)
Finalizes R-hat calculation from the final_reducer_state
.
Args |
final_reducer_state
|
PotentialScaleReductionReducerState that
represents the final state of the running R-hat statistic.
|
Returns |
rhat
|
an estimate of the R-hat.
|
initialize
View source
initialize(
initial_chain_state, initial_kernel_results=None
)
Initializes an empty PotentialScaleReductionReducerState
.
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 .
For streaming R-hat, this argument has no influence on the
computation; hence, it is None by default. However, it's
still accepted to fit the Reducer base class.
|
Returns |
state
|
PotentialScaleReductionReducerState with rhat_state field
representing a stream of no inputs.
|
one_step
View source
one_step(
new_chain_state, current_reducer_state, previous_kernel_results=None
)
Update the current_reducer_state
with a new chain state.
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
|
PotentialScaleReductionReducerState representing
the current state of the running R-hat statistic.
|
previous_kernel_results
|
A (possibly nested) structure of Tensor s
representing internal calculations made in a related
TransitionKernel . For streaming R-hat, this argument has no
influence on computation; hence, it is None by default. However, it's
still accepted to fit the Reducer base class.
|
Returns |
new_reducer_state
|
PotentialScaleReductionReducerState with updated
running statistics.
|
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.PotentialScaleReductionReducer\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/potential_scale_reduction_reducer.py#L37-L186) |\n\n`Reducer` that computes a running R-hat diagnostic statistic.\n\nInherits From: [`Reducer`](../../../tfp/experimental/mcmc/Reducer) \n\n tfp.experimental.mcmc.PotentialScaleReductionReducer(\n independent_chain_ndims=1, name=None\n )\n\n`PotentialScaleReductionReducer` assumes that all provided chain states\ninclude samples from multiple independent Markov chains, and that all of\nthese chains are to be included in the same calculation.\n`PotentialScaleReductionReducer` also assumes that incoming samples have\nshape `[Ci1, Ci2,...,CiD] + A`. Dimensions `0` through `D - 1` index the\n`Ci1 x ... x CiD` independent chains to be tested for convergence to the\nsame target. The remaining dimensions, `A`, represent the event shape and\nhence, can have any shape (even empty, which implies scalar samples). The\nnumber of independent chain dimensions is defined by the\n`independent_chain_ndims` parameter at initialization.\n\nAs with all reducers, PotentialScaleReductionReducer does not hold state\ninformation; rather, it stores supplied metadata. Intermediate calculations\nare held in a state object, which is returned via `initialize` and `one_step`\nmethod calls.\n\n`PotentialScaleReductionReducer` is meant to fit into the larger Streaming\nMCMC framework. `RunningPotentialScaleReduction` in [`tfp.experimental.stats`](../../../tfp/experimental/stats)\nis better suited for more generic streaming R-hat needs. More precise\nalgorithmic details can also be found by referencing\n`RunningPotentialScaleReduction`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `independent_chain_ndims` | Integer type `Tensor` with value `\u003e= 1` giving the number of dimensions, from `dim = 1` to `dim = D`, holding independent chain results to be tested for convergence. |\n| `name` | Python `str` name prefixed to Ops created by this function. Default value: `None` (i.e., 'potential_scale_reduction_reducer'). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|-------------------------------------------------------------------------------------------------|\n| `ValueError` | if `independent_chain_ndims \u003c 1`. This results in undefined intermediate variance calculations. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|---------------------------|---------------|\n| `independent_chain_ndims` | \u003cbr /\u003e \u003cbr /\u003e |\n| `name` | \u003cbr /\u003e \u003cbr /\u003e |\n| `parameters` | \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/potential_scale_reduction_reducer.py#L161-L174) \n\n finalize(\n final_reducer_state\n )\n\nFinalizes R-hat 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` | `PotentialScaleReductionReducerState` that represents the final state of the running R-hat statistic. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|--------|---------------------------|\n| `rhat` | an estimate of the R-hat. |\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/potential_scale_reduction_reducer.py#L87-L127) \n\n initialize(\n initial_chain_state, initial_kernel_results=None\n )\n\nInitializes an empty `PotentialScaleReductionReducerState`.\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`. For streaming R-hat, this argument has no influence on the computation; hence, it is `None` by default. However, it's still accepted to fit the `Reducer` base class. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---------|---------------------------------------------------------------------------------------------------|\n| `state` | `PotentialScaleReductionReducerState` with `rhat_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/potential_scale_reduction_reducer.py#L129-L159) \n\n one_step(\n new_chain_state, current_reducer_state, previous_kernel_results=None\n )\n\nUpdate the `current_reducer_state` with a new chain state.\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` | `PotentialScaleReductionReducerState` representing the current state of the running R-hat statistic. |\n| `previous_kernel_results` | A (possibly nested) structure of `Tensor`s representing internal calculations made in a related `TransitionKernel`. For streaming R-hat, this argument has no influence on computation; hence, it is `None` by default. However, it's still accepted to fit the `Reducer` base class. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---------------------|------------------------------------------------------------------------|\n| `new_reducer_state` | `PotentialScaleReductionReducerState` with updated running statistics. |\n\n\u003cbr /\u003e"]]