code: def test_randomized_pca_inverse(setup):
      # Test that randomized PCA is inversible on dense data
      rng = np.random.RandomState(0)
      n, p = 50, 3
      X = mt.tensor(rng.randn(n, p))  # spherical data
      X[:, 1] *= 0.00001  # make middle component relatively small
      X += [5, 4, 3]  # make a large mean
  
      # same check that we can find the original data from the transformed signal
      # (since the data is almost of rank n_components)
      pca = PCA(
          n_components=2, svd_solver="randomized", random_state=0
      ).fit(X)
      Y = pca.transform(X)
      Y_inverse = pca.inverse_transform(Y)
      assert_almost_equal(X.to_numpy(), Y_inverse.to_numpy(), decimal=2)
  
      # same as above with whitening (approximate reconstruction)
      pca = PCA(
          n_components=2,
          whiten=True,
          svd_solver="randomized",
          random_state=0,
      ).fit(X)
      Y = pca.transform(X)
      Y_inverse = pca.inverse_transform(Y)
      relative_max_delta = (
          mt.abs(X - Y_inverse) / mt.abs(X).mean()
      ).max()
      assert relative_max_delta.to_numpy() < 1e-5
  
imports: from itertools import product
  import numpy
  import pytest
  import scipy
  from sklearn import datasets
  from sklearn.utils._testing import assert_array_almost_equal, assert_almost_equal, assert_raises_regex, assert_raise_message, assert_raises
  from ....None import tensor
  from .._pca import PCA, _assess_dimension, _infer_dimension
label_desc: Use image node_id 12 for calling a global function with example usage: test_randomized_pca_inverse(setup) without return types