code: def model_parameter_samples_from_gibbs_samples(model, gibbs_samples):
      """Constructs parameter samples to match the model (e.g. for sts.forecast).
  
      This unpacks the Gibbs samples, dropping the latents, to match the order
      needed for `make_state_space_model`.
  
      Args:
        model: A `tfd.sts.StructuralTimeSeries` model instance. This must be of the
          form constructed by `build_model_for_gibbs_sampling`.
        gibbs_samples: A `GibbsSamplerState` instance, presumably from
          `fit_with_gibbs_sampling`.
  
      Returns:
        A set of posterior samples, that can be used with `make_state_space_model`
        or `sts.forecast`.
      """
      # Make use of the indices in the model to avoid requiring a specific
      # order of components.
      (
          (level_component_index, level_component),
          (regression_component_index, _),
          seasonal_indices_and_components,
      ) = _get_components_from_model(model)
      seasonal_index_set = set(
          [x[0] for x in seasonal_indices_and_components]
      )
      model_parameter_samples = (gibbs_samples.observation_noise_scale,)
  
      # The last axis is the seasonal axis.
      seasonal_parameter_samples = tf.unstack(
          gibbs_samples.seasonal_drift_scales, axis=-1
      )
      # Allow seasonal components to not be consecutive by tracking how many
      # have been unpacked.
      seasonal_component_index = 0
      for index in range(len(model.components)):
          if index == level_component_index:
              model_parameter_samples += (gibbs_samples.level_scale,)
              if isinstance(
                  level_component, local_linear_trend.LocalLinearTrend
              ):
                  model_parameter_samples += (
                      gibbs_samples.slope_scale,
                  )
          elif index == regression_component_index:
              model_parameter_samples += (gibbs_samples.weights,)
          elif index in seasonal_index_set:
              model_parameter_samples += (
                  seasonal_parameter_samples[seasonal_component_index],
              )
              seasonal_component_index += 1
  
      return model_parameter_samples
  
imports: import collections
  import itertools
  import numpy
  import six
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import identity
  from tensorflow_probability.python.bijectors import invert
  from tensorflow_probability.python.bijectors import square
  from tensorflow_probability.python.distributions import categorical
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.distributions import gamma
  from tensorflow_probability.python.distributions import inverse_gamma
  from tensorflow_probability.python.distributions import mixture_same_family
  from tensorflow_probability.python.distributions import mvn_diag
  from tensorflow_probability.python.distributions import mvn_linear_operator
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.distributions import normal_conjugate_posteriors
  from tensorflow_probability.python.distributions import transformed_distribution
  from tensorflow_probability.python.experimental.distributions import mvn_precision_factor_linop
  from tensorflow_probability.python.experimental.sts_gibbs import dynamic_spike_and_slab
  from tensorflow_probability.python.experimental.sts_gibbs import sample_parameters
  from tensorflow_probability.python.experimental.sts_gibbs import spike_and_slab
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import reparameterization
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.sts.components import local_level
  from tensorflow_probability.python.sts.components import local_linear_trend
  from tensorflow_probability.python.sts.components import regression
  from tensorflow_probability.python.sts.components import seasonal
  from tensorflow_probability.python.sts.components import sum
  from tensorflow_probability.python.sts.internal import util
label_desc: Use image node_id 7 for calling a global function with example usage: model_parameter_samples_from_gibbs_samples(model, gibbs_samples) and returns: model_parameter_samples