class_docstr:     ## Discriminator Loss
  
      Discriminator should **ascend** on the gradient,
  
      $$
  abla_{  heta_d} rac{1}{m} \sum_{i=1}^m \Bigg[
          \log D\Big(\pmb{x}^{(i)}\Big) +
          \log \Big(1 - D\Big(G\Big(\pmb{z}^{(i)}\Big)\Big)\Big)
      \Bigg]$$
  
      $m$ is the mini-batch size and $(i)$ is used to index samples in the mini-batch.
      $\pmb{x}$ are samples from $p_{data}$ and $\pmb{z}$ are samples from $p_z$.
      
code: def __init__(self, smoothing: float = 0.2):
      super().__init__()
      # We use PyTorch Binary Cross Entropy Loss, which is
      # $-\sum\Big[y \log(\hat{y}) + (1 - y) \log(1 - \hat{y})\Big]$,
      # where $y$ are the labels and $\hat{y}$ are the predictions.
      # *Note the negative sign*.
      # We use labels equal to $1$ for $\pmb{x}$ from $p_{data}$
      # and labels equal to $0$ for $\pmb{x}$ from $p_{G}.$
      # Then descending on the sum of these is the same as ascending on
      # the above gradient.
      #
      # `BCEWithLogitsLoss` combines softmax and binary cross entropy loss.
      self.loss_true = nn.BCEWithLogitsLoss()
      self.loss_false = nn.BCEWithLogitsLoss()
  
      # We use label smoothing because it seems to work better in some cases
      self.smoothing = smoothing
  
      # Labels are registered as buffered and persistence is set to `False`.
      self.register_buffer(
          "labels_true",
          _create_labels(256, 1.0 - smoothing, 1.0),
          False,
      )
      self.register_buffer(
          "labels_false", _create_labels(256, 0.0, smoothing), False
      )
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/gan/original/__init__.py
imports: import torch
  import torch.nn
  import torch.utils.data
  import torch.utils.data
  from labml_helpers.module import Module
label_desc: Use image node_id 1 to create a new DiscriminatorLogitsLoss object from inherited base classes: Module with example: obj = DiscriminatorLogitsLoss(smoothing)