code: def test_purify_identifiable():
      np.random.seed(0)
  
      # Test whether perturbing a model, then purifying it recovers the original model.
      def helper(randomize):
          raw_mat = np.random.uniform(
              -1, 1, size=(n_rows, n_cols)
          ) * np.random.binomial(1, 0.9, size=(n_rows, n_cols))
          densities = np.random.uniform(1, 100, size=(n_rows, n_cols))
          intercept, m1, m2, pure_mat, n_iters = purify(
              raw_mat.copy(),
              densities=densities,
              tol=1e-10,
              randomize=randomize,
          )
          m1_perturbed = m1.copy()
          m2_perturbed = m2.copy()
          mat_perturbed = pure_mat.copy()
          for i in range(n_rows):
              val = np.random.normal()
              m1_perturbed[i] += val
              mat_perturbed[i, :] -= val
          for j in range(n_cols):
              val = np.random.normal()
              m2_perturbed[j] += val
              mat_perturbed[:, j] -= val
          intercept2, m12, m22, pure_mat2, n_iters2 = purify(
              mat_perturbed,
              densities=densities,
              tol=1e-10,
              randomize=randomize,
          )
          m12 += m1_perturbed
          m22 += m2_perturbed
  
          # After centering, the purified model should be the same.
          m12 -= np.average(m12, weights=np.sum(densities, axis=1))
          m22 -= np.average(m22, weights=np.sum(densities, axis=0))
  
          assert np.all(np.isclose(m1, m12, atol=1e-10))
          assert np.all(np.isclose(m2, m22, atol=1e-10))
          assert np.all(np.isclose(pure_mat, pure_mat2, atol=1e-10))
  
      helper(False)
      helper(True)
  
file_path: interpret/python/interpret-core/tests/glassbox/ebm/research/test_purify.py
imports: import numpy
  from interpret.glassbox._ebm._research._purify import _purify_row, _purify_col
  from interpret.glassbox._ebm._research import purify
label_desc: Use image node_id 5 for calling a global function with example usage: test_purify_identifiable() without return types