class_docstr: Expected Calibration Error (ECE)
  
  Args:
      n_cls (int): number of existing target classes
      n_bins (int): number of bins to discretize the uncertainty.
  
  References:
      https://arxiv.org/pdf/1706.04599.pdf
class_docstr_tok: ["Expected","Calibration","Error","(","ECE",")","Args",":","n_cls","(","int",")",":","number","of","existing","target","classes","n_bins","(","int",")",":","number","of","bins","to","discretize","the","uncertainty",".","References",":","https",":","\/\/arxiv.org\/pdf\/1706.04599.pdf"]
docstr: calculates the ece per class.
  
  Returns:
      ece (nd.array): ece value per class
docstr_tok: ["calculates","the","ece","per","class",".","Returns",":","ece","(","nd.array",")",":","ece","value","per","class"]
code: def calculate_result(self):
      """calculates the ece per class.
  
      Returns:
          ece (nd.array): ece value per class
      """
      accuracy = self._acc()
      ece = np.zeros([self.n_cls])
      for cls in range(self.n_cls):
          n = self.samples[cls, :].sum()
          if n == 0:
              ece[cls] = 0
          else:
              bin_confidence = self.conf_agg[cls] / np.maximum(
                  1, self.samples[cls]
              )
              diff_accuracy = np.abs(accuracy[cls, :] - bin_confidence)
              ece[cls] = (
                  (self.samples[cls, :] / n) * diff_accuracy
              ).sum()
      return ece
  
imports: import dataclasses
  import math
  import warnings
  from collections import defaultdict
  import numpy
  import torch
  from sklearn.metrics import confusion_matrix, auc
  from baal.utils.array_utils import to_prob
label_desc: Use image node_id 4 for calling the ECE_PerCLs obj's underlying member method code with example usage: obj.calculate_result() and returns: ece