class_docstr: Riemannian Walk (RWalk) plugin.
  RWalk computes the importance of each weight at the end of every training
  iteration, and updates each parameter's importance online using moving
  average. During training on each minibatch, the loss is augmented
  with a penalty which keeps the value of a parameter close to the
  value it had on previous experiences, proportional to a score that has
  high values if small changes cause large improvements in the loss.
  This plugin does not use task identities.
  
  .. note::
      To reproduce the results of the paper in class-incremental scenarios,
      this plug-in should be used in conjunction with a replay strategy
      (e.g., :class:`ReplayPlugin`).
class_docstr_tok: ["Riemannian","Walk","(","RWalk",")","plugin",".","RWalk","computes","the","importance","of","each","weight","at","the","end","of","every","training","iteration",",","and","updates","each","parameter","'s","importance","online","using","moving","average",".","During","training","on","each","minibatch",",","the","loss","is","augmented","with","a","penalty","which","keeps","the","value","of","a","parameter","close","to","the","value","it","had","on","previous","experiences",",","proportional","to","a","score","that","has","high","values","if","small","changes","cause","large","improvements","in","the","loss",".","This","plugin","does","not","use","task","identities",".","..","note",":",":","To","reproduce","the","results","of","the","paper","in","class-incremental","scenarios",",","this","plug-in","should","be","used","in","conjunction","with","a","replay","strategy","(","e.g.",",",":","class",":","`","ReplayPlugin","`",")","."]
docstr: :param ewc_lambda: hyperparameter to weigh the penalty inside the total
         loss. The larger the lambda, the larger the regularization.
  :param ewc_alpha: Specify the moving average factor for the importance
          matrix, as defined RWalk paper (a.k.a. EWC++). Higher values
          lead to higher weight to newly computed importances. Must be
          in [0, 1]. Defaults to 0.9.
  :param delta_t: Specify the iterations interval in which the parameter
          scores are updated. Defaults to 10.
docstr_tok: [":","param","ewc_lambda",":","hyperparameter","to","weigh","the","penalty","inside","the","total","loss",".","The","larger","the","lambda",",","the","larger","the","regularization",".",":","param","ewc_alpha",":","Specify","the","moving","average","factor","for","the","importance","matrix",",","as","defined","RWalk","paper","(","a.k.a",".","EWC++",")",".","Higher","values","lead","to","higher","weight","to","newly","computed","importances",".","Must","be","in","[","0",",","1","]",".","Defaults","to","0.9.",":","param","delta_t",":","Specify","the","iterations","interval","in","which","the","parameter","scores","are","updated",".","Defaults","to","10","."]
code: def __init__(
      self,
      ewc_lambda: float = 0.1,
      ewc_alpha: float = 0.9,
      delta_t: int = 10,
  ):
      """
      :param ewc_lambda: hyperparameter to weigh the penalty inside the total
             loss. The larger the lambda, the larger the regularization.
      :param ewc_alpha: Specify the moving average factor for the importance
              matrix, as defined RWalk paper (a.k.a. EWC++). Higher values
              lead to higher weight to newly computed importances. Must be
              in [0, 1]. Defaults to 0.9.
      :param delta_t: Specify the iterations interval in which the parameter
              scores are updated. Defaults to 10.
      """
  
      super().__init__()
  
      assert 0 <= ewc_alpha <= 1, "`ewc_alpha` must be in [0, 1]."
      assert delta_t >= 1, "`delta_t` must be at least 1."
  
      self.ewc_alpha = ewc_alpha
      self.ewc_lambda = ewc_lambda
      self.delta_t = delta_t
  
      # Information computed every delta_t
      self.checkpoint_params: Dict[str, ParamData] = dict()
      self.checkpoint_loss: Dict[str, ParamData] = dict()
  
      # Partial scores (s_t1^t2) computed incrementally every delta_t
      self.checkpoint_scores: Dict[str, ParamData] = dict()
  
      # Information stored at the beginning of every iteration
      self.iter_grad: Dict[str, ParamData] = dict()
      self.iter_importance: Optional[Dict[str, ParamData]] = None
      self.iter_params: Dict[str, ParamData] = dict()
  
      # Information stored at the end of every experience (t_k in the paper)
      self.exp_scores: Optional[Dict[str, ParamData]] = None
      self.exp_params: Optional[Dict[str, ParamData]] = None
      self.exp_importance: Optional[Dict[str, ParamData]] = None
      self.exp_penalties: Optional[Dict[str, ParamData]] = None
  
file_path: avalanche/avalanche/training/plugins/rwalk.py
imports: from typing import Dict, Optional
  import warnings
  import torch
  import torch.nn.functional
  from avalanche.training.plugins.strategy_plugin import SupervisedPlugin
  from avalanche.training.utils import copy_params_dict, zerolike_params_dict, ParamData
  from avalanche.models.utils import avalanche_forward
label_desc: Use image node_id 1 to create a new RWalkPlugin object from inherited base classes: SupervisedPlugin with example: obj = RWalkPlugin(ewc_lambda, ewc_alpha, delta_t)