class_docstr: NCM Classifier.
  NCMClassifier performs nearest class mean classification
  measuring the distance between the input tensor and the
  ones stored in 'self.class_means'.
  
  Before being used for inference, NCMClassifier needs to
  be updated with a mean vector per class, by calling
  `update_class_means_dict`.
  
  This class registers a `class_means` buffer that stores
  the class means in a single tensor of shape
  [max_class_id_seen, feature_size]. Classes with ID smaller
  than `max_class_id_seen` are associated with a 0-vector.
docstr: Update dictionary of class means.
  If class already exists, the average of the two mean vectors
  will be computed.
  
  :param class_means_dict: a dictionary mapping class id
      to class mean tensor.
  :param momentum: Weighting of the new means vs old means
                   in the update. 1 = replace, 0 = don't update
docstr_tok: ["Update","dictionary","of","class","means",".","If","class","already","exists",",","the","average","of","the","two","mean","vectors","will","be","computed",".",":","param","class_means_dict",":","a","dictionary","mapping","class","id","to","class","mean","tensor",".",":","param","momentum",":","Weighting","of","the","new","means","vs","old","means","in","the","update",".","1","=","replace",",","0","=","do","n't","update"]
code: def update_class_means_dict(
      self, class_means_dict: Dict[int, Tensor], momentum: float = 0.5
  ):
      """
      Update dictionary of class means.
      If class already exists, the average of the two mean vectors
      will be computed.
  
      :param class_means_dict: a dictionary mapping class id
          to class mean tensor.
      :param momentum: Weighting of the new means vs old means
                       in the update. 1 = replace, 0 = don't update
      """
      assert momentum <= 1 and momentum >= 0
      assert isinstance(class_means_dict, dict), (
          "class_means_dict must be a dictionary mapping class_id "
          "to mean vector"
      )
      for k, v in class_means_dict.items():
          if (
              k not in self.class_means_dict
              or (self.class_means_dict[k] == 0).all()
          ):
              self.class_means_dict[k] = class_means_dict[k].clone()
          else:
              device = self.class_means_dict[k].device
              self.class_means_dict[k] = (
                  momentum * class_means_dict[k].to(device)
                  + (1 - momentum) * self.class_means_dict[k]
              )
  
      self._vectorize_means_dict()
  
file_path: avalanche/avalanche/models/ncm_classifier.py
imports: from typing import Dict
  import torch
  from torch import Tensor, nn
  from avalanche.models import DynamicModule
label_desc: Use image node_id 5 for calling the NCMClassifier obj's underlying member method code with example usage: obj.update_class_means_dict(class_means_dict, momentum) without return types