code: def test_forecast_from_hmc(self):
      if not tf1.control_flow_v2_enabled():
          self.skipTest(
              "test_forecast_from_hmc does not currently work with TF1"
          )
  
      # test that we can directly plug in the output of an HMC chain as
      # the input to `forecast`, as done in the example, with no `sess.run` call.
      num_results = 5
      num_timesteps = 4
      num_steps_forecast = 3
      batch_shape = [1, 2]
      observed_time_series = self._build_tensor(
          np.random.randn(*(batch_shape + [num_timesteps]))
      )
      model = self._build_model(observed_time_series)
      samples, _ = fitting.fit_with_hmc(
          model,
          observed_time_series,
          num_results=num_results,
          num_warmup_steps=2,
          num_variational_steps=2,
      )
  
      forecast_dist = forecast.forecast(
          model,
          observed_time_series,
          parameter_samples=samples,
          num_steps_forecast=num_steps_forecast,
      )
  
      forecast_mean = forecast_dist.mean()[..., 0]
      forecast_scale = forecast_dist.stddev()[..., 0]
  
      sample_shape = [10]
      forecast_samples = forecast_dist.sample(
          sample_shape, seed=test_util.test_seed()
      )[..., 0]
  
      self.evaluate(tf1.global_variables_initializer())
      (
          forecast_mean_,
          forecast_scale_,
          forecast_samples_,
      ) = self.evaluate(
          (forecast_mean, forecast_scale, forecast_samples)
      )
      self.assertAllEqual(
          forecast_mean_.shape, batch_shape + [num_steps_forecast]
      )
      self.assertAllEqual(
          forecast_scale_.shape, batch_shape + [num_steps_forecast]
      )
      self.assertAllEqual(
          forecast_samples_.shape,
          sample_shape + batch_shape + [num_steps_forecast],
      )
  
imports: import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.sts import fitting
  from tensorflow_probability.python.sts import forecast
  from tensorflow_probability.python.sts.components import seasonal
  from tensorflow_probability.python.sts.components import sum
  from tensorflow_probability.python.sts.internal import missing_values_util
label_desc: Use image node_id 5 for calling the _ForecastTest obj's underlying member method code with example usage: obj.test_forecast_from_hmc() without return types