class_docstr: Tests for simulation smoothing values in a couple of special cases of
  variates. Both computed values and KFAS values are used for comparison
  against the simulation smoother output.
class_docstr_tok: ["Tests","for","simulation","smoothing","values","in","a","couple","of","special","cases","of","variates",".","Both","computed","values","and","KFAS","values","are","used","for","comparison","against","the","simulation","smoother","output","."]
code: def test_simulation_smoothing_2(self):
      # Test with measurement and state disturbances as np.arange / 10.,
      # initial state variates are zeros.
      sim = self.sim
  
      Z = self.model["design"]
      T = self.model["transition"]
  
      nobs = self.model.nobs
      k_endog = self.model.k_endog
      k_posdef = self.model.ssm.k_posdef
      k_states = self.model.k_states
  
      # Construct the variates
      measurement_disturbance_variates = np.reshape(
          np.arange(nobs * k_endog) / 10.0, (nobs, k_endog)
      )
      state_disturbance_variates = np.reshape(
          np.arange(nobs * k_posdef) / 10.0, (nobs, k_posdef)
      )
      initial_state_variates = np.zeros(k_states)
  
      # Compute some additional known quantities
      generated_measurement_disturbance = np.zeros(
          measurement_disturbance_variates.shape
      )
      chol = np.linalg.cholesky(self.model["obs_cov"])
      for t in range(self.model.nobs):
          generated_measurement_disturbance[t] = np.dot(
              chol, measurement_disturbance_variates[t]
          )
  
      generated_state_disturbance = np.zeros(
          state_disturbance_variates.shape
      )
      chol = np.linalg.cholesky(self.model["state_cov"])
      for t in range(self.model.nobs):
          generated_state_disturbance[t] = np.dot(
              chol, state_disturbance_variates[t]
          )
  
      generated_obs = np.zeros((self.model.k_endog, self.model.nobs))
      generated_state = np.zeros(
          (self.model.k_states, self.model.nobs + 1)
      )
      chol = np.linalg.cholesky(self.results.initial_state_cov)
      generated_state[:, 0] = self.results.initial_state + np.dot(
          chol, initial_state_variates
      )
      for t in range(self.model.nobs):
          generated_state[:, t + 1] = (
              np.dot(T, generated_state[:, t])
              + generated_state_disturbance.T[:, t]
          )
          generated_obs[:, t] = (
              np.dot(Z, generated_state[:, t])
              + generated_measurement_disturbance.T[:, t]
          )
      y = generated_obs.copy().T
      y[np.isnan(self.model.endog)] = np.nan
  
      generated_model = mlemodel.MLEModel(
          y, k_states=k_states, k_posdef=k_posdef
      )
      for name in [
          "design",
          "obs_cov",
          "transition",
          "selection",
          "state_cov",
      ]:
          generated_model[name] = self.model[name]
  
      generated_model.initialize_approximate_diffuse(1e6)
      generated_model.ssm.filter_univariate = True
      generated_res = generated_model.ssm.smooth()
      simulated_state = (
          generated_state[:, :-1]
          - generated_res.smoothed_state
          + self.results.smoothed_state
      )
      if not self.model.ssm.filter_collapsed:
          simulated_measurement_disturbance = (
              generated_measurement_disturbance.T
              - generated_res.smoothed_measurement_disturbance
              + self.results.smoothed_measurement_disturbance
          )
      simulated_state_disturbance = (
          generated_state_disturbance.T
          - generated_res.smoothed_state_disturbance
          + self.results.smoothed_state_disturbance
      )
  
      # Test against known values
      sim.simulate(
          measurement_disturbance_variates=(
              measurement_disturbance_variates
          ),
          state_disturbance_variates=state_disturbance_variates,
          initial_state_variates=np.zeros(k_states),
      )
  
      assert_allclose(
          sim.generated_measurement_disturbance,
          generated_measurement_disturbance,
      )
      assert_allclose(
          sim.generated_state_disturbance, generated_state_disturbance
      )
      assert_allclose(sim.generated_state, generated_state)
      assert_allclose(sim.generated_obs, generated_obs)
      assert_allclose(sim.simulated_state, simulated_state, atol=1e-7)
      if not self.model.ssm.filter_collapsed:
          assert_allclose(
              sim.simulated_measurement_disturbance.T,
              simulated_measurement_disturbance.T,
          )
      assert_allclose(
          sim.simulated_state_disturbance, simulated_state_disturbance
      )
  
      # Test against R package KFAS values
      if self.test_against_KFAS:
          path = os.path.join(
              current_path,
              "results",
              "results_simulation_smoothing2.csv",
          )
          true = pd.read_csv(path)
          assert_allclose(
              sim.simulated_state.T,
              true[["state1", "state2", "state3"]],
              atol=1e-7,
          )
          assert_allclose(
              sim.simulated_measurement_disturbance,
              true[["eps1", "eps2", "eps3"]].T,
              atol=1e-7,
          )
          assert_allclose(
              sim.simulated_state_disturbance,
              true[["eta1", "eta2", "eta3"]].T,
              atol=1e-7,
          )
          signals = np.zeros((3, self.model.nobs))
          for t in range(self.model.nobs):
              signals[:, t] = np.dot(Z, sim.simulated_state[:, t])
          assert_allclose(
              signals,
              true[["signal1", "signal2", "signal3"]].T,
              atol=1e-7,
          )
  
imports: import os
  import numpy
  import pandas
  from numpy.testing import assert_allclose, assert_equal
  import pytest
  from statsmodels import datasets
  from statsmodels.tsa.statespace import mlemodel, sarimax, structural, varmax
  from statsmodels.tsa.statespace.simulation_smoother import SIMULATION_STATE, SIMULATION_DISTURBANCE, SIMULATION_ALL
label_desc: Use image node_id 8 for calling the MultivariateVARKnown obj's underlying member method code with example usage: obj.test_simulation_smoothing_2() without return types