code: def test_sir_regularized_1d():
      # Compare regularized SIR to traditional SIR, in a setting where the
      # regularization is compatible with the true parameters (i.e. there
      # is no regularization bias).
  
      np.random.seed(93482)
  
      n = 1000
      p = 10
      xmat = np.random.normal(size=(n, p))
      y = np.dot(xmat[:, 0:4], np.r_[1, 1, -1, -1]) + np.random.normal(
          size=n
      )
      model = SlicedInverseReg(y, xmat)
      rslt = model.fit()
  
      # The penalty drives p[0] ~ p[1] and p[2] ~ p[3]]
      fmat = np.zeros((2, p))
      fmat[0, 0:2] = [1, -1]
      fmat[1, 2:4] = [1, -1]
  
      rslt2 = model.fit_regularized(1, 3 * fmat)
  
      pa0 = np.zeros(p)
      pa0[0:4] = [1, 1, -1, -1]
      pa1 = rslt.params[:, 0]
      pa2 = rslt2.params[:, 0:2]
  
      # Compare two 1d subspaces
      def sim(x, y):
          x = x / np.sqrt(np.sum(x * x))
          y = y / np.sqrt(np.sum(y * y))
          return 1 - np.abs(np.dot(x, y))
  
      # Regularized SIRshould be closer to the truth than traditional SIR
      assert_equal(sim(pa0, pa1) > sim(pa0, pa2), True)
  
      # Regularized SIR should be close to the truth
      assert_equal(sim(pa0, pa2) < 1e-3, True)
  
      # Regularized SIR should have a smaller penalty value than traditional SIR
      assert_equal(
          np.sum(np.dot(fmat, pa1) ** 2)
          > np.sum(np.dot(fmat, pa2) ** 2),
          True,
      )
  
file_path: statsmodels/statsmodels/regression/tests/test_dimred.py
imports: import numpy
  import pandas
  import pytest
  from statsmodels.regression.dimred import SlicedInverseReg, SAVE, PHD, CORE
  from numpy.testing import assert_equal, assert_allclose
  from statsmodels.tools.numdiff import approx_fprime
label_desc: Use image node_id 3 for calling a global function with example usage: test_sir_regularized_1d() and returns: unknown