tfp.experimental.mcmc.Reducer
Stay organized with collections
Save and categorize content based on your preferences.
Base class for all MCMC Reducer
s.
This class defines the minimal requirements to implement a Markov chain Monte
Carlo (MCMC) reducer. A reducer updates a streaming computation by reducing
new samples to a summary statistic. Reducer
s can be defined to return "side
information" if desired, but they do not remember state. Hence, reducers
should be seen as objects that hold metadata (i.e. shape and dtype of
incoming samples) and all reducer method calls must be coupled with a state
object, as first returned by the initialize
method.
Methods
finalize
View source
finalize(
final_reducer_state
)
Finalizes target statistic calculation from the final_state
.
This is an identity function of the final_state
by default. Subclasses
can override it for streaming calculations whose running state is not the
same as the desired result.
Args |
final_reducer_state
|
A tuple , namedtuple or list of Tensor s
representing the final state of the reduced statistic.
|
Returns |
statistic
|
An estimate of the target statistic
|
initialize
View source
@abc.abstractmethod
initialize(
initial_chain_state, initial_inner_kernel_results
)
Initializes a reducer state corresponding to the stream of no samples.
This is an abstract method and must be overridden by subclasses.
Args |
initial_chain_state
|
Tensor or Python list of Tensor s representing
the current state(s) of the Markov chain(s). This is to be used for
any needed (shape, dtype, etc.) information, but should not be
considered part of the stream being reduced.
|
initial_inner_kernel_results
|
A (possibly nested) tuple , namedtuple or
list of Tensor s representing internal calculations made in a related
TransitionKernel . This allows for introspection of deeper layers of
TransitionKernel s that have bearing to the nature of the initial
reducer state.
|
Returns |
init_reducer_state
|
tuple , namedtuple or list of Tensor s
representing the stream of no samples.
|
one_step
View source
@abc.abstractmethod
one_step(
new_chain_state, current_reducer_state, previous_kernel_results
)
Takes one step of the Reducer
.
This is an abstract method and must be overridden by subclasses.
Args |
new_chain_state
|
Incoming chain state(s) with shape and dtype compatible
with the initial_chain_state with which the current_reducer_state
was produced by initialize .
|
current_reducer_state
|
A tuple , namedtuple or list of Tensor s
representing the current state of reduced statistics.
|
previous_kernel_results
|
A (possibly nested) tuple , namedtuple or
list of Tensor s representing internal calculations made in a related
TransitionKernel . This allows for introspection of deeper layers of
TransitionKernel s that have bearing to the nature of the updated
reducer state (i.e. updating based on a value in the kernel results of
some TransitionKernel ).
|
Returns |
new_state
|
The new reducer state after updates. This has the same type and
structure as 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.Reducer\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/reducer.py#L28-L102) |\n\nBase class for all MCMC `Reducer`s.\n\nThis class defines the minimal requirements to implement a Markov chain Monte\nCarlo (MCMC) reducer. A reducer updates a streaming computation by reducing\nnew samples to a summary statistic. `Reducer`s can be defined to return \"side\ninformation\" if desired, but they do not remember state. Hence, reducers\nshould be seen as objects that hold metadata (i.e. shape and dtype of\nincoming samples) and all reducer method calls must be coupled with a state\nobject, as first returned by the `initialize` method.\n\nMethods\n-------\n\n### `finalize`\n\n[View source](https://github.com/tensorflow/probability/blob/v0.23.0/tensorflow_probability/python/experimental/mcmc/reducer.py#L88-L102) \n\n finalize(\n final_reducer_state\n )\n\nFinalizes target statistic calculation from the `final_state`.\n\nThis is an identity function of the `final_state` by default. Subclasses\ncan override it for streaming calculations whose running state is not the\nsame as the desired result.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-----------------------|-------------------------------------------------------------------------------------------------------|\n| `final_reducer_state` | A `tuple`, `namedtuple` or `list` of `Tensor`s representing the final state of the reduced statistic. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|-------------|-------------------------------------|\n| `statistic` | An estimate of the target statistic |\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/reducer.py#L41-L61) \n\n @abc.abstractmethod\n initialize(\n initial_chain_state, initial_inner_kernel_results\n )\n\nInitializes a reducer state corresponding to the stream of no samples.\n\nThis is an abstract method and must be overridden by subclasses.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `initial_chain_state` | `Tensor` or Python `list` of `Tensor`s representing the current state(s) of the Markov chain(s). This is to be used for any needed (shape, dtype, etc.) information, but should not be considered part of the stream being reduced. |\n| `initial_inner_kernel_results` | A (possibly nested) `tuple`, `namedtuple` or `list` of `Tensor`s representing internal calculations made in a related `TransitionKernel`. This allows for introspection of deeper layers of `TransitionKernel`s that have bearing to the nature of the initial reducer state. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|----------------------|-------------------------------------------------------------------------------------|\n| `init_reducer_state` | `tuple`, `namedtuple` or `list` of `Tensor`s representing the stream of no samples. |\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/reducer.py#L63-L86) \n\n @abc.abstractmethod\n one_step(\n new_chain_state, current_reducer_state, previous_kernel_results\n )\n\nTakes one step of the `Reducer`.\n\nThis is an abstract method and must be overridden by subclasses.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `new_chain_state` | Incoming chain state(s) with shape and dtype compatible with the `initial_chain_state` with which the `current_reducer_state` was produced by `initialize`. |\n| `current_reducer_state` | A `tuple`, `namedtuple` or `list` of `Tensor`s representing the current state of reduced statistics. |\n| `previous_kernel_results` | A (possibly nested) `tuple`, `namedtuple` or `list` of `Tensor`s representing internal calculations made in a related `TransitionKernel`. This allows for introspection of deeper layers of `TransitionKernel`s that have bearing to the nature of the updated reducer state (i.e. updating based on a value in the kernel results of some `TransitionKernel`). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|-------------|-------------------------------------------------------------------------------------------------------|\n| `new_state` | The new reducer state after updates. This has the same type and structure as `current_reducer_state`. |\n\n\u003cbr /\u003e"]]