tfp.experimental.mcmc.ProgressBarReducer
Stay organized with collections
Save and categorize content based on your preferences.
Reducer
that displays a progress bar.
Inherits From: Reducer
tfp.experimental.mcmc.ProgressBarReducer(
num_results, progress_bar_fn=make_tqdm_progress_bar_fn()
)
Used in the notebooks
Note this is not XLA-compatible (tf.function(jit_compile=True)
).
Numpy and JAX substrates are not supported.
Example usage:
kernel = ...
current_state = ...
num_results = ...
pbar = tfp.experimental.mcmc.ProgressBarReducer(num_results)
_, final_state, kernel_results = tfp.experimental.mcmc.sample_fold(
num_steps=num_results,
current_state=current_state,
kernel=kernel,
reducer=pbar,
)
Args |
num_results
|
Integer number of results to expect (as passed to sample
chain).
|
progress_bar_fn
|
A function that takes an integer num_results and
returns an iterator that advances a progress bar. Defaults to tqdm
progress bars (make sure they are pip installed befure using.)
|
Attributes |
num_results
|
|
parameters
|
|
progress_bar_fn
|
|
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
initialize(
initial_chain_state, initial_kernel_results=None
)
Initialize progress bars.
All arguments are ignored.
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 structure of future trace results.
|
initial_kernel_results
|
A (possibly nested) structure of Tensor s
representing internal calculations made in a related TransitionKernel .
It is used to infer the structure of future trace results.
|
Returns |
state
|
empty list.
|
one_step
View source
one_step(
new_chain_state, current_reducer_state, previous_kernel_results
)
Advance progress bar by one result.
All arguments are ignored.
Args |
new_chain_state
|
A (possibly nested) structure of incoming chain state(s)
with shape and dtype compatible with those used to initialize the
TracingState .
|
current_reducer_state
|
TracingState s representing all previously traced
results.
|
previous_kernel_results
|
A (possibly nested) structure of Tensor s
representing internal calculations made in a related
TransitionKernel .
|
Returns |
new_reducer_state
|
empty list.
|
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.ProgressBarReducer\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/progress_bar_reducer.py#L49-L150) |\n\n`Reducer` that displays a progress bar.\n\nInherits From: [`Reducer`](../../../tfp/experimental/mcmc/Reducer) \n\n tfp.experimental.mcmc.ProgressBarReducer(\n num_results, progress_bar_fn=make_tqdm_progress_bar_fn()\n )\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|----------------------------------------------------------------------------------------------------------------------|\n| - [TFP Release Notes notebook (0.12.1)](https://www.tensorflow.org/probability/examples/TFP_Release_Notebook_0_12_1) |\n\nNote this is not XLA-compatible ([`tf.function(jit_compile=True)`](https://www.tensorflow.org/api_docs/python/tf/function)).\nNumpy and JAX substrates are not supported.\n\n#### Example usage:\n\n kernel = ...\n current_state = ...\n num_results = ...\n pbar = tfp.experimental.mcmc.ProgressBarReducer(num_results)\n _, final_state, kernel_results = tfp.experimental.mcmc.sample_fold(\n num_steps=num_results,\n current_state=current_state,\n kernel=kernel,\n reducer=pbar,\n )\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `num_results` | Integer number of results to expect (as passed to sample chain). |\n| `progress_bar_fn` | A function that takes an integer `num_results` and returns an iterator that advances a progress bar. Defaults to `tqdm` progress bars (make sure they are pip installed befure using.) |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|-------------------|---------------|\n| `num_results` | \u003cbr /\u003e \u003cbr /\u003e |\n| `parameters` | \u003cbr /\u003e \u003cbr /\u003e |\n| `progress_bar_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/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/progress_bar_reducer.py#L89-L110) \n\n initialize(\n initial_chain_state, initial_kernel_results=None\n )\n\nInitialize progress bars.\n\nAll arguments are ignored.\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 structure of future trace results. |\n| `initial_kernel_results` | A (possibly nested) structure of `Tensor`s representing internal calculations made in a related `TransitionKernel`. It is used to infer the structure of future trace results. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---------|-------------|\n| `state` | empty list. |\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/progress_bar_reducer.py#L112-L138) \n\n one_step(\n new_chain_state, current_reducer_state, previous_kernel_results\n )\n\nAdvance progress bar by one result.\n\nAll arguments are ignored.\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 `TracingState`. |\n| `current_reducer_state` | `TracingState`s representing all previously traced results. |\n| `previous_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| `new_reducer_state` | empty list. |\n\n\u003cbr /\u003e"]]