tfp.experimental.sts_gibbs.build_model_for_gibbs_fitting

Builds a StructuralTimeSeries model instance that supports Gibbs sampling.

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.

observed_time_series optional float Tensor of shape [..., T, 1](omitting the trailing unit dimension is also supported whenT > 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 maskTensorto specify timesteps with missing observations. </td> </tr><tr> <td>design_matrix<a id="design_matrix"></a> </td> <td> Optional floatTensorof shapeconcat([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 ofobserved_time_series. If asparse_weights_nonzero_probis specified, requesting sparse regression, then theweights_priormean is ignored (because nonzero means are not currently implemented by the spike-and-slab sampler). In this case,weights_prior=Noneis 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 oftfd.InverseGammarepresenting a prior on the level variance (level_scale2) of a local level model. May have batch shape broadcastable to the batch shape ofobserved_time_series. </td> </tr><tr> <td>observation_noise_variance_prior<a id="observation_noise_variance_prior"></a> </td> <td> An instance oftfd.InverseGammarepresenting a prior on the observation noise variance (observation_noise_scale2). May have batch shape broadcastable to the batch shape ofobserved_time_series. </td> </tr><tr> <td>slope_variance_prior<a id="slope_variance_prior"></a> </td> <td> Optional instance oftfd.InverseGammarepresenting a prior on slope variance (slope_scale**2) of a local linear trend model. May have batch shape broadcastable to the batch shape ofobserved_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> optionaltfd.Distributioninstance specifying a prior on the initial level. IfNone, a heuristic default prior is constructed based on the providedobserved_time_series. Default value:None. </td> </tr><tr> <td>sparse_weights_nonzero_prob<a id="sparse_weights_nonzero_prob"></a> </td> <td> Optional scalar floatTensorprior probability that any given feature has nonzero weight. If specified, this triggers a sparse regression with a spike-and-slab prior, wheresparse_weights_nonzero_probis 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).

model A tfp.sts.StructuralTimeSeries model instance.