docstr: Check that slope follows `slope_mean` and has stationary variance.
docstr_tok: ["Check","that","slope","follows","`","slope_mean","`","and","has","stationary","variance","."]
code: def test_slope_mean_and_variance(self):
      """Check that slope follows `slope_mean` and has stationary variance."""
  
      level_scale = 0.1
      slope_scale = 0.2
      initial_level = 3.0
      initial_slope = 0.0
      slope_mean = -2.0
      initial_level = 3.0
      autoregressive_coef = 0.9
      num_timesteps = 50
  
      # Stationary distribution of an AR1 process, from
      # (https://en.wikipedia.org/wiki/Autoregressive_model#Example:_An_AR(1)_process)  # pylint: disable=line-too-long
      stationary_slope_variance = slope_scale**2 / (
          1.0 - autoregressive_coef**2
      )
  
      # Initialize the slope prior at the stationary variance.
      initial_state_prior = mvn_diag.MultivariateNormalDiag(
          loc=self._build_placeholder([initial_level, initial_slope]),
          scale_diag=self._build_placeholder(
              [1.0, np.sqrt(stationary_slope_variance)]
          ),
      )
  
      semilocal_ssm = SemiLocalLinearTrendStateSpaceModel(
          num_timesteps=num_timesteps,
          level_scale=self._build_placeholder(level_scale),
          slope_scale=self._build_placeholder(slope_scale),
          slope_mean=self._build_placeholder(slope_mean),
          autoregressive_coef=self._build_placeholder(
              autoregressive_coef
          ),
          initial_state_prior=initial_state_prior,
      )
  
      # The slope of the mean should converge to `slope_mean` (as opposed to
      # staying fixed at `initial_slope` as in a LocalLinearTrend).
      mean_ = self.evaluate(semilocal_ssm.mean()[..., 0])
      final_slope = mean_[num_timesteps - 1] - mean_[num_timesteps - 2]
      self.assertAllClose(final_slope, slope_mean, atol=0.05)
  
      # The variance in latent `slope` should converge to the stationary
      # distribution of an AR1 process:
      latent_covs, _ = semilocal_ssm._joint_covariances()
      actual_slope_variances = tf.linalg.diag_part(latent_covs)[:, 1]
      converged_slope_variance = actual_slope_variances[-1]
      self.assertAllClose(
          self.evaluate(converged_slope_variance),
          stationary_slope_variance,
          atol=1e-4,
      )
  
imports: import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import mvn_diag
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.sts.components.local_linear_trend import LocalLinearTrendStateSpaceModel
  from tensorflow_probability.python.sts.components.semilocal_linear_trend import SemiLocalLinearTrendStateSpaceModel
label_desc: Use image node_id 3 for calling the _SemiLocalLinearTrendStateSpaceModelTest obj's underlying member method code with example usage: obj.test_slope_mean_and_variance() without return types