class_docstr: Average Gradient Episodic Memory Plugin.
  
  AGEM projects the gradient on the current minibatch by using an external
  episodic memory of patterns from previous experiences. If the dot product
  between the current gradient and the (average) gradient of a randomly
  sampled set of memory examples is negative, the gradient is projected.
  This plugin does not use task identities.
class_docstr_tok: ["Average","Gradient","Episodic","Memory","Plugin",".","AGEM","projects","the","gradient","on","the","current","minibatch","by","using","an","external","episodic","memory","of","patterns","from","previous","experiences",".","If","the","dot","product","between","the","current","gradient","and","the","(","average",")","gradient","of","a","randomly","sampled","set","of","memory","examples","is","negative",",","the","gradient","is","projected",".","This","plugin","does","not","use","task","identities","."]
docstr: :param patterns_per_experience: number of patterns per experience in the
      memory.
  :param sample_size: number of patterns in memory sample when computing
      reference gradient.
docstr_tok: [":","param","patterns_per_experience",":","number","of","patterns","per","experience","in","the","memory",".",":","param","sample_size",":","number","of","patterns","in","memory","sample","when","computing","reference","gradient","."]
code: def __init__(self, patterns_per_experience: int, sample_size: int):
      """
      :param patterns_per_experience: number of patterns per experience in the
          memory.
      :param sample_size: number of patterns in memory sample when computing
          reference gradient.
      """
  
      super().__init__()
  
      self.patterns_per_experience = int(patterns_per_experience)
      self.sample_size = int(sample_size)
  
      # One AvalancheDataset for each experience
      self.buffers: List[AvalancheDataset] = []
      self.buffer_dataloader: Optional[
          GroupBalancedInfiniteDataLoader
      ] = None
      # Placeholder iterator to avoid typing issues
      self.buffer_dliter: Iterator[Any] = iter([])
      # Placeholder Tensor to avoid typing issues
      self.reference_gradients: Tensor = torch.empty(0)
  
file_path: avalanche/avalanche/training/plugins/agem.py
imports: import warnings
  import random
  from typing import Any, Iterator, List, Optional
  import torch
  from torch import Tensor
  from avalanche.benchmarks.utils import _make_taskaware_classification_dataset
  from avalanche.benchmarks.utils.data import AvalancheDataset
  from avalanche.benchmarks.utils.data_loader import GroupBalancedInfiniteDataLoader
  from avalanche.models import avalanche_forward
  from avalanche.training.plugins.strategy_plugin import SupervisedPlugin
label_desc: Use image node_id 1 to create a new AGEMPlugin object from inherited base classes: SupervisedPlugin with example: obj = AGEMPlugin(patterns_per_experience, sample_size)