class_docstr: <a id="TrackStatistics"></a>
  
  ### Track statistics
  
  This module computes statistics and tracks them with [labml `tracker`](https://docs.labml.ai/api/tracker.html).
class_docstr_tok: ["<","a","id=","''","TrackStatistics","''",">","<","\/a",">","#","#","#","Track","statistics","This","module","computes","statistics","and","tracks","them","with","[","labml","`","tracker","`","]","(","https",":","\/\/docs.labml.ai\/api\/tracker.html",")","."]
code: def forward(self, evidence: torch.Tensor, target: torch.Tensor):
      # Number of classes
      n_classes = evidence.shape[-1]
      # Predictions that correctly match with the target (greedy sampling based on highest probability)
      match = evidence.argmax(dim=-1).eq(target.argmax(dim=-1))
      # Track accuracy
      tracker.add("accuracy.", match.sum() / match.shape[0])
  
      # $\textcolor{orange}{\alpha_k} = e_k + 1$
      alpha = evidence + 1.0
      # $S = \sum_{k=1}^K \textcolor{orange}{\alpha_k}$
      strength = alpha.sum(dim=-1)
  
      # $\hat{p}_k = \frac{\textcolor{orange}{\alpha_k}}{S}$
      expected_probability = alpha / strength[:, None]
      # Expected probability of the selected (greedy highset probability) class
      expected_probability, _ = expected_probability.max(dim=-1)
  
      # Uncertainty mass $u = \frac{K}{S}$
      uncertainty_mass = n_classes / strength
  
      # Track $u$ for correctly predictions
      tracker.add("u.succ.", uncertainty_mass.masked_select(match))
      # Track $u$ for incorrect predictions
      tracker.add("u.fail.", uncertainty_mass.masked_select(~match))
      # Track $\hat{p}_k$ for correctly predictions
      tracker.add(
          "prob.succ.", expected_probability.masked_select(match)
      )
      # Track $\hat{p}_k$ for incorrect predictions
      tracker.add(
          "prob.fail.", expected_probability.masked_select(~match)
      )
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/uncertainty/evidence/__init__.py
imports: import torch
  from labml import tracker
  from labml_helpers.module import Module
label_desc: Use image node_id 1 for calling the TrackStatistics obj's underlying member method code with example usage: obj.forward(evidence, target) without return types