code: def test_sanity_check_sweep_over_features(self):
      num_outputs = 100
      num_features = 3
      batch_shape = [2]
      design_matrix, true_weights, targets = self.evaluate(
          self._random_regression_task(
              num_outputs=num_outputs,
              num_features=num_features,
              batch_shape=batch_shape,
              # Specify weights with a clear sparsity pattern.
              weights=tf.convert_to_tensor(
                  [[10.0, 0.0, -10.0], [0.0, 0.0, 0.5]]
              ),
              seed=test_util.test_seed(),
          )
      )
  
      sampler = spike_and_slab.SpikeSlabSampler(
          design_matrix,
          # Ensure the probability of keeping an irrelevant feature is tiny.
          nonzero_prior_prob=1e-6,
      )
      initial_state = sampler._initialize_sampler_state(
          targets=targets,
          nonzeros=tf.convert_to_tensor([True, True, True]),
          observation_noise_variance=1.0,
      )
      final_state = self.evaluate(
          sampler._resample_all_features(
              initial_state, seed=test_util.test_seed()
          )
      )
  
      # Check that we recovered the true sparsity pattern and approximate weights.
      self.assertAllEqual(
          final_state.nonzeros,
          [[True, False, True], [False, False, True]],
      )
      self.assertAllClose(
          final_state.conditional_weights_mean,
          true_weights,
          rtol=0.05,
          atol=0.15,
      )
      # Check shapes of other components.
      self.assertAllEqual(
          final_state.conditional_prior_precision_chol.shape,
          batch_shape + [num_features, num_features],
      )
      self.assertAllEqual(
          final_state.conditional_posterior_precision_chol.shape,
          batch_shape + [num_features, num_features],
      )
      self.assertAllEqual(
          final_state.observation_noise_variance_posterior_scale.shape,
          batch_shape,
      )
  
      posterior = sampler._get_conditional_posterior(final_state)
      posterior_variances, posterior_weights = self.evaluate(
          posterior.sample(10, seed=test_util.test_seed())
      )
      self.assertAllFinite(posterior_variances)
      self.assertAllFinite(posterior_weights)
  
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import inverse_gamma
  from tensorflow_probability.python.distributions import normal_conjugate_posteriors
  from tensorflow_probability.python.experimental.sts_gibbs import spike_and_slab
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.mcmc.internal import util
label_desc: Use image node_id 8 for calling the SpikeAndSlabTest obj's underlying member method code with example usage: obj.test_sanity_check_sweep_over_features() without return types