class_docstr: Base class for torch backend outlier detection algorithms.
class_docstr_tok: ["Base","class","for","torch","backend","outlier","detection","algorithms","."]
docstr: Aggregates and normalizes the data
  
  If the detector has an ensembler attribute we use it to aggregate and normalize the data.
  
  Parameters
  ----------
  x
      Data to aggregate and normalize.
  
  Returns
  -------
  `torch.Tensor` or original data without alteration
  
  Raises
  ------
  ThresholdNotInferredError
      If the detector is an ensemble, and the ensembler used to aggregate the outlier scores has a fittable
      component, then the detector threshold must be inferred before predictions can be made. This is because
      while the scoring functionality of the detector is fit within the `.fit` method on the training data
      the ensembler has to be fit on the validation data along with the threshold and this is done in the
      `.infer_threshold` method.
docstr_tok: ["Aggregates","and","normalizes","the","data","If","the","detector","has","an","ensembler","attribute","we","use","it","to","aggregate","and","normalize","the","data",".","Parameters","--","--","--","--","--","x","Data","to","aggregate","and","normalize",".","Returns","--","--","--","-","`","torch.Tensor","`","or","original","data","without","alteration","Raises","--","--","--","ThresholdNotInferredError","If","the","detector","is","an","ensemble",",","and","the","ensembler","used","to","aggregate","the","outlier","scores","has","a","fittable","component",",","then","the","detector","threshold","must","be","inferred","before","predictions","can","be","made",".","This","is","because","while","the","scoring","functionality","of","the","detector","is","fit","within","the","`",".fit","`","method","on","the","training","data","the","ensembler","has","to","be","fit","on","the","validation","data","along","with","the","threshold","and","this","is","done","in","the","`",".infer_threshold","`","method","."]
code: def _ensembler(self, x: torch.Tensor) -> torch.Tensor:
      """Aggregates and normalizes the data
  
      If the detector has an ensembler attribute we use it to aggregate and normalize the data.
  
      Parameters
      ----------
      x
          Data to aggregate and normalize.
  
      Returns
      -------
      `torch.Tensor` or original data without alteration
  
      Raises
      ------
      ThresholdNotInferredError
          If the detector is an ensemble, and the ensembler used to aggregate the outlier scores has a fittable
          component, then the detector threshold must be inferred before predictions can be made. This is because
          while the scoring functionality of the detector is fit within the `.fit` method on the training data
          the ensembler has to be fit on the validation data along with the threshold and this is done in the
          `.infer_threshold` method.
      """
      if hasattr(self, "ensembler") and self.ensembler is not None:
          # `type: ignore` here because self.ensembler here causes an error with mypy when using torch.jit.script.
          # For some reason it thinks self.ensembler is a torch.Tensor and therefore is not callable.
          if not torch.jit.is_scripting():
              if not self.ensembler.fitted:  # type: ignore
                  self.check_threshold_inferred()
          return self.ensembler(x)  # type: ignore
      else:
          return x
  
imports: from typing import List, Union, Optional, Dict
  from dataclasses import dataclass, fields
  from abc import ABC, abstractmethod
  import numpy
  import torch
  from alibi_detect.od.pytorch.ensemble import FitMixinTorch
  from alibi_detect.utils.pytorch.misc import get_device
  from alibi_detect.exceptions import ThresholdNotInferredError
  from alibi_detect.utils._types import TorchDeviceType
label_desc: Use image node_id 6 for calling the TorchOutlierDetector obj's underlying member method code with example usage: obj._ensembler(x) and returns: self, x