docstr: Test the accuracy of the estimated Brier decomposition.
docstr_tok: ["Test","the","accuracy","of","the","estimated","Brier","decomposition","."]
code: def test_brier_decomposition(self, temperature, nlabels, nsamples):
      """Test the accuracy of the estimated Brier decomposition."""
      tf.random.set_seed(1)
      seed_stream = test_util.test_seed_stream()
      logits = (
          tf.random.normal((nsamples, nlabels), seed=seed_stream())
          / temperature
      )
      labels = tf.random.uniform(
          (nsamples,),
          maxval=nlabels,
          seed=seed_stream(),
          dtype=tf.int32,
      )
  
      (
          uncertainty,
          resolution,
          reliability,
      ) = calibration.brier_decomposition(labels=labels, logits=logits)
  
      # Recover an estimate of the Brier score from the decomposition
      brier = uncertainty - resolution + reliability
  
      # Estimate Brier score directly
      brier_direct = calibration.brier_score(
          labels=labels, logits=logits
      )
      (
          uncertainty,
          resolution,
          reliability,
          brier,
          brier_direct,
      ) = self.evaluate(
          [
              uncertainty,
              resolution,
              reliability,
              brier,
              tf.reduce_mean(brier_direct, axis=0),
          ]
      )
  
      logging.info(
          "Brier, n=%d k=%d T=%.2f, Unc %.4f - Res %.4f + Rel %.4f = "
          "Brier %.4f,  Brier-direct %.4f",
          nsamples,
          nlabels,
          temperature,
          uncertainty,
          resolution,
          reliability,
          brier,
          brier_direct,
      )
  
      self.assertGreaterEqual(
          resolution, 0.0, msg="Brier resolution negative"
      )
      self.assertGreaterEqual(
          reliability, 0.0, msg="Brier reliability negative"
      )
      self.assertAlmostEqual(
          brier,
          brier_direct,
          delta=1.0e-1,
          msg="Brier from decomposition (%.4f) and Brier direct (%.4f) disagree "
          "beyond estimation error." % (brier, brier_direct),
      )
  
imports: import itertools
  from absl import logging
  from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import categorical
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.stats import calibration
label_desc: Use image node_id 1 for calling the CalibrationTest obj's underlying member method code with example usage: obj.test_brier_decomposition(temperature, nlabels, nsamples) without return types