class_docstr: Adversarial Autoencoder model.
  
  Args:
      model_config (Adversarial_AE_Config): The Autoencoder configuration setting the main
          parameters of the model.
  
      encoder (BaseEncoder): An instance of BaseEncoder (inheriting from `torch.nn.Module` which
          plays the role of encoder. This argument allows you to use your own neural networks
          architectures if desired. If None is provided, a simple Multi Layer Preception
          (https://en.wikipedia.org/wiki/Multilayer_perceptron) is used. Default: None.
  
      decoder (BaseDecoder): An instance of BaseDecoder (inheriting from `torch.nn.Module` which
          plays the role of decoder. This argument allows you to use your own neural networks
          architectures if desired. If None is provided, a simple Multi Layer Preception
          (https://en.wikipedia.org/wiki/Multilayer_perceptron) is used. Default: None.
  
      discriminator (BaseDiscriminator): An instance of BaseDiscriminator (inheriting from
          `torch.nn.Module` which plays the role of discriminator. This argument allows you to
          use your own neural networks architectures if desired. If None is provided, a simple
          Multi Layer Preception (https://en.wikipedia.org/wiki/Multilayer_perceptron) is used.
          Default: None.
  
  .. note::
      For high dimensional data we advice you to provide you own network architectures. With the
      provided MLP you may end up with a ``MemoryError``.
class_docstr_tok: ["Adversarial","Autoencoder","model",".","Args",":","model_config","(","Adversarial_AE_Config",")",":","The","Autoencoder","configuration","setting","the","main","parameters","of","the","model",".","encoder","(","BaseEncoder",")",":","An","instance","of","BaseEncoder","(","inheriting","from","`","torch.nn.Module","`","which","plays","the","role","of","encoder",".","This","argument","allows","you","to","use","your","own","neural","networks","architectures","if","desired",".","If","None","is","provided",",","a","simple","Multi","Layer","Preception","(","https",":","\/\/en.wikipedia.org\/wiki\/Multilayer_perceptron",")","is","used",".","Default",":","None",".","decoder","(","BaseDecoder",")",":","An","instance","of","BaseDecoder","(","inheriting","from","`","torch.nn.Module","`","which","plays","the","role","of","decoder",".","This","argument","allows","you","to","use","your","own","neural","networks","architectures","if","desired",".","If","None","is","provided",",","a","simple","Multi","Layer","Preception","(","https",":","\/\/en.wikipedia.org\/wiki\/Multilayer_perceptron",")","is","used",".","Default",":","None",".","discriminator","(","BaseDiscriminator",")",":","An","instance","of","BaseDiscriminator","(","inheriting","from","`","torch.nn.Module","`","which","plays","the","role","of","discriminator",".","This","argument","allows","you","to","use","your","own","neural","networks","architectures","if","desired",".","If","None","is","provided",",","a","simple","Multi","Layer","Preception","(","https",":","\/\/en.wikipedia.org\/wiki\/Multilayer_perceptron",")","is","used",".","Default",":","None",".","..","note",":",":","For","high","dimensional","data","we","advice","you","to","provide","you","own","network","architectures",".","With","the","provided","MLP","you","may","end","up","with","a","``","MemoryError","``","."]
code: def loss_function(self, recon_x, x, z, z_prior):
      N = z.shape[0]  # batch size
  
      if self.model_config.reconstruction_loss == "mse":
          recon_loss = 0.5 * F.mse_loss(
              recon_x.reshape(x.shape[0], -1),
              x.reshape(x.shape[0], -1),
              reduction="none",
          ).sum(dim=-1)
  
      elif self.model_config.reconstruction_loss == "bce":
          recon_loss = F.binary_cross_entropy(
              recon_x.reshape(x.shape[0], -1),
              x.reshape(x.shape[0], -1),
              reduction="none",
          ).sum(dim=-1)
  
      gen_adversarial_score = self.discriminator(z).embedding.flatten()
      prior_adversarial_score = self.discriminator(
          z_prior
      ).embedding.flatten()
  
      true_labels = torch.ones(N, requires_grad=False).to(z.device)
      fake_labels = torch.zeros(N, requires_grad=False).to(z.device)
  
      autoencoder_loss = self.adversarial_loss_scale * (
          F.binary_cross_entropy(
              gen_adversarial_score, true_labels
          )  # generated are true
      ) + (recon_loss * self.reconstruction_loss_scale)
  
      gen_adversarial_score_ = self.discriminator(
          z.detach()
      ).embedding.flatten()
  
      discriminator_loss = (
          F.binary_cross_entropy(
              prior_adversarial_score, true_labels
          )  # prior is true
      ) + (
          F.binary_cross_entropy(
              gen_adversarial_score_, fake_labels
          )  # generated are false
      )
  
      return (
          (recon_loss).mean(dim=0),
          (autoencoder_loss).mean(dim=0),
          (discriminator_loss).mean(dim=0),
      )
  
imports: import inspect
  import logging
  import os
  import warnings
  from copy import deepcopy
  from typing import Optional
  import cloudpickle
  import torch
  import torch.nn.functional
  from ...customexception import BadInheritanceError
  from ...data.datasets import BaseDataset
  from ..base.base_utils import CPU_Unpickler, ModelOutput, hf_hub_is_available
  from ..nn import BaseDecoder, BaseDiscriminator, BaseEncoder
  from ..nn.default_architectures import Discriminator_MLP
  from ..vae import VAE
  from .adversarial_ae_config import Adversarial_AE_Config
label_desc: Use image node_id 4 for calling the Adversarial_AE obj's underlying member method code with example usage: obj.loss_function(recon_x, x, z, z_prior) and returns: recon_loss,  autoencoder_loss,  discriminator_loss