Class Dropout

java.lang.Object
com.jml.neural_network.layers.Dropout
All Implemented Interfaces:
BaseLayer

public class Dropout extends Object implements BaseLayer
A dropout layer. This layer has a probability of dropping (zeroing out) each element during the forward pass. This is only done during training. Dropout layers will not be used when making predictions with the final model.

Dropout is an effective form of regularization. In addition, the outputs of this layer are scaled by 1/(1-p) where p is the probability of dropping an element of the layer.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Dropout​(double p)
    Constructs a dropout layer for a neural network.
    Note: this constructor infers the input dimension from the previous layer in the network.
    Dropout​(int inDim, double p)
    Constructs a dropout layer for a neural network.
  • Method Summary

    Modifier and Type
    Method
    Description
    linalg.Matrix
    back​(linalg.Matrix upstreamGrad)
    Computes backward pass for layer.
    linalg.Matrix
    forward​(linalg.Matrix forwardIn)
    Feeds the inputs through the layer.
    Constructs a string containing this all details of the model pertinent for saving the model to a file.
    int
    Gets the input dimension of this layer.
    int
    Gets the output dimension of this layer.
    Gets the details of this layer as a String.
    void
    updateInDim​(int inDim)
    Updates the input dimension for the layer.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.jml.neural_network.layers.BaseLayer

    getParams, getUpdates, resetGradients, setParams
  • Field Details

  • Constructor Details

    • Dropout

      public Dropout(double p)
      Constructs a dropout layer for a neural network.
      Note: this constructor infers the input dimension from the previous layer in the network. Thus, it cannot be used as the first layer of the neural network. For the first layer use Dropout(int, double) to specify the input dimension.
      Parameters:
      p - The probability of an element being zeroed.
    • Dropout

      public Dropout(int inDim, double p)
      Constructs a dropout layer for a neural network.
      Parameters:
      inDim - Input dimension of the layer.
      p - The probability of an element being zeroed.
  • Method Details

    • forward

      public linalg.Matrix forward(linalg.Matrix forwardIn)
      Feeds the inputs through the layer. Each input will be scaled by 1/(1-p) and have a probability, p, of being zeroed or "dropped."
      Specified by:
      forward in interface BaseLayer
      Parameters:
      inputs - Input values for the layer
      Returns:
      The result of the layer applied to the values.
    • back

      public linalg.Matrix back(linalg.Matrix upstreamGrad)
      Description copied from interface: BaseLayer
      Computes backward pass for layer.
      Specified by:
      back in interface BaseLayer
      Returns:
      Result of the backwards pass of the layer as a Matrix. If this layer has weights, this matrix will have the same shape as the weight matrix for the layer.
    • getInDim

      public int getInDim()
      Gets the input dimension of this layer.
      Specified by:
      getInDim in interface BaseLayer
      Returns:
      The input dimension for this layer.
    • getOutDim

      public int getOutDim()
      Gets the output dimension of this layer.
      Specified by:
      getOutDim in interface BaseLayer
      Returns:
      The output dimension for this layer.
    • updateInDim

      public void updateInDim(int inDim)
      Updates the input dimension for the layer.
      WARNING: This will zero any weight values the layer may currently be holding.
      Specified by:
      updateInDim in interface BaseLayer
      Parameters:
      inDim - New input size for the layer.
    • inspect

      public String inspect()
      Gets the details of this layer as a String.
      Specified by:
      inspect in interface BaseLayer
      Returns:
      The details of this layer as a String.
    • getDetails

      public String getDetails()
      Constructs a string containing this all details of the model pertinent for saving the model to a file.
      Specified by:
      getDetails in interface BaseLayer
      Returns:
      A string containing all information, including trainable parameters, needed to recreate the layer.