class_docstr: Densely-connected layer class with reparameterization estimator.
  
  This layer implements the Bayesian variational inference analogue to
  a dense layer by assuming the `kernel` and/or the `bias` are drawn
  from distributions. By default, the layer implements a stochastic
  forward pass via sampling from the kernel and bias posteriors,
  
  ```none
  kernel, bias ~ posterior
  outputs = activation(matmul(inputs, kernel) + bias)
  ```
  
  It uses the reparameterization estimator [(Kingma and Welling, 2014)][1],
  which performs a Monte Carlo approximation of the distribution integrating
  over the `kernel` and `bias`.
  
  The arguments permit separate specification of the surrogate posterior
  (`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
  distributions.
  
  Upon being built, this layer adds losses (accessible via the `losses`
  property) representing the divergences of `kernel` and/or `bias` surrogate
  posteriors and their respective priors. When doing minibatch stochastic
  optimization, make sure to scale this loss such that it is applied just once
  per epoch (e.g. if `kl` is the sum of `losses` for each element of the batch,
  you should pass `kl / num_examples_per_epoch` to your optimizer).
  
  You can access the `kernel` and/or `bias` posterior and prior distributions
  after the layer is built via the `kernel_posterior`, `kernel_prior`,
  `bias_posterior` and `bias_prior` properties.
  
  #### Examples
  
  We illustrate a Bayesian neural network with [variational inference](
  https://en.wikipedia.org/wiki/Variational_Bayesian_methods),
  assuming a dataset of `features` and `labels`.
  
  ```python
  import tensorflow as tf
  import tensorflow_probability as tfp
  
  model = tf_keras.Sequential([
      tfp.layers.DenseReparameterization(512, activation=tf.nn.relu),
      tfp.layers.DenseReparameterization(10),
  ])
  
  logits = model(features)
  neg_log_likelihood = tf.nn.softmax_cross_entropy_with_logits(
      labels=labels, logits=logits)
  kl = sum(model.losses)
  loss = neg_log_likelihood + kl
  train_op = tf.train.AdamOptimizer().minimize(loss)
  ```
  
  It uses reparameterization gradients to minimize the
  Kullback-Leibler divergence up to a constant, also known as the
  negative Evidence Lower Bound. It consists of the sum of two terms:
  the expected negative log-likelihood, which we approximate via
  Monte Carlo; and the KL divergence, which is added via regularizer
  terms which are arguments to the layer.
  
  #### References
  
  [1]: Diederik Kingma and Max Welling. Auto-Encoding Variational Bayes. In
       _International Conference on Learning Representations_, 2014.
       https://arxiv.org/abs/1312.6114
docstr: Construct layer.
  
  Args:
    ${args}
docstr_tok: ["Construct","layer",".","Args",":","$","{","args","}"]
code: def __init__(
      self,
      units,
      activation=None,
      activity_regularizer=None,
      trainable=True,
      kernel_posterior_fn=tfp_layers_util.default_mean_field_normal_fn(),
      kernel_posterior_tensor_fn=lambda d: d.sample(),
      kernel_prior_fn=tfp_layers_util.default_multivariate_normal_fn,
      kernel_divergence_fn=lambda q, p, ignore: kl_lib.kl_divergence(
          q, p
      ),
      bias_posterior_fn=tfp_layers_util.default_mean_field_normal_fn(
          is_singular=True
      ),
      bias_posterior_tensor_fn=lambda d: d.sample(),
      bias_prior_fn=None,
      bias_divergence_fn=lambda q, p, ignore: kl_lib.kl_divergence(
          q, p
      ),
      **kwargs,
  ):
      # pylint: disable=g-doc-args
      """Construct layer.
  
      Args:
        ${args}
      """
      # pylint: enable=g-doc-args
      super(DenseReparameterization, self).__init__(
          units=units,
          activation=activation,
          activity_regularizer=activity_regularizer,
          trainable=trainable,
          kernel_posterior_fn=kernel_posterior_fn,
          kernel_posterior_tensor_fn=kernel_posterior_tensor_fn,
          kernel_prior_fn=kernel_prior_fn,
          kernel_divergence_fn=kernel_divergence_fn,
          bias_posterior_fn=bias_posterior_fn,
          bias_posterior_tensor_fn=bias_posterior_tensor_fn,
          bias_prior_fn=bias_prior_fn,
          bias_divergence_fn=bias_divergence_fn,
          **kwargs,
      )
  
imports: import tensorflow.compat.v2
  from tensorflow_probability.python import random
  from tensorflow_probability.python.distributions import independent
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.internal import docstring_util
  from tensorflow_probability.python.internal import tf_keras
  from tensorflow_probability.python.layers import util
  from tensorflow_probability.python.util import SeedStream
label_desc: Use image node_id 1 to create a new DenseReparameterization object from inherited base classes: _DenseVariational with example: obj = DenseReparameterization(units, activation, activity_regularizer, trainable, kernel_posterior_fn, kernel_posterior_tensor_fn, kernel_prior_fn, kernel_divergence_fn, bias_posterior_fn, bias_posterior_tensor_fn, bias_prior_fn, bias_divergence_fn)