<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/sts_gibbs/gibbs_sampler.py#L211-L374) |

Builds a StructuralTimeSeries model instance that supports Gibbs sampling.

    tfp.experimental.sts_gibbs.build_model_for_gibbs_fitting(
        observed_time_series,
        design_matrix,
        weights_prior,
        level_variance_prior,
        observation_noise_variance_prior,
        slope_variance_prior=None,
        initial_level_prior=None,
        sparse_weights_nonzero_prob=None,
        seasonal_components=None
    )

To support Gibbs sampling, a model must have have conjugate priors on all
scale and weight parameters, and must be constructed so that
`model.parameters` matches the parameters and ordering specified by the
`GibbsSamplerState` namedtuple. Currently, this includes (only) models
consisting of the sum of a LocalLevel or LocalLinearTrend component with
(optionally) a LinearRegression or SpikeAndSlabSparseLinearRegression
component.

<br />

<br />

<br />

| ## Args ||
|---|---|---|
| `observed_time_series` | optional `float` `Tensor` of shape \[..., T, 1\]`(omitting the trailing unit dimension is also supported when`T \> 1`), specifying an observed time series. May optionally be an instance of <a href="../../../tfp/sts/MaskedTimeSeries"><code>tfp.sts.MaskedTimeSeries</code></a>, which includes a mask`Tensor`to specify timesteps with missing observations. </td> </tr><tr> <td>`design_matrix`<a id="design_matrix"></a> </td> <td> Optional float`Tensor`of shape`concat(\[batch_shape, \[num_timesteps, num_features\]\])`. This may also optionally be an instance of <a href="https://www.tensorflow.org/api_docs/python/tf/linalg/LinearOperator"><code>tf.linalg.LinearOperator</code></a>. If None, no regression is done. </td> </tr><tr> <td>`weights_prior`<a id="weights_prior"></a> </td> <td> Optional distribution instance specifying a normal prior on weights. This may be a multivariate normal instance with event shape`\[num_features\]`, or a scalar normal distribution with event shape`\[\]`. In either case, the batch shape must broadcast to the batch shape of`observed_time_series`. If a`sparse_weights_nonzero_prob`is specified, requesting sparse regression, then the`weights_prior`mean is ignored (because nonzero means are not currently implemented by the spike-and-slab sampler). In this case,`weights_prior=None`is also valid, and will use the default prior of the spike-and-slab sampler. </td> </tr><tr> <td>`level_variance_prior`<a id="level_variance_prior"></a> </td> <td> An instance of`tfd.InverseGamma`representing a prior on the level variance (`level_scale**2`) of a local level model. May have batch shape broadcastable to the batch shape of`observed_time_series`. </td> </tr><tr> <td>`observation_noise_variance_prior`<a id="observation_noise_variance_prior"></a> </td> <td> An instance of`tfd.InverseGamma`representing a prior on the observation noise variance (`observation_noise_scale** 2`). May have batch shape broadcastable to the batch shape of`observed_time_series`. </td> </tr><tr> <td>`slope_variance_prior`<a id="slope_variance_prior"></a> </td> <td> Optional instance of`tfd.InverseGamma`representing a prior on slope variance (`slope_scale\*\*2`) of a local linear trend model. May have batch shape broadcastable to the batch shape of`observed_time_series`. If specified, a local linear trend model is used rather than a local level model. Default value:`None`. </td> </tr><tr> <td>`initial_level_prior`<a id="initial_level_prior"></a> </td> <td> optional`tfd.Distribution`instance specifying a prior on the initial level. If`None`, a heuristic default prior is constructed based on the provided`observed_time_series`. Default value:`None`. </td> </tr><tr> <td>`sparse_weights_nonzero_prob`<a id="sparse_weights_nonzero_prob"></a> </td> <td> Optional scalar float`Tensor`prior probability that any given feature has nonzero weight. If specified, this triggers a sparse regression with a spike-and-slab prior, where`sparse_weights_nonzero_prob`is the prior probability of the 'slab' component. Default value:`None`. </td> </tr><tr> <td>`seasonal_components\` | An (optional) list of Seasonal components to include in the model. There are restrictions about what priors may be specified (InverseGamma drift scale prior). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| `model` | A [`tfp.sts.StructuralTimeSeries`](https://www.tensorflow.org/probability/api_docs/python/tfp/sts/StructuralTimeSeries) model instance. |

<br />