def _decompose_from_posterior_marginals(<EOL>model, posterior_means, posterior_covs, parameter_samples):
try:<EOL><INDENT>model.components<EOL><DEDENT>except AttributeError:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>'.format(model))<EOL><DEDENT>with tf.compat.v1.name_scope('<STR_LIT>'):<EOL><INDENT>latent_sizes = [component.latent_size for component in model.components]<EOL>component_means = tf.split(posterior_means, latent_sizes, axis=-<NUM_LIT:1>)<EOL>component_covs = _split_covariance_into_marginals(<EOL>posterior_covs, latent_sizes)<EOL>num_timesteps = dist_util.prefer_static_value(<EOL>tf.shape(input=posterior_means))[-<NUM_LIT:2>]<EOL>component_ssms = model.make_component_state_space_models(<EOL>num_timesteps=num_timesteps,<EOL>param_vals=parameter_samples)<EOL>component_predictive_dists = collections.OrderedDict()<EOL>for (component, component_ssm,<EOL>component_mean, component_cov) in zip(model.components, component_ssms,<EOL>component_means, component_covs):<EOL><INDENT>component_obs_mean, component_obs_cov = (<EOL>component_ssm.latents_to_observations(<EOL>latent_means=component_mean,<EOL>latent_covs=component_cov))<EOL>component_predictive_dists[component] = sts_util.mix_over_posterior_draws(<EOL>means=component_obs_mean[..., <NUM_LIT:0>],<EOL>variances=component_obs_cov[..., <NUM_LIT:0>, <NUM_LIT:0>])<EOL><DEDENT><DEDENT>return component_predictive_dists<EOL>
Utility method to decompose a joint posterior into components.

    Args:
      model: `tfp.sts.Sum` instance defining an additive STS model.
      posterior_means: float `Tensor` of shape `concat(
        [[num_posterior_draws], batch_shape, num_timesteps, latent_size])`
        representing the posterior mean over latents in an
        `AdditiveStateSpaceModel`.
      posterior_covs: float `Tensor` of shape `concat(
        [[num_posterior_draws], batch_shape, num_timesteps,
        latent_size, latent_size])`
        representing the posterior marginal covariances over latents in an
        `AdditiveStateSpaceModel`.
      parameter_samples: Python `list` of `Tensors` representing posterior
        samples of model parameters, with shapes `[concat([
        [num_posterior_draws], param.prior.batch_shape,
        param.prior.event_shape]) for param in model.parameters]`. This may
        optionally also be a map (Python `dict`) of parameter names to
        `Tensor` values.

    Returns:
      component_dists: A `collections.OrderedDict` instance mapping
        component StructuralTimeSeries instances (elements of `model.components`)
        to `tfd.Distribution` instances representing the posterior marginal
        distributions on the process modeled by each component. Each distribution
        has batch shape matching that of `posterior_means`/`posterior_covs`, and
        event shape of `[num_timesteps]`.