class_docstr: Implements a location-scale heavy-tail Lambert W x Normal distribution.
class_docstr_tok: ["Implements","a","location-scale","heavy-tail","Lambert","W","x","Normal","distribution","."]
code: def _variance(self):
      tailweight = tf.convert_to_tensor(self.tailweight)
      scale = tf.convert_to_tensor(self.scale)
      # For tail < 0.5, the variance is finite. See Eq (18) in
      # https://www.hindawi.com/journals/tswj/2015/909231/
      var = tf.cast(
          tf.pow(1.0 - 2.0 * tailweight, -3.0 / 2.0), dtype=self.dtype
      ) * tf.math.square(scale)
      # We need to put the tf.where inside the outer tf.where to ensure we never
      # hit a NaN in the gradient.
      result_where_defined = tf.where(
          tailweight < 0.5,
          var,
          tf.convert_to_tensor(np.inf, dtype=self.dtype),
      )
  
      if self.allow_nan_stats:
          ans = tf.where(
              tailweight < 1.0,
              result_where_defined,
              tf.convert_to_tensor(np.nan, self.dtype),
          )
      else:
          ans = distribution_util.with_dependencies(
              [
                  assert_util.assert_greater_equal(
                      tf.ones([], dtype=self.dtype),
                      tailweight,
                      message="variance not defined for components of tailweight >= 1",
                  ),
              ],
              result_where_defined,
          )
      return tf.broadcast_to(ans, self._batch_shape_tensor())
  
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import identity
  from tensorflow_probability.python.bijectors import lambertw_transform
  from tensorflow_probability.python.bijectors import softplus
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.distributions import transformed_distribution
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import parameter_properties
  from tensorflow_probability.python.internal import tensor_util
label_desc: Use image node_id 5 for calling the LambertWNormal obj's underlying member method code with example usage: obj._variance() and returns: tf