docstr: Fit the detector on reference data.
  
  If the ``'pytorch'`` backend is used, the detector is fitted using gradient descent. This is the recommended
  backend for larger datasets.
  
  If the ``'sklearn'`` backend is used, the detector is fitted using the EM algorithm. The ``'sklearn'``
  backend is recommended for smaller datasets. For more information on the EM algorithm and the sklearn Gaussian
  Mixture Model, see `here <https://scikit-learn.org/stable/modules/generated/sklearn.mixture.GaussianMixture.html#sklearn.mixture.GaussianMixture>`_.  # noqa: E501
  
  Parameters
  ----------
  x_ref
      Reference data used to fit the detector.
  optimizer
      Optimizer used to fit the detector. Only used if the ``'pytorch'`` backend is used. Defaults to ``'Adam'``.
  learning_rate
      Learning rate used to fit the detector. Only used if the ``'pytorch'`` backend is used. Defaults to ``0.1``.
  max_epochs
      Maximum number of training epochs used to fit the detector. Used for both the ``'pytorch'`` and ``'sklearn'``
      backends. If the backend is ``'sklearn'``, the detector is fit using the EM algorithm and `max_epochs`
      defaults to ``100``. If the backend is ``'pytorch'``, the detector is fitted using gradient descent and
      `max_epochs` defaults to ``10``.
  batch_size
      Batch size used to fit the detector. Only used if the ``'pytorch'`` backend is used. Defaults to ``None``.
      If ``None``, the entire dataset is used for each gradient update.
  tol
      Convergence threshold used to fit the detector. Used for both ``'sklearn'`` and ``'pytorch'`` backends.
      Defaults to ``1e-3``.
  n_iter_no_change
      The number of iterations over which the loss must decrease by `tol` in order for optimization to continue.
      Only used if the ``'pytorch'`` backend is used.
  n_init
      Number of initializations used to fit the detector. Only used if the ``'sklearn'`` backend is used.
      Defaults to ``1``.
  init_params
      Initialization method used to fit the detector. Only used if the ``'sklearn'`` backend is used. Must be
      one of:
      'kmeans' : responsibilities are initialized using kmeans.
      'kmeans++' : responsibilities are initialized using kmeans++.
      'random' : responsibilities are initialized randomly.
      'random_from_data' : responsibilities are initialized randomly from the data.
      Defaults to ``'kmeans'``.
  verbose
      Verbosity level used to fit the detector. Used for both ``'sklearn'`` and ``'pytorch'`` backends. Defaults to ``0``.
  
  Returns
  -------
  Dictionary with fit results. The dictionary contains the following keys depending on the backend used:
      - converged: bool indicating whether EM algorithm converged.
      - n_iter: number of EM iterations performed. Only returned if `backend` is ``'sklearn'``.
      - n_epochs: number of gradient descent iterations performed. Only returned if `backend` is ``'pytorch'``.
      - lower_bound: log-likelihood lower bound.
docstr_tok: ["Fit","the","detector","on","reference","data",".","If","the","``","'pytorch","'","``","backend","is","used",",","the","detector","is","fitted","using","gradient","descent",".","This","is","the","recommended","backend","for","larger","datasets",".","If","the","``","'sklearn","'","``","backend","is","used",",","the","detector","is","fitted","using","the","EM","algorithm",".","The","``","'sklearn","'","``","backend","is","recommended","for","smaller","datasets",".","For","more","information","on","the","EM","algorithm","and","the","sklearn","Gaussian","Mixture","Model",",","see","`","here","<","https",":","\/\/scikit-learn.org\/stable\/modules\/generated\/sklearn.mixture.GaussianMixture.html","#","sklearn.mixture.GaussianMixture",">","`","_",".","#","noqa",":","E501","Parameters","--","--","--","--","--","x_ref","Reference","data","used","to","fit","the","detector",".","optimizer","Optimizer","used","to","fit","the","detector",".","Only","used","if","the","``","'pytorch","'","``","backend","is","used",".","Defaults","to","``","'Adam","'","``",".","learning_rate","Learning","rate","used","to","fit","the","detector",".","Only","used","if","the","``","'pytorch","'","``","backend","is","used",".","Defaults","to","``","0.1","``",".","max_epochs","Maximum","number","of","training","epochs","used","to","fit","the","detector",".","Used","for","both","the","``","'pytorch","'","``","and","``","'sklearn","'","``","backends",".","If","the","backend","is","``","'sklearn","'","``",",","the","detector","is","fit","using","the","EM","algorithm","and","`","max_epochs","`","defaults","to","``","100","``",".","If","the","backend","is","``","'pytorch","'","``",",","the","detector","is","fitted","using","gradient","descent","and","`","max_epochs","`","defaults","to","``","10","``",".","batch_size","Batch","size","used","to","fit","the","detector",".","Only","used","if","the","``","'pytorch","'","``","backend","is","used",".","Defaults","to","``","None","``",".","If","``","None","``",",","the","entire","dataset","is","used","for","each","gradient","update",".","tol","Convergence","threshold","used","to","fit","the","detector",".","Used","for","both","``","'sklearn","'","``","and","``","'pytorch","'","``","backends",".","Defaults","to","``","1e-3","``",".","n_iter_no_change","The","number","of","iterations","over","which","the","loss","must","decrease","by","`","tol","`","in","order","for","optimization","to","continue",".","Only","used","if","the","``","'pytorch","'","``","backend","is","used",".","n_init","Number","of","initializations","used","to","fit","the","detector",".","Only","used","if","the","``","'sklearn","'","``","backend","is","used",".","Defaults","to","``","1","``",".","init_params","Initialization","method","used","to","fit","the","detector",".","Only","used","if","the","``","'sklearn","'","``","backend","is","used",".","Must","be","one","of",":","'kmeans","'",":","responsibilities","are","initialized","using","kmeans",".","'kmeans++","'",":","responsibilities","are","initialized","using","kmeans++",".","'random","'",":","responsibilities","are","initialized","randomly",".","'random_from_data","'",":","responsibilities","are","initialized","randomly","from","the","data",".","Defaults","to","``","'kmeans","'","``",".","verbose","Verbosity","level","used","to","fit","the","detector",".","Used","for","both","``","'sklearn","'","``","and","``","'pytorch","'","``","backends",".","Defaults","to","``","0","``",".","Returns","--","--","--","-","Dictionary","with","fit","results",".","The","dictionary","contains","the","following","keys","depending","on","the","backend","used",":","-","converged",":","bool","indicating","whether","EM","algorithm","converged",".","-","n_iter",":","number","of","EM","iterations","performed",".","Only","returned","if","`","backend","`","is","``","'sklearn","'","``",".","-","n_epochs",":","number","of","gradient","descent","iterations","performed",".","Only","returned","if","`","backend","`","is","``","'pytorch","'","``",".","-","lower_bound",":","log-likelihood","lower","bound","."]
code: def fit(
      self,
      x_ref: np.ndarray,
      optimizer: Optional[str] = "Adam",
      learning_rate: float = 0.1,
      max_epochs: Optional[int] = None,
      batch_size: Optional[int] = None,
      tol: float = 1e-3,
      n_iter_no_change: int = 25,
      n_init: int = 1,
      init_params: str = "kmeans",
      verbose: int = 0,
  ) -> None:
      """Fit the detector on reference data.
  
      If the ``'pytorch'`` backend is used, the detector is fitted using gradient descent. This is the recommended
      backend for larger datasets.
  
      If the ``'sklearn'`` backend is used, the detector is fitted using the EM algorithm. The ``'sklearn'``
      backend is recommended for smaller datasets. For more information on the EM algorithm and the sklearn Gaussian
      Mixture Model, see `here <https://scikit-learn.org/stable/modules/generated/sklearn.mixture.GaussianMixture.html#sklearn.mixture.GaussianMixture>`_.  # noqa: E501
  
      Parameters
      ----------
      x_ref
          Reference data used to fit the detector.
      optimizer
          Optimizer used to fit the detector. Only used if the ``'pytorch'`` backend is used. Defaults to ``'Adam'``.
      learning_rate
          Learning rate used to fit the detector. Only used if the ``'pytorch'`` backend is used. Defaults to ``0.1``.
      max_epochs
          Maximum number of training epochs used to fit the detector. Used for both the ``'pytorch'`` and ``'sklearn'``
          backends. If the backend is ``'sklearn'``, the detector is fit using the EM algorithm and `max_epochs`
          defaults to ``100``. If the backend is ``'pytorch'``, the detector is fitted using gradient descent and
          `max_epochs` defaults to ``10``.
      batch_size
          Batch size used to fit the detector. Only used if the ``'pytorch'`` backend is used. Defaults to ``None``.
          If ``None``, the entire dataset is used for each gradient update.
      tol
          Convergence threshold used to fit the detector. Used for both ``'sklearn'`` and ``'pytorch'`` backends.
          Defaults to ``1e-3``.
      n_iter_no_change
          The number of iterations over which the loss must decrease by `tol` in order for optimization to continue.
          Only used if the ``'pytorch'`` backend is used.
      n_init
          Number of initializations used to fit the detector. Only used if the ``'sklearn'`` backend is used.
          Defaults to ``1``.
      init_params
          Initialization method used to fit the detector. Only used if the ``'sklearn'`` backend is used. Must be
          one of:
          'kmeans' : responsibilities are initialized using kmeans.
          'kmeans++' : responsibilities are initialized using kmeans++.
          'random' : responsibilities are initialized randomly.
          'random_from_data' : responsibilities are initialized randomly from the data.
          Defaults to ``'kmeans'``.
      verbose
          Verbosity level used to fit the detector. Used for both ``'sklearn'`` and ``'pytorch'`` backends. Defaults to ``0``.
  
      Returns
      -------
      Dictionary with fit results. The dictionary contains the following keys depending on the backend used:
          - converged: bool indicating whether EM algorithm converged.
          - n_iter: number of EM iterations performed. Only returned if `backend` is ``'sklearn'``.
          - n_epochs: number of gradient descent iterations performed. Only returned if `backend` is ``'pytorch'``.
          - lower_bound: log-likelihood lower bound.
      """
      return self.backend.fit(
          self.backend._to_backend_dtype(x_ref),
          **self.backend.format_fit_kwargs(locals()),
      )
  
imports: from typing import Optional, Dict, Any
  import numpy
  from alibi_detect.utils._types import Literal
  from alibi_detect.base import outlier_prediction_dict
  from alibi_detect.base import BaseDetector, ThresholdMixin, FitMixin
  from alibi_detect.od.pytorch import GMMTorch
  from alibi_detect.od.sklearn import GMMSklearn
  from alibi_detect.utils.frameworks import BackendValidator
  from alibi_detect.version import __version__
  from alibi_detect.exceptions import _catch_error
  from alibi_detect.utils._types import TorchDeviceType
label_desc: Use image node_id 2 for calling the GMM obj's underlying member method code with example usage: obj.fit(x_ref, optimizer, learning_rate, max_epochs, batch_size, tol, n_iter_no_change, n_init, init_params, verbose) and returns: self