<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/probability/blob/v0.25.0/tensorflow_probability/python/experimental/mcmc/progress_bar_reducer.py#L49-L150) |

`Reducer` that displays a progress bar.

Inherits From: [`Reducer`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/mcmc/Reducer)

    tfp.experimental.mcmc.ProgressBarReducer(
        num_results, progress_bar_fn=make_tqdm_progress_bar_fn()
    )

### Used in the notebooks

| Used in the tutorials |
|---|
| - [TFP Release Notes notebook (0.12.1)](https://www.tensorflow.org/probability/examples/TFP_Release_Notebook_0_12_1) |

Note this is not XLA-compatible ([`tf.function(jit_compile=True)`](https://www.tensorflow.org/api_docs/python/tf/function)).
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,
    )

<br />

<br />

<br />

| ## 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.) |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `num_results` | <br /> <br /> |
| `parameters` | <br /> <br /> |
| `progress_bar_fn` | <br /> <br /> |

<br />

## Methods

### `finalize`

[View source](https://github.com/tensorflow/probability/blob/v0.25.0/tensorflow_probability/python/experimental/mcmc/reducer.py#L88-L102)

    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.

<br />

<br />

<br />

| Args ||
|---|---|
| `final_reducer_state` | A `tuple`, `namedtuple` or `list` of `Tensor`s representing the final state of the reduced statistic. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `statistic` | An estimate of the target statistic |

<br />

### `initialize`

[View source](https://github.com/tensorflow/probability/blob/v0.25.0/tensorflow_probability/python/experimental/mcmc/progress_bar_reducer.py#L89-L110)

    initialize(
        initial_chain_state, initial_kernel_results=None
    )

Initialize progress bars.

All arguments are ignored.

<br />

<br />

<br />

| 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. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `state` | empty list. |

<br />

### `one_step`

[View source](https://github.com/tensorflow/probability/blob/v0.25.0/tensorflow_probability/python/experimental/mcmc/progress_bar_reducer.py#L112-L138)

    one_step(
        new_chain_state, current_reducer_state, previous_kernel_results
    )

Advance progress bar by one result.

All arguments are ignored.

<br />

<br />

<br />

| 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`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `new_reducer_state` | empty list. |

<br />