Interface BaseLayer

All Known Subinterfaces:
TrainableLayer
All Known Implementing Classes:
Dense, Dropout, Linear

public interface BaseLayer
Base layer interface. Specifies basic functionality that all layers should have.
  • Method Summary

    Modifier and Type
    Method
    Description
    linalg.Matrix
    back​(linalg.Matrix upStream)
    Computes backward pass for layer.
    linalg.Matrix
    forward​(linalg.Matrix input)
    Computes forward pass for 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.
    default linalg.Matrix[]
    Gets the trainable parameters of this layer in an array.
    default linalg.Matrix[]
    Gets the update matrices for the trainable parameters of this layer.
    Gets and formats details of this layer in a human-readable String.
    default void
    Resets the gradients for this layers' trainable parameters.
    default void
    setParams​(linalg.Matrix... params)
    Sets parameters of this layer.
    void
    updateInDim​(int newInDim)
    Updates this layers input dimension.
  • Method Details

    • forward

      linalg.Matrix forward(linalg.Matrix input)
      Computes forward pass for layer.
      Returns:
      Result of the forward pass of a layer as a matrix.
    • back

      linalg.Matrix back(linalg.Matrix upStream)
      Computes backward pass for layer.
      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

      int getInDim()
      Gets the input dimension of this layer.
      Returns:
      The input dimension of this layer.
    • getOutDim

      int getOutDim()
      Gets the output dimension of this layer.
      Returns:
      The output dimension of this layer.
    • updateInDim

      void updateInDim(int newInDim)
      Updates this layers input dimension. This is useful for creating a layer with an unknown input dimension and inferring it from the previous layer in the network.
      Parameters:
      newInDim - New input dimension for layer.
    • getParams

      default linalg.Matrix[] getParams()
      Gets the trainable parameters of this layer in an array.
      Returns:
      The trainable parameters of this layer in an array. If this layer does not inherit TrainableLayer then this will return null.
    • setParams

      default void setParams(linalg.Matrix... params)
      Sets parameters of this layer. If this layer does not inherit TrainableLayer then this does nothing.
      Parameters:
      params - Parameters of layer as an array of matrices.
    • getUpdates

      default linalg.Matrix[] getUpdates()
      Gets the update matrices for the trainable parameters of this layer.
      Returns:
      An array of update matrices for this layers' trainable parameters. If this layer does not inherit * TrainableLayer then this will return null.
    • resetGradients

      default void resetGradients()
      Resets the gradients for this layers' trainable parameters.
    • inspect

      String inspect()
      Gets and formats details of this layer in a human-readable String.
      Returns:
      The details of this layer in a human-reusable String.
    • getDetails

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