class_docstr: Dense layer with random `kernel` and `bias`.
  
  This layer uses variational inference to fit a "surrogate" posterior to the
  distribution over both the `kernel` matrix and the `bias` terms which are
  otherwise used in a manner similar to `tf_keras.layers.Dense`.
  
  This layer fits the "weights posterior" according to the following generative
  process:
  
  ```none
  [K, b] ~ Prior()
  M = matmul(X, K) + b
  Y ~ Likelihood(M)
  ```
docstr: Creates the `DenseVariational` layer.
  
  Args:
    units: Positive integer, dimensionality of the output space.
    make_posterior_fn: Python callable taking `tf.size(kernel)`,
      `tf.size(bias)`, `dtype` and returns another callable which takes an
      input and produces a `tfd.Distribution` instance.
    make_prior_fn: Python callable taking `tf.size(kernel)`, `tf.size(bias)`,
      `dtype` and returns another callable which takes an input and produces a
      `tfd.Distribution` instance.
    kl_weight: Amount by which to scale the KL divergence loss between prior
      and posterior.
    kl_use_exact: Python `bool` indicating that the analytical KL divergence
      should be used rather than a Monte Carlo approximation.
    activation: Activation function to use.
      If you don't specify anything, no activation is applied
      (ie. "linear" activation: `a(x) = x`).
    use_bias: Boolean, whether the layer uses a bias vector.
    activity_regularizer: Regularizer function applied to
      the output of the layer (its "activation")..
    **kwargs: Extra arguments forwarded to `tf_keras.layers.Layer`.
docstr_tok: ["Creates","the","`","DenseVariational","`","layer",".","Args",":","units",":","Positive","integer",",","dimensionality","of","the","output","space",".","make_posterior_fn",":","Python","callable","taking","`","tf.size","(","kernel",")","`",",","`","tf.size","(","bias",")","`",",","`","dtype","`","and","returns","another","callable","which","takes","an","input","and","produces","a","`","tfd.Distribution","`","instance",".","make_prior_fn",":","Python","callable","taking","`","tf.size","(","kernel",")","`",",","`","tf.size","(","bias",")","`",",","`","dtype","`","and","returns","another","callable","which","takes","an","input","and","produces","a","`","tfd.Distribution","`","instance",".","kl_weight",":","Amount","by","which","to","scale","the","KL","divergence","loss","between","prior","and","posterior",".","kl_use_exact",":","Python","`","bool","`","indicating","that","the","analytical","KL","divergence","should","be","used","rather","than","a","Monte","Carlo","approximation",".","activation",":","Activation","function","to","use",".","If","you","do","n't","specify","anything",",","no","activation","is","applied","(","ie",".","``","linear","''","activation",":","`","a","(","x",")","=","x","`",")",".","use_bias",":","Boolean",",","whether","the","layer","uses","a","bias","vector",".","activity_regularizer",":","Regularizer","function","applied","to","the","output","of","the","layer","(","its","``","activation","''",")","..","*","*","kwargs",":","Extra","arguments","forwarded","to","`","tf_keras.layers.Layer","`","."]
code: def __init__(
      self,
      units,
      make_posterior_fn,
      make_prior_fn,
      kl_weight=None,
      kl_use_exact=False,
      activation=None,
      use_bias=True,
      activity_regularizer=None,
      **kwargs,
  ):
      """Creates the `DenseVariational` layer.
  
      Args:
        units: Positive integer, dimensionality of the output space.
        make_posterior_fn: Python callable taking `tf.size(kernel)`,
          `tf.size(bias)`, `dtype` and returns another callable which takes an
          input and produces a `tfd.Distribution` instance.
        make_prior_fn: Python callable taking `tf.size(kernel)`, `tf.size(bias)`,
          `dtype` and returns another callable which takes an input and produces a
          `tfd.Distribution` instance.
        kl_weight: Amount by which to scale the KL divergence loss between prior
          and posterior.
        kl_use_exact: Python `bool` indicating that the analytical KL divergence
          should be used rather than a Monte Carlo approximation.
        activation: Activation function to use.
          If you don't specify anything, no activation is applied
          (ie. "linear" activation: `a(x) = x`).
        use_bias: Boolean, whether the layer uses a bias vector.
        activity_regularizer: Regularizer function applied to
          the output of the layer (its "activation")..
        **kwargs: Extra arguments forwarded to `tf_keras.layers.Layer`.
      """
      if "input_shape" not in kwargs and "input_dim" in kwargs:
          kwargs["input_shape"] = (kwargs.pop("input_dim"),)
      super(DenseVariational, self).__init__(
          activity_regularizer=tf_keras.regularizers.get(
              activity_regularizer
          ),
          **kwargs,
      )
      self.units = int(units)
  
      self._make_posterior_fn = make_posterior_fn
      self._make_prior_fn = make_prior_fn
      self._kl_divergence_fn = _make_kl_divergence_penalty(
          kl_use_exact, weight=kl_weight
      )
  
      self.activation = tf_keras.activations.get(activation)
      self.use_bias = use_bias
      self.supports_masking = False
      self.input_spec = tf_keras.layers.InputSpec(min_ndim=2)
  
file_path: probability/tensorflow_probability/python/layers/dense_variational_v2.py
imports: import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.internal import tf_keras
label_desc: Use image node_id 1 to create a new DenseVariational object from inherited base classes: tf_keras.layers with example: obj = DenseVariational(units, make_posterior_fn, make_prior_fn, kl_weight, kl_use_exact, activation, use_bias, activity_regularizer)