class_docstr: Auto Encoder (AE) is a type of neural networks for learning useful data
  representations in an unsupervised manner. Similar to PCA, AE could be used
  to detect outlying objects in the data by calculating the reconstruction
  errors. See :cite:`aggarwal2015outlier` Chapter 3 for details.
  
  Notes
  -----
      This is the PyTorch version of AutoEncoder. See auto_encoder.py for
      the TensorFlow version.
  
      The documentation is not finished!
  
  Parameters
  ----------
  hidden_neurons : list, optional (default=[64, 32])
      The number of neurons per hidden layers. So the network has the
      structure as [n_features, 64, 32, 32, 64, n_features]
  
  hidden_activation : str, optional (default='relu')
      Activation function to use for hidden layers.
      All hidden layers are forced to use the same type of activation.
      See https://pytorch.org/docs/stable/nn.html for details.
      Currently only
      'relu': nn.ReLU()
      'sigmoid': nn.Sigmoid()
      'tanh': nn.Tanh()
      are supported. See pyod/utils/torch_utility.py for details.
  
  batch_norm : boolean, optional (default=True)
      Whether to apply Batch Normalization,
      See https://pytorch.org/docs/stable/generated/torch.nn.BatchNorm1d.html
  
  learning_rate : float, optional (default=1e-3)
      Learning rate for the optimizer. This learning_rate is given to
      an Adam optimizer (torch.optim.Adam).
      See https://pytorch.org/docs/stable/generated/torch.optim.Adam.html
  
  epochs : int, optional (default=100)
      Number of epochs to train the model.
  
  batch_size : int, optional (default=32)
      Number of samples per gradient update.
  
  dropout_rate : float in (0., 1), optional (default=0.2)
      The dropout to be used across all layers.
  
  weight_decay : float, optional (default=1e-5)
      The weight decay for Adam optimizer.
      See https://pytorch.org/docs/stable/generated/torch.optim.Adam.html
  
  preprocessing : bool, optional (default=True)
      If True, apply standardization on the data.
  
  loss_fn : obj, optional (default=torch.nn.MSELoss)
      Optimizer instance which implements torch.nn._Loss.
      One of https://pytorch.org/docs/stable/nn.html#loss-functions
      or a custom loss. Custom losses are currently unstable.
  
  verbose : int, optional (default=1)
      Verbosity mode.
  
      - 0 = silent
      - 1 = progress bar
      - 2 = one line per epoch.
  
      For verbose >= 1, model summary may be printed.
      !CURRENTLY NOT SUPPORTED.!
  
  random_state : random_state: int, RandomState instance or None, optional
      (default=None)
      If int, random_state is the seed used by the random
      number generator; If RandomState instance, random_state is the random
      number generator; If None, the random number generator is the
      RandomState instance used by `np.random`.
      !CURRENTLY NOT SUPPORTED.!
  
  contamination : float in (0., 0.5), optional (default=0.1)
      The amount of contamination of the data set, i.e.
      the proportion of outliers in the data set. When fitting this is used
      to define the threshold on the decision function.
  
  Attributes
  ----------
  encoding_dim_ : int
      The number of neurons in the encoding layer.
  
  compression_rate_ : float
      The ratio between the original feature and
      the number of neurons in the encoding layer.
  
  model_ : Keras Object
      The underlying AutoEncoder in Keras.
  
  history_: Keras Object
      The AutoEncoder training history.
  
  decision_scores_ : numpy array of shape (n_samples,)
      The outlier scores of the training data.
      The higher, the more abnormal. Outliers tend to have higher
      scores. This value is available once the detector is
      fitted.
  
  threshold_ : float
      The threshold is based on ``contamination``. It is the
      ``n_samples * contamination`` most abnormal samples in
      ``decision_scores_``. The threshold is calculated for generating
      binary outlier labels.
  
  labels_ : int, either 0 or 1
      The binary labels of the training data. 0 stands for inliers
      and 1 for outliers/anomalies. It is generated by applying
      ``threshold_`` on ``decision_scores_``.
docstr: Internal function to train the autoencoder
  
  Parameters
  ----------
  train_loader : torch dataloader
      Train data.
docstr_tok: ["Internal","function","to","train","the","autoencoder","Parameters","--","--","--","--","--","train_loader",":","torch","dataloader","Train","data","."]
code: def _train_autoencoder(self, train_loader):
      """Internal function to train the autoencoder
  
      Parameters
      ----------
      train_loader : torch dataloader
          Train data.
      """
      optimizer = torch.optim.Adam(
          self.model.parameters(),
          lr=self.learning_rate,
          weight_decay=self.weight_decay,
      )
  
      self.best_loss = float("inf")
      self.best_model_dict = None
  
      for epoch in range(self.epochs):
          overall_loss = []
          for data, data_idx in train_loader:
              data = data.to(self.device).float()
              loss = self.loss_fn(data, self.model(data))
  
              self.model.zero_grad()
              loss.backward()
              optimizer.step()
              overall_loss.append(loss.item())
          print(
              "epoch {epoch}: training loss {train_loss} ".format(
                  epoch=epoch, train_loss=np.mean(overall_loss)
              )
          )
  
          # track the best model so far
          if np.mean(overall_loss) <= self.best_loss:
              # print("epoch {ep} is the current best; loss={loss}".format(ep=epoch, loss=np.mean(overall_loss)))
              self.best_loss = np.mean(overall_loss)
              self.best_model_dict = self.model.state_dict()
  
imports: from __future__ import division
  from __future__ import print_function
  import numpy
  import torch
  from sklearn.utils import check_array
  from sklearn.utils.validation import check_is_fitted
  from torch import nn
  from .base import BaseDetector
  from ..utils.stat_models import pairwise_distances_no_broadcast
  from ..utils.torch_utility import get_activation_by_name
label_desc: Use image node_id 3 for calling the AutoEncoder obj's underlying member method code with example usage: obj._train_autoencoder(train_loader) without return types