class_docstr: Deep Streaming Linear Discriminant Analysis.
  
  This strategy does not use backpropagation.
  Minibatches are first passed to the pretrained feature extractor.
  The result is processed one element at a time to fit the LDA.
  Original paper:
  "Hayes et. al., Lifelong Machine Learning with Deep Streaming Linear
  Discriminant Analysis, CVPR Workshop, 2020"
  https://openaccess.thecvf.com/content_CVPRW_2020/papers/w15/Hayes_Lifelong_Machine_Learning_With_Deep_Streaming_Linear_Discriminant_Analysis_CVPRW_2020_paper.pdf
class_docstr_tok: ["Deep","Streaming","Linear","Discriminant","Analysis",".","This","strategy","does","not","use","backpropagation",".","Minibatches","are","first","passed","to","the","pretrained","feature","extractor",".","The","result","is","processed","one","element","at","a","time","to","fit","the","LDA",".","Original","paper",":","''","Hayes","et",".","al.",",","Lifelong","Machine","Learning","with","Deep","Streaming","Linear","Discriminant","Analysis",",","CVPR","Workshop",",","2020","''","https",":","\/\/openaccess.thecvf.com\/content_CVPRW_2020\/papers\/w15\/Hayes_Lifelong_Machine_Learning_With_Deep_Streaming_Linear_Discriminant_Analysis_CVPRW_2020_paper.pdf"]
docstr: Init function for the SLDA model.
  
  :param slda_model: a PyTorch model
  :param criterion: loss function
  :param output_layer_name: if not None, wrap model to retrieve
      only the `output_layer_name` output. If None, the strategy
      assumes that the model already produces a valid output.
      You can use `FeatureExtractorBackbone` class to create your custom
      SLDA-compatible model.
  :param input_size: feature dimension
  :param num_classes: number of total classes in stream
  :param train_mb_size: batch size for feature extractor during
      training. Fit will be called on a single pattern at a time.
  :param eval_mb_size: batch size for inference
  :param shrinkage_param: value of the shrinkage parameter
  :param streaming_update_sigma: True if sigma is plastic else False
      feature extraction in `self.feature_extraction_wrapper`.
  :param plugins: list of StrategyPlugins
  :param evaluator: Evaluation Plugin instance
  :param eval_every: run eval every `eval_every` epochs.
      See `BaseTemplate` for details.
docstr_tok: ["Init","function","for","the","SLDA","model",".",":","param","slda_model",":","a","PyTorch","model",":","param","criterion",":","loss","function",":","param","output_layer_name",":","if","not","None",",","wrap","model","to","retrieve","only","the","`","output_layer_name","`","output",".","If","None",",","the","strategy","assumes","that","the","model","already","produces","a","valid","output",".","You","can","use","`","FeatureExtractorBackbone","`","class","to","create","your","custom","SLDA-compatible","model",".",":","param","input_size",":","feature","dimension",":","param","num_classes",":","number","of","total","classes","in","stream",":","param","train_mb_size",":","batch","size","for","feature","extractor","during","training",".","Fit","will","be","called","on","a","single","pattern","at","a","time",".",":","param","eval_mb_size",":","batch","size","for","inference",":","param","shrinkage_param",":","value","of","the","shrinkage","parameter",":","param","streaming_update_sigma",":","True","if","sigma","is","plastic","else","False","feature","extraction","in","`","self.feature_extraction_wrapper","`",".",":","param","plugins",":","list","of","StrategyPlugins",":","param","evaluator",":","Evaluation","Plugin","instance",":","param","eval_every",":","run","eval","every","`","eval_every","`","epochs",".","See","`","BaseTemplate","`","for","details","."]
code: def __init__(
      self,
      slda_model,
      criterion,
      input_size,
      num_classes,
      output_layer_name=None,
      shrinkage_param=1e-4,
      streaming_update_sigma=True,
      train_epochs: int = 1,
      train_mb_size: int = 1,
      eval_mb_size: int = 1,
      device: Union[str, torch.device] = "cpu",
      plugins: Optional[Sequence["SupervisedPlugin"]] = None,
      evaluator: Union[
          EvaluationPlugin, Callable[[], EvaluationPlugin]
      ] = default_evaluator,
      eval_every=-1,
  ):
      """Init function for the SLDA model.
  
      :param slda_model: a PyTorch model
      :param criterion: loss function
      :param output_layer_name: if not None, wrap model to retrieve
          only the `output_layer_name` output. If None, the strategy
          assumes that the model already produces a valid output.
          You can use `FeatureExtractorBackbone` class to create your custom
          SLDA-compatible model.
      :param input_size: feature dimension
      :param num_classes: number of total classes in stream
      :param train_mb_size: batch size for feature extractor during
          training. Fit will be called on a single pattern at a time.
      :param eval_mb_size: batch size for inference
      :param shrinkage_param: value of the shrinkage parameter
      :param streaming_update_sigma: True if sigma is plastic else False
          feature extraction in `self.feature_extraction_wrapper`.
      :param plugins: list of StrategyPlugins
      :param evaluator: Evaluation Plugin instance
      :param eval_every: run eval every `eval_every` epochs.
          See `BaseTemplate` for details.
      """
  
      if plugins is None:
          plugins = []
  
      slda_model = slda_model.eval()
      if output_layer_name is not None:
          slda_model = FeatureExtractorBackbone(
              slda_model.to(device), output_layer_name
          ).eval()
  
      super(StreamingLDA, self).__init__(
          slda_model,
          None,  # type: ignore
          criterion,
          train_mb_size,
          train_epochs,
          eval_mb_size,
          device=device,
          plugins=plugins,
          evaluator=evaluator,
          eval_every=eval_every,
      )
  
      # SLDA parameters
      self.input_size = input_size
      self.shrinkage_param = shrinkage_param
      self.streaming_update_sigma = streaming_update_sigma
  
      # setup weights for SLDA
      self.muK = torch.zeros((num_classes, input_size)).to(self.device)
      self.cK = torch.zeros(num_classes).to(self.device)
      self.Sigma = torch.ones((input_size, input_size)).to(self.device)
      self.num_updates = 0
      self.Lambda = torch.zeros_like(self.Sigma).to(self.device)
      self.prev_num_updates = -1
  
imports: import warnings
  from typing import Callable, Optional, Sequence, Union
  import os
  import torch
  from avalanche.training.plugins import SupervisedPlugin
  from avalanche.training.templates import SupervisedTemplate
  from avalanche.training.plugins.evaluation import EvaluationPlugin, default_evaluator
  from avalanche.models.dynamic_modules import MultiTaskModule
  from avalanche.models import FeatureExtractorBackbone
label_desc: Use image node_id 1 to create a new StreamingLDA object from inherited base classes: SupervisedTemplate with example: obj = StreamingLDA(slda_model, criterion, input_size, num_classes, output_layer_name, shrinkage_param, streaming_update_sigma, train_epochs, train_mb_size, eval_mb_size, device, plugins, evaluator, eval_every)