code: def test_samples_from_weights_prior(self):
      nonzero_prior_prob = 0.7
      num_outputs, num_features = 200, 4
  
      # Setting the design matrix to zero, the targets provide no information
      # about weights, so the sampler should sample from the prior.
      design_matrix = tf.zeros([num_outputs, num_features])
      targets = 0.42 * samplers.normal(
          [num_outputs], seed=test_util.test_seed()
      )
      sampler = spike_and_slab.SpikeSlabSampler(
          design_matrix=design_matrix,
          weights_prior_precision=tf.eye(num_features),
          nonzero_prior_prob=nonzero_prior_prob,
      )
  
      # Draw 100 posterior samples. Since all state needed for the
      # internal feature sweep is a function of the sparsity pattern, it's
      # sufficient to pass the sparsity pattern (by way of the weights) as
      # the outer-loop state.
      @tf.function(autograph=False)
      def loop_body(var_weights_seed, _):
          _, weights, seed = var_weights_seed
          seed, next_seed = samplers.split_seed(seed, n=2)
          variance, weights = sampler.sample_noise_variance_and_weights(
              initial_nonzeros=tf.not_equal(weights, 0.0),
              targets=targets,
              seed=seed,
          )
          return variance, weights, next_seed
  
      init_seed = test_util.test_seed(sampler_type="stateless")
      variance_samples, weight_samples, _ = tf.scan(
          fn=loop_body,
          initializer=(1.0, tf.ones([num_features]), init_seed),
          elems=tf.range(100),
      )
  
      # With the default (relatively uninformative) prior, the noise variance
      # posterior mean should be close to the most-likely value.
      self.assertAllClose(
          tf.reduce_mean(variance_samples),
          tf.math.reduce_std(targets) ** 2,
          atol=0.03,
      )
      # Since there is no evidence for the weights, the sparsity of our samples
      # should match the prior.
      nonzero_weight_samples = tf.cast(
          tf.not_equal(weight_samples, 0.0), tf.float32
      )
      self.assertAllClose(
          nonzero_prior_prob,
          tf.reduce_mean(nonzero_weight_samples),
          atol=0.04,
      )
  
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 9 for calling the SpikeAndSlabTest obj's underlying member method code with example usage: obj.test_samples_from_weights_prior() and returns: variance,  weights,  next_seed