class_docstr: Retrospective Adversarial Replay for Continual Learning
  https://openreview.net/forum?id=XEoih0EwCwL
  Continual learning is an emerging research challenge in machine learning
  that addresses the problem where models quickly fit the most recently
  trained-on data and are prone to catastrophic forgetting due to
  distribution shifts --- it does this by maintaining a small historical
  replay buffer in replay-based methods.
  To avoid these problems, this paper proposes a method,
  ``Retrospective Adversarial Replay (RAR)'', that synthesizes adversarial
  samples near the forgetting boundary. RAR perturbs a buffered sample
  towards its nearest neighbor drawn from the current task in a latent
  representation space. By replaying such samples, we are able to refine the
  boundary between previous and current tasks, hence combating forgetting and
  reducing bias towards the current task. To mitigate the severity of a small
  replay buffer, we develop a novel MixUp-based strategy to increase replay
  variation by replaying mixed augmentations.
  Combined with RAR, this achieves a holistic framework that helps to
  alleviate catastrophic forgetting. We show that this excels on
  broadly-used benchmarks and outperforms other continual learning baselines
  especially when only a small buffer is used. We conduct a thorough
  ablation study over each key component as well as a hyperparameter
  sensitivity analysis to demonstrate the effectiveness and robustness of RAR.
class_docstr_tok: ["Retrospective","Adversarial","Replay","for","Continual","Learning","https",":","\/\/openreview.net\/forum","?","id=XEoih0EwCwL","Continual","learning","is","an","emerging","research","challenge","in","machine","learning","that","addresses","the","problem","where","models","quickly","fit","the","most","recently","trained-on","data","and","are","prone","to","catastrophic","forgetting","due","to","distribution","shifts","--","-","it","does","this","by","maintaining","a","small","historical","replay","buffer","in","replay-based","methods",".","To","avoid","these","problems",",","this","paper","proposes","a","method",",","``","Retrospective","Adversarial","Replay","(","RAR",")","''",",","that","synthesizes","adversarial","samples","near","the","forgetting","boundary",".","RAR","perturbs","a","buffered","sample","towards","its","nearest","neighbor","drawn","from","the","current","task","in","a","latent","representation","space",".","By","replaying","such","samples",",","we","are","able","to","refine","the","boundary","between","previous","and","current","tasks",",","hence","combating","forgetting","and","reducing","bias","towards","the","current","task",".","To","mitigate","the","severity","of","a","small","replay","buffer",",","we","develop","a","novel","MixUp-based","strategy","to","increase","replay","variation","by","replaying","mixed","augmentations",".","Combined","with","RAR",",","this","achieves","a","holistic","framework","that","helps","to","alleviate","catastrophic","forgetting",".","We","show","that","this","excels","on","broadly-used","benchmarks","and","outperforms","other","continual","learning","baselines","especially","when","only","a","small","buffer","is","used",".","We","conduct","a","thorough","ablation","study","over","each","key","component","as","well","as","a","hyperparameter","sensitivity","analysis","to","demonstrate","the","effectiveness","and","robustness","of","RAR","."]
docstr: FGSM - This function generate the perturbation to the input.
  
  :param input: Data that we want to apply the perturbation
  :param data_grad: Gradient of those samples
  
  :return: Attacked input
docstr_tok: ["FGSM","-","This","function","generate","the","perturbation","to","the","input",".",":","param","input",":","Data","that","we","want","to","apply","the","perturbation",":","param","data_grad",":","Gradient","of","those","samples",":","return",":","Attacked","input"]
code: def mifgsm_attack(self, input, data_grad):
      """
      FGSM - This function generate the perturbation to the input.
  
      :param input: Data that we want to apply the perturbation
      :param data_grad: Gradient of those samples
  
      :return: Attacked input
      """
      pert_out = input
      alpha = self.epsilon_fgsm / self.iter_fgsm
      g = 0
      for i in range(self.iter_fgsm - 1):
          g = self.decay_factor_fgsm * g + data_grad / torch.norm(
              data_grad, p=1
          )
          pert_out = pert_out + alpha * torch.sign(g)
          pert_out = torch.clamp(pert_out, 0, 1)
          if (
              torch.norm((pert_out - input), p=float("inf"))
              > self.epsilon_fgsm
          ):
              break
      return pert_out
  
file_path: avalanche/avalanche/training/plugins/rar.py
imports: import copy
  from typing import TYPE_CHECKING, Optional
  import numpy
  import torch
  from torch.optim import SGD
  from torch.utils.data.dataloader import DataLoader
  from torchvision.models.feature_extraction import get_graph_node_names, create_feature_extractor
  from avalanche.training.plugins.strategy_plugin import SupervisedPlugin
  from avalanche.training.storage_policy import ReservoirSamplingBuffer
  from avalanche.benchmarks.utils.data_loader import ReplayDataLoader
label_desc: Use image node_id 6 for calling the RARPlugin obj's underlying member method code with example usage: obj.mifgsm_attack(input, data_grad) and returns: pert_out