code: def test_ece():
      ece_calculator = ECE(n_bins=3)
  
      # start with multiclass classification
      pred = torch.FloatTensor([[-40, 50, 10], [10, 80, 10]])
      target = torch.LongTensor([[2], [1]])
  
      for i in range(2):
          ece_calculator.update(
              output=pred[i, :].unsqueeze(0),
              target=target[i, :].unsqueeze(0),
          )
  
      assert np.allclose(ece_calculator.samples, [0, 0, 2])
      assert np.allclose(ece_calculator.tp, [0, 0, 1])
      assert round(ece_calculator.value, 2) == 0.5
  
      pth = "tmp"
      Path(pth).mkdir(exist_ok=True)
      ece_calculator.plot(pth=os.path.join(pth, "figure.png"))
      assert os.path.exists(os.path.join(pth, "figure.png"))
      shutil.rmtree(pth)
  
      ece_calculator.reset()
  
      # start with multiclass classification
      pred = torch.FloatTensor([[0.4, 0.5, 0.1], [0.1, 0.8, 0.1]])
      target = torch.LongTensor([[2], [1]])
  
      for i in range(2):
          ece_calculator.update(
              output=pred[i, :].unsqueeze(0),
              target=target[i, :].unsqueeze(0),
          )
  
      assert np.allclose(ece_calculator.samples, [0, 1, 1])
      assert np.allclose(ece_calculator.tp, [0, 0, 1])
      assert np.allclose(
          ece_calculator.conf_agg, np.array([0.0, 0.5, 0.8])
      )
      assert round(ece_calculator.value, 2) == 0.35
  
imports: import os
  from pathlib import Path
  import numpy
  import pytest
  import shutil
  import torch
  from hypothesis import given
  from torch_hypothesis import classification_logits_and_labels
  from baal.utils.metrics import Loss, Accuracy, Precision, ECE, ClassificationReport, PRAuC, ECE_PerCLs
label_desc: Use image node_id 11 for calling a global function with example usage: test_ece() without return types