class_docstr: Elastic Weight Consolidation (EWC) plugin.
  EWC computes importance of each weight at the end of training on current
  experience. During training on each minibatch, the loss is augmented
  with a penalty which keeps the value of the current weights close to the
  value they had on previous experiences in proportion to their importance
  on that experience. Importances are computed with an additional pass on the
  training set. This plugin does not use task identities.
docstr: :param ewc_lambda: hyperparameter to weigh the penalty inside the total
         loss. The larger the lambda, the larger the regularization.
  :param mode: `separate` to keep a separate penalty for each previous
         experience.
         `online` to keep a single penalty summed with a decay factor
         over all previous tasks.
  :param decay_factor: used only if mode is `online`.
         It specifies the decay term of the importance matrix.
  :param keep_importance_data: if True, keep in memory both parameter
          values and importances for all previous task, for all modes.
          If False, keep only last parameter values and importances.
          If mode is `separate`, the value of `keep_importance_data` is
          set to be True.
docstr_tok: [":","param","ewc_lambda",":","hyperparameter","to","weigh","the","penalty","inside","the","total","loss",".","The","larger","the","lambda",",","the","larger","the","regularization",".",":","param","mode",":","`","separate","`","to","keep","a","separate","penalty","for","each","previous","experience",".","`","online","`","to","keep","a","single","penalty","summed","with","a","decay","factor","over","all","previous","tasks",".",":","param","decay_factor",":","used","only","if","mode","is","`","online","`",".","It","specifies","the","decay","term","of","the","importance","matrix",".",":","param","keep_importance_data",":","if","True",",","keep","in","memory","both","parameter","values","and","importances","for","all","previous","task",",","for","all","modes",".","If","False",",","keep","only","last","parameter","values","and","importances",".","If","mode","is","`","separate","`",",","the","value","of","`","keep_importance_data","`","is","set","to","be","True","."]
code: def __init__(
      self,
      ewc_lambda,
      mode="separate",
      decay_factor=None,
      keep_importance_data=False,
  ):
      """
      :param ewc_lambda: hyperparameter to weigh the penalty inside the total
             loss. The larger the lambda, the larger the regularization.
      :param mode: `separate` to keep a separate penalty for each previous
             experience.
             `online` to keep a single penalty summed with a decay factor
             over all previous tasks.
      :param decay_factor: used only if mode is `online`.
             It specifies the decay term of the importance matrix.
      :param keep_importance_data: if True, keep in memory both parameter
              values and importances for all previous task, for all modes.
              If False, keep only last parameter values and importances.
              If mode is `separate`, the value of `keep_importance_data` is
              set to be True.
      """
  
      super().__init__()
      assert (decay_factor is None) or (
          mode == "online"
      ), "You need to set `online` mode to use `decay_factor`."
      assert (decay_factor is not None) or (
          mode != "online"
      ), "You need to set `decay_factor` to use the `online` mode."
      assert (
          mode == "separate" or mode == "online"
      ), "Mode must be separate or online."
  
      self.ewc_lambda = ewc_lambda
      self.mode = mode
      self.decay_factor = decay_factor
  
      if self.mode == "separate":
          self.keep_importance_data = True
      else:
          self.keep_importance_data = keep_importance_data
  
      self.saved_params: Dict[int, Dict[str, ParamData]] = defaultdict(
          dict
      )
      self.importances: Dict[int, Dict[str, ParamData]] = defaultdict(
          dict
      )
  
file_path: avalanche/avalanche/training/plugins/ewc.py
imports: from collections import defaultdict
  from typing import Dict, Tuple, Union
  import warnings
  import itertools
  import torch
  from torch.utils.data import DataLoader
  from avalanche.models.utils import avalanche_forward
  from avalanche.training.plugins.strategy_plugin import SupervisedPlugin
  from avalanche.training.utils import copy_params_dict, zerolike_params_dict, ParamData
label_desc: Use image node_id 1 to create a new EWCPlugin object from inherited base classes: SupervisedPlugin with example: obj = EWCPlugin(ewc_lambda, mode, decay_factor, keep_importance_data)