code: def test_sir_regularized_numdiff():
      # Use numeric gradients to check the analytic gradient
      # for the regularized SIRobjective function.
  
      np.random.seed(93482)
  
      n = 1000
      p = 10
      xmat = np.random.normal(size=(n, p))
      y1 = np.dot(xmat, np.linspace(-1, 1, p))
      y2 = xmat.sum(1)
      y = y2 / (1 + y1**2) + np.random.normal(size=n)
      model = SlicedInverseReg(y, xmat)
      _ = model.fit()
  
      # Second difference penalty matrix.
      fmat = np.zeros((p - 2, p))
      for i in range(p - 2):
          fmat[i, i : i + 3] = [1, -2, 1]
  
      with pytest.warns(
          UserWarning, match="SIR.fit_regularized did not"
      ):
          _ = model.fit_regularized(2, 3 * fmat)
  
      # Compare the gradients to the numerical derivatives
      for _ in range(5):
          pa = np.random.normal(size=(p, 2))
          pa, _, _ = np.linalg.svd(pa, 0)
          gn = approx_fprime(
              pa.ravel(), model._regularized_objective, 1e-7
          )
          gr = model._regularized_grad(pa.ravel())
          assert_allclose(gn, gr, atol=1e-5, rtol=1e-4)
  
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 2 for calling a global function with example usage: test_sir_regularized_numdiff() without return types