<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/sequential_monte_carlo_kernel.py#L144-L373) |

Sequential Monte Carlo transition kernel.

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

    tfp.experimental.mcmc.SequentialMonteCarlo(
        propose_and_update_log_weights_fn,
        resample_fn=https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/mcmc/resample_systematic,
        resample_criterion_fn=https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/mcmc/ess_below_threshold,
        unbiased_gradients=True,
        particles_dim=0,
        name=None
    )

Sequential Monte Carlo maintains a population of weighted particles
representing samples from a sequence of target distributions. It is
*not* a calibrated MCMC kernel: the transitions step through a sequence of
target distributions, rather than trying to maintain a stationary
distribution.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `propose_and_update_log_weights_fn` | Python `callable` with signature `new_weighted_particles = propose_and_update_log_weights_fn(step, weighted_particles, seed=None)`. Its input is a [`tfp.experimental.mcmc.WeightedParticles`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/mcmc/WeightedParticles) structure representing weighted samples (with normalized weights) from the `step`th target distribution, and it returns another such structure representing unnormalized weighted samples from the next (`step + 1`th) target distribution. This will typically include particles sampled from a proposal distribution `q(x[step + 1] | x[step])`, and weights that account for some or all of: the proposal density, a transition density `p(x[step + 1] | x[step]), observation weights`p(y\[step + 1\] \| x\[step + 1\])`, and/or a backwards or 'L'-kernel`L(x\[step\] \| x\[step + 1\])`. The (log) normalization constant of the weights is interpreted as the incremental (log) marginal likelihood. </td> </tr><tr> <td>`resample_fn`<a id="resample_fn"></a> </td> <td> Resampling scheme specified as a`callable`with signature`indices = resample_fn(log_probs, event_size, sample_shape, seed)`, where`log_probs`is a`Tensor`of the same shape as`state.log_weights`containing a normalized log-probability for every current particle,`event_size`is the number of new particle indices to generate,`sample_shape`is the number of independent index sets to return, and the return value`indices`is an`int`Tensor of shape`concat(\[sample_shape, \[event_size, B1, ..., BN\])`. Typically one of <a href="../../../tfp/experimental/mcmc/resample_deterministic_minimum_error"><code>tfp.experimental.mcmc.resample_deterministic_minimum_error</code></a>, <a href="../../../tfp/experimental/mcmc/resample_independent"><code>tfp.experimental.mcmc.resample_independent</code></a>, <a href="../../../tfp/experimental/mcmc/resample_stratified"><code>tfp.experimental.mcmc.resample_stratified</code></a>, or <a href="../../../tfp/experimental/mcmc/resample_systematic"><code>tfp.experimental.mcmc.resample_systematic</code></a>. Default value: <a href="../../../tfp/experimental/mcmc/resample_systematic"><code>tfp.experimental.mcmc.resample_systematic</code></a>. </td> </tr><tr> <td>`resample_criterion_fn`<a id="resample_criterion_fn"></a> </td> <td> optional Python`callable`with signature`do_resample = resample_criterion_fn(weighted_particles)`, passed an instance of <a href="../../../tfp/experimental/mcmc/WeightedParticles"><code>tfp.experimental.mcmc.WeightedParticles</code></a>. The return value`do_resample`determines whether particles are resampled at the current step. The default behavior is to resample particles when the effective sample size falls below half of the total number of particles. Default value: <a href="../../../tfp/experimental/mcmc/ess_below_threshold"><code>tfp.experimental.mcmc.ess_below_threshold</code></a>. </td> </tr><tr> <td>`unbiased_gradients`<a id="unbiased_gradients"></a> </td> <td> If`True`, use the stop-gradient resampling trick of Scibior, Masrani, and Wood [{scibor_ref_idx}] to correct for gradient bias introduced by the discrete resampling step. This will generally increase the variance of stochastic gradients. Default value:`True`. </td> </tr><tr> <td>`particles_dim`<a id="particles_dim"></a> </td> <td>`int`dimension that indexes the particles in the <a href="../../../tfp/experimental/mcmc/WeightedParticles"><code>tfp.experimental.mcmc.WeightedParticles</code></a> structures on which this kernel operates. Default value:`0`. </td> </tr><tr> <td>`name`<a id="name"></a> </td> <td> Python`str\` name for ops created by this kernel. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `experimental_shard_axis_names` | The shard axis names for members of the state. |
| `is_calibrated` | Returns `True` if Markov chain converges to specified distribution. <br /> `TransitionKernel`s which are "uncalibrated" are often calibrated by composing them with the [`tfp.mcmc.MetropolisHastings`](https://www.tensorflow.org/probability/api_docs/python/tfp/mcmc/MetropolisHastings) `TransitionKernel`. |
| `name` | <br /> <br /> |
| `particles_dim` | <br /> <br /> |
| `propose_and_update_log_weights_fn` | <br /> <br /> |
| `resample_criterion_fn` | <br /> <br /> |
| `resample_fn` | <br /> <br /> |
| `unbiased_gradients` | <br /> <br /> |

<br />

## Methods

### `bootstrap_results`

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

    bootstrap_results(
        init_state
    )

Returns an object with the same type as returned by `one_step(...)[1]`.

<br />

<br />

<br />

| Args ||
|---|---|
| `init_state` | `Tensor` or Python `list` of `Tensor`s representing the initial state(s) of the Markov chain(s). |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `kernel_results` | A (possibly nested) `tuple`, `namedtuple` or `list` of `Tensor`s representing internal calculations made within this function. |

<br />

### `copy`

[View source](https://github.com/tensorflow/probability/blob/v0.25.0/tensorflow_probability/python/mcmc/kernel.py#L148-L164)

    copy(
        **override_parameter_kwargs
    )

Non-destructively creates a deep copy of the kernel.

<br />

<br />

<br />

| Args ||
|---|---|
| `**override_parameter_kwargs` | Python String/value `dictionary` of initialization arguments to override with new values. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `new_kernel` | `TransitionKernel` object of same type as `self`, initialized with the union of self.parameters and override_parameter_kwargs, with any shared keys overridden by the value of override_parameter_kwargs, i.e., `dict(self.parameters, **override_parameters_kwargs)`. |

<br />

### `experimental_with_shard_axes`

[View source](https://github.com/tensorflow/probability/blob/v0.25.0/tensorflow_probability/python/mcmc/kernel.py#L136-L146)

    experimental_with_shard_axes(
        shard_axis_names
    )

Returns a copy of the kernel with the provided shard axis names.

<br />

<br />

<br />

| Args ||
|---|---|
| `shard_axis_names` | a structure of strings indicating the shard axis names for each component of this kernel's state. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A copy of the current kernel with the shard axis information. ||

<br />

### `one_step`

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

    one_step(
        state, kernel_results, seed=None
    )

Takes one Sequential Monte Carlo inference step.

<br />

<br />

<br />

| Args ||
|---|---|
| `state` | instance of [`tfp.experimental.mcmc.WeightedParticles`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/mcmc/WeightedParticles) representing the current particles with (log) weights. The `log_weights` must be a float `Tensor` of shape `[num_particles, b1, ..., bN]`. The `particles` may be any structure of `Tensor`s, each of which must have shape `concat([log_weights.shape, event_shape])` for some `event_shape`, which may vary across components. |
| `kernel_results` | instance of [`tfp.experimental.mcmc.SequentialMonteCarloResults`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/mcmc/SequentialMonteCarloResults) representing results from a previous step. |
| `seed` | PRNG seed; see [`tfp.random.sanitize_seed`](https://www.tensorflow.org/probability/api_docs/python/tfp/random/sanitize_seed) for details. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `state` | instance of [`tfp.experimental.mcmc.WeightedParticles`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/mcmc/WeightedParticles) representing new particles with (log) weights. |
| `kernel_results` | instance of [`tfp.experimental.mcmc.SequentialMonteCarloResults`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/mcmc/SequentialMonteCarloResults). |

<br />