code: def testVarianceWhenProbCloseToOne(self):
      # Prob is very close to 1.0, so the naive 1 - p will be (numerically) 0,
      # which would make variance zero.  Main point of this test is to verify that
      # the variance is > 0 ... we also verify that variance is correct.
  
      # tf.sigmoid(logits) is < float eps away from 1.0, which means the naive
      # 1 - tf.sigmoid(logits) will result in 0.0, which is a loss of precision.
      one_minus_prob_64 = np.float64(np.finfo(np.float32).eps) / 2
      logits_32 = np.float32(
          np.log((1.0 - one_minus_prob_64) / one_minus_prob_64)
      )
  
      # Verify that this value of logits results in loss of precision for a naive
      # implementation (justifying our "fancy" implementation of sigmoid(-logits))
      self.assertAllEqual(0.0, 1 - tf.sigmoid(logits_32))
  
      # See! This one weird trick fixes everything.  Asserts below check that we
      # used the trick correctly in our code.
      self.assertGreater(self.evaluate(tf.sigmoid(-logits_32)), 0.0)
  
      dist = bernoulli.Bernoulli(logits=logits_32)
  
      expected_variance = np.float32(
          one_minus_prob_64 * (1 - one_minus_prob_64)
      )
  
      self.assertGreater(expected_variance, 0.0)
  
      self.assertAllClose(
          dist.variance(),
          expected_variance,
          # Equivalent to atol=0, rtol=1e-6, but less likely to confuse which
          # element is being used for the "r" in rtol.
          # Note this also ensures dist.variance() > 0, which the naive
          # implementation would not be able to do.
          atol=expected_variance * 1e-6,
          rtol=0,
      )
  
imports: import numpy
  from scipy import special
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import bernoulli
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math import gradient
label_desc: Use image node_id 21 for calling the BernoulliTest obj's underlying member method code with example usage: obj.testVarianceWhenProbCloseToOne() without return types