docstr: Sampling from the Standard Normal Distribution using Cauchy proposal.
docstr_tok: ["Sampling","from","the","Standard","Normal","Distribution","using","Cauchy","proposal","."]
code: def testRWM1DCauchy(self):
      """Sampling from the Standard Normal Distribution using Cauchy proposal."""
      dtype = np.float32
      num_burnin_steps = 750
      num_chain_results = 400
  
      target = normal.Normal(loc=dtype(0), scale=dtype(1))
  
      def cauchy_new_state_fn(scale, dtype):
          dist = cauchy.Cauchy(loc=dtype(0), scale=dtype(scale))
  
          def _fn(state_parts, seed):
              seeds = samplers.split_seed(
                  seed, n=len(state_parts), salt="rwmcauchy"
              )
              next_state_parts = [
                  state + dist.sample(state.shape, seed=part_seed)
                  for state, part_seed in zip(state_parts, seeds)
              ]
              return next_state_parts
  
          return _fn
  
      samples = sample.sample_chain(
          num_results=num_chain_results,
          num_burnin_steps=num_burnin_steps,
          current_state=dtype([1] * 8),  # 8 parallel chains
          kernel=random_walk_metropolis.RandomWalkMetropolis(
              target.log_prob,
              new_state_fn=cauchy_new_state_fn(scale=0.5, dtype=dtype),
          ),
          trace_fn=None,
          seed=test_util.test_seed(),
      )
  
      sample_mean = tf.math.reduce_mean(samples, axis=(0, 1))
      sample_std = tf.math.reduce_std(samples, axis=(0, 1))
      [sample_mean_, sample_std_] = self.evaluate(
          [sample_mean, sample_std]
      )
  
      self.assertAllClose(0.0, sample_mean_, atol=0.2, rtol=0.0)
      self.assertAllClose(1.0, sample_std_, atol=0.2, rtol=0.0)
  
imports: import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import cauchy
  from tensorflow_probability.python.distributions import mvn_tril
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.internal import distribute_lib
  from tensorflow_probability.python.internal import distribute_test_lib
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.mcmc import random_walk_metropolis
  from tensorflow_probability.python.mcmc import sample
label_desc: Use image node_id 4 for calling the RWMTest obj's underlying member method code with example usage: obj.testRWM1DCauchy() and returns: _fn, next_state_parts