class_docstr: Runs one step of the RWM algorithm with symmetric proposal.
  
  Random Walk Metropolis is a gradient-free Markov chain Monte Carlo
  (MCMC) algorithm. The algorithm involves a proposal generating step
  `proposal_state = current_state + perturb` by a random
  perturbation, followed by Metropolis-Hastings accept/reject step. For more
  details see [Section 2.1 of Roberts and Rosenthal (2004)](
  http://dx.doi.org/10.1214/154957804100000024).
  
  Current class implements RWM for normal and uniform proposals. Alternatively,
  the user can supply any custom proposal generating function.
  
  The function `one_step` can update multiple chains in parallel. It assumes
  that all leftmost dimensions of `current_state` index independent chain states
  (and are therefore updated independently). The output of
  `target_log_prob_fn(*current_state)` should sum log-probabilities across all
  event dimensions. Slices along the rightmost dimensions may have different
  target distributions; for example, `current_state[0, :]` could have a
  different target distribution from `current_state[1, :]`. These semantics
  are governed by `target_log_prob_fn(*current_state)`. (The number of
  independent chains is `tf.size(target_log_prob_fn(*current_state))`.)
  
  #### Examples:
  
  ##### Sampling from the Standard Normal Distribution.
  
  ```python
  import numpy as np
  import tensorflow.compat.v2 as tf
  import tensorflow_probability as tfp
  tfd = tfp.distributions
  
  dtype = np.float32
  
  target = tfd.Normal(loc=dtype(0), scale=dtype(1))
  
  samples = tfp.mcmc.sample_chain(
    num_results=1000,
    current_state=dtype(1),
    kernel=tfp.mcmc.RandomWalkMetropolis(target.log_prob),
    num_burnin_steps=500,
    trace_fn=None,
    seed=42)
  
  sample_mean = tf.math.reduce_mean(samples, axis=0)
  sample_std = tf.sqrt(
      tf.math.reduce_mean(
          tf.math.squared_difference(samples, sample_mean),
          axis=0))
  
  print('Estimated mean: {}'.format(sample_mean))
  print('Estimated standard deviation: {}'.format(sample_std))
  ```
  
  ##### Sampling from a 2-D Normal Distribution.
  
  ```python
  import numpy as np
  import tensorflow.compat.v2 as tf
  import tensorflow_probability as tfp
  tfd = tfp.distributions
  
  dtype = np.float32
  true_mean = dtype([0, 0])
  true_cov = dtype([[1, 0.5],
                    [0.5, 1]])
  num_results = 500
  num_chains = 100
  
  # Target distribution is defined through the Cholesky decomposition `L`:
  L = tf.linalg.cholesky(true_cov)
  target = tfd.MultivariateNormalTriL(loc=true_mean, scale_tril=L)
  
  # Initial state of the chain
  init_state = np.ones([num_chains, 2], dtype=dtype)
  
  # Run Random Walk Metropolis with normal proposal for `num_results`
  # iterations for `num_chains` independent chains:
  samples = tfp.mcmc.sample_chain(
      num_results=num_results,
      current_state=init_state,
      kernel=tfp.mcmc.RandomWalkMetropolis(target_log_prob_fn=target.log_prob),
      num_burnin_steps=200,
      num_steps_between_results=1,  # Thinning.
      trace_fn=None,
      seed=54)
  
  sample_mean = tf.math.reduce_mean(samples, axis=0)
  x = tf.squeeze(samples - sample_mean)
  sample_cov = tf.matmul(tf.transpose(x, [1, 2, 0]),
                         tf.transpose(x, [1, 0, 2])) / num_results
  
  mean_sample_mean = tf.math.reduce_mean(sample_mean)
  mean_sample_cov = tf.math.reduce_mean(sample_cov, axis=0)
  x = tf.reshape(sample_cov - mean_sample_cov, [num_chains, 2 * 2])
  cov_sample_cov = tf.reshape(tf.matmul(x, x, transpose_a=True) / num_chains,
                              shape=[2 * 2, 2 * 2])
  
  print('Estimated mean: {}'.format(mean_sample_mean))
  print('Estimated avg covariance: {}'.format(mean_sample_cov))
  print('Estimated covariance of covariance: {}'.format(cov_sample_cov))
  ```
  
  ##### Sampling from the Standard Normal Distribution using Cauchy proposal.
  
  ```python
  import numpy as np
  import tensorflow.compat.v2 as tf
  import tensorflow_probability as tfp
  tfd = tfp.distributions
  
  dtype = np.float32
  num_burnin_steps = 500
  num_chain_results = 1000
  
  def cauchy_new_state_fn(scale, dtype):
    cauchy = tfd.Cauchy(loc=dtype(0), scale=dtype(scale))
    def _fn(state_parts, seed):
      next_state_parts = []
      part_seeds = tfp.random.split_seed(
          seed, n=len(state_parts), salt='rwmcauchy')
      for sp, ps in zip(state_parts, part_seeds):
        next_state_parts.append(sp + cauchy.sample(
          sample_shape=sp.shape, seed=ps))
      return next_state_parts
    return _fn
  
  target = tfd.Normal(loc=dtype(0), scale=dtype(1))
  
  samples = tfp.mcmc.sample_chain(
      num_results=num_chain_results,
      num_burnin_steps=num_burnin_steps,
      current_state=dtype(1),
      kernel=tfp.mcmc.RandomWalkMetropolis(
          target.log_prob,
          new_state_fn=cauchy_new_state_fn(scale=0.5, dtype=dtype)),
      trace_fn=None,
      seed=42)
  
  sample_mean = tf.math.reduce_mean(samples, axis=0)
  sample_std = tf.sqrt(
      tf.math.reduce_mean(
          tf.math.squared_difference(samples, sample_mean),
          axis=0))
  
  print('Estimated mean: {}'.format(sample_mean))
  print('Estimated standard deviation: {}'.format(sample_std))
  ```
class_docstr_tok: ["Runs","one","step","of","the","RWM","algorithm","with","symmetric","proposal",".","Random","Walk","Metropolis","is","a","gradient-free","Markov","chain","Monte","Carlo","(","MCMC",")","algorithm",".","The","algorithm","involves","a","proposal","generating","step","`","proposal_state","=","current_state","+","perturb","`","by","a","random","perturbation",",","followed","by","Metropolis-Hastings","accept\/reject","step",".","For","more","details","see","[","Section","2.1","of","Roberts","and","Rosenthal","(","2004",")","]","(","http",":","\/\/dx.doi.org\/10.1214\/154957804100000024",")",".","Current","class","implements","RWM","for","normal","and","uniform","proposals",".","Alternatively",",","the","user","can","supply","any","custom","proposal","generating","function",".","The","function","`","one_step","`","can","update","multiple","chains","in","parallel",".","It","assumes","that","all","leftmost","dimensions","of","`","current_state","`","index","independent","chain","states","(","and","are","therefore","updated","independently",")",".","The","output","of","`","target_log_prob_fn","(","*","current_state",")","`","should","sum","log-probabilities","across","all","event","dimensions",".","Slices","along","the","rightmost","dimensions","may","have","different","target","distributions",";","for","example",",","`","current_state","[","0",",",":","]","`","could","have","a","different","target","distribution","from","`","current_state","[","1",",",":","]","`",".","These","semantics","are","governed","by","`","target_log_prob_fn","(","*","current_state",")","`",".","(","The","number","of","independent","chains","is","`","tf.size","(","target_log_prob_fn","(","*","current_state",")",")","`",".",")","#","#","#","#","Examples",":","#","#","#","#","#","Sampling","from","the","Standard","Normal","Distribution",".","``","`","python","import","numpy","as","np","import","tensorflow.compat.v2","as","tf","import","tensorflow_probability","as","tfp","tfd","=","tfp.distributions","dtype","=","np.float32","target","=","tfd.Normal","(","loc=dtype","(","0",")",",","scale=dtype","(","1",")",")","samples","=","tfp.mcmc.sample_chain","(","num_results=1000",",","current_state=dtype","(","1",")",",","kernel=tfp.mcmc.RandomWalkMetropolis","(","target.log_prob",")",",","num_burnin_steps=500",",","trace_fn=None",",","seed=42",")","sample_mean","=","tf.math.reduce_mean","(","samples",",","axis=0",")","sample_std","=","tf.sqrt","(","tf.math.reduce_mean","(","tf.math.squared_difference","(","samples",",","sample_mean",")",",","axis=0",")",")","print","(","'Estimated","mean",":","{","}","'.format","(","sample_mean",")",")","print","(","'Estimated","standard","deviation",":","{","}","'.format","(","sample_std",")",")","``","`","#","#","#","#","#","Sampling","from","a","2-D","Normal","Distribution",".","``","`","python","import","numpy","as","np","import","tensorflow.compat.v2","as","tf","import","tensorflow_probability","as","tfp","tfd","=","tfp.distributions","dtype","=","np.float32","true_mean","=","dtype","(","[","0",",","0","]",")","true_cov","=","dtype","(","[","[","1",",","0.5","]",",","[","0.5",",","1","]","]",")","num_results","=","500","num_chains","=","100","#","Target","distribution","is","defined","through","the","Cholesky","decomposition","`","L","`",":","L","=","tf.linalg.cholesky","(","true_cov",")","target","=","tfd.MultivariateNormalTriL","(","loc=true_mean",",","scale_tril=L",")","#","Initial","state","of","the","chain","init_state","=","np.ones","(","[","num_chains",",","2","]",",","dtype=dtype",")","#","Run","Random","Walk","Metropolis","with","normal","proposal","for","`","num_results","`","#","iterations","for","`","num_chains","`","independent","chains",":","samples","=","tfp.mcmc.sample_chain","(","num_results=num_results",",","current_state=init_state",",","kernel=tfp.mcmc.RandomWalkMetropolis","(","target_log_prob_fn=target.log_prob",")",",","num_burnin_steps=200",",","num_steps_between_results=1",",","#","Thinning",".","trace_fn=None",",","seed=54",")","sample_mean","=","tf.math.reduce_mean","(","samples",",","axis=0",")","x","=","tf.squeeze","(","samples","-","sample_mean",")","sample_cov","=","tf.matmul","(","tf.transpose","(","x",",","[","1",",","2",",","0","]",")",",","tf.transpose","(","x",",","[","1",",","0",",","2","]",")",")","\/","num_results","mean_sample_mean","=","tf.math.reduce_mean","(","sample_mean",")","mean_sample_cov","=","tf.math.reduce_mean","(","sample_cov",",","axis=0",")","x","=","tf.reshape","(","sample_cov","-","mean_sample_cov",",","[","num_chains",",","2","*","2","]",")","cov_sample_cov","=","tf.reshape","(","tf.matmul","(","x",",","x",",","transpose_a=True",")","\/","num_chains",",","shape=","[","2","*","2",",","2","*","2","]",")","print","(","'Estimated","mean",":","{","}","'.format","(","mean_sample_mean",")",")","print","(","'Estimated","avg","covariance",":","{","}","'.format","(","mean_sample_cov",")",")","print","(","'Estimated","covariance","of","covariance",":","{","}","'.format","(","cov_sample_cov",")",")","``","`","#","#","#","#","#","Sampling","from","the","Standard","Normal","Distribution","using","Cauchy","proposal",".","``","`","python","import","numpy","as","np","import","tensorflow.compat.v2","as","tf","import","tensorflow_probability","as","tfp","tfd","=","tfp.distributions","dtype","=","np.float32","num_burnin_steps","=","500","num_chain_results","=","1000","def","cauchy_new_state_fn","(","scale",",","dtype",")",":","cauchy","=","tfd.Cauchy","(","loc=dtype","(","0",")",",","scale=dtype","(","scale",")",")","def","_fn","(","state_parts",",","seed",")",":","next_state_parts","=","[","]","part_seeds","=","tfp.random.split_seed","(","seed",",","n=len","(","state_parts",")",",","salt='rwmcauchy","'",")","for","sp",",","ps","in","zip","(","state_parts",",","part_seeds",")",":","next_state_parts.append","(","sp","+","cauchy.sample","(","sample_shape=sp.shape",",","seed=ps",")",")","return","next_state_parts","return","_fn","target","=","tfd.Normal","(","loc=dtype","(","0",")",",","scale=dtype","(","1",")",")","samples","=","tfp.mcmc.sample_chain","(","num_results=num_chain_results",",","num_burnin_steps=num_burnin_steps",",","current_state=dtype","(","1",")",",","kernel=tfp.mcmc.RandomWalkMetropolis","(","target.log_prob",",","new_state_fn=cauchy_new_state_fn","(","scale=0.5",",","dtype=dtype",")",")",",","trace_fn=None",",","seed=42",")","sample_mean","=","tf.math.reduce_mean","(","samples",",","axis=0",")","sample_std","=","tf.sqrt","(","tf.math.reduce_mean","(","tf.math.squared_difference","(","samples",",","sample_mean",")",",","axis=0",")",")","print","(","'Estimated","mean",":","{","}","'.format","(","sample_mean",")",")","print","(","'Estimated","standard","deviation",":","{","}","'.format","(","sample_std",")",")","``","`"]
code: def is_calibrated(self):
      return True
  
imports: import collections
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import distribute_lib
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.mcmc import kernel
  from tensorflow_probability.python.mcmc import metropolis_hastings
  from tensorflow_probability.python.mcmc.internal import util
label_desc: Use image node_id 5 for calling the RandomWalkMetropolis obj's underlying member method code with example usage: obj.is_calibrated() and returns: True