class_docstr: Equivalent to IncrementalClassifier but using the cosine layer
  described in "Learning a Unified Classifier Incrementally via Rebalancing"
  by Saihui Hou et al.
class_docstr_tok: ["Equivalent","to","IncrementalClassifier","but","using","the","cosine","layer","described","in","``","Learning","a","Unified","Classifier","Incrementally","via","Rebalancing","''","by","Saihui","Hou","et","al","."]
code: def adaptation(self, experience):
      num_classes = len(experience.classes_in_this_experience)
  
      new_classes = set(experience.classes_in_this_experience) - set(
          self.classes
      )
  
      if len(new_classes) == 0:
          # Do not adapt
          return
  
      self.classes = self.classes.union(new_classes)
  
      for c in list(new_classes):
          self.class_order.append(c)
  
      max_index = len(self.class_order)
  
      if self.fc is None:
          self.fc = CosineLinear(
              self.feature_dim, max_index, sigma=True
          )
          return
  
      fc = self._generate_fc(self.feature_dim, max_index)
  
      if isinstance(self.fc, CosineLinear):
          # First exp self.fc is CosineLinear
          # while it is SplitCosineLinear for subsequent exps
          fc.fc1.weight.data = self.fc.weight.data
          fc.sigma.data = self.fc.sigma.data
      elif isinstance(self.fc, SplitCosineLinear):
          prev_out_features1 = self.fc.fc1.out_features
          fc.fc1.weight.data[
              :prev_out_features1
          ] = self.fc.fc1.weight.data
          fc.fc1.weight.data[
              prev_out_features1:
          ] = self.fc.fc2.weight.data
          fc.sigma.data = self.fc.sigma.data
  
      del self.fc
      self.fc = fc
  
imports: import math
  import torch
  import torch.nn
  import torch.nn.functional
  import numpy
  from avalanche.models import DynamicModule
label_desc: Use image node_id 2 for calling the CosineIncrementalClassifier obj's underlying member method code with example usage: obj.adaptation(experience) without return types