Class Dense

  • All Implemented Interfaces:
    java.io.Serializable

    public class Dense
    extends Layer
    Basic fully-connected layer.
    See Also:
    Serialized Form
    • Field Detail

      • weights

        public Matrix weights
        Weights.
      • biases

        public Matrix biases
        Biases.
    • Constructor Detail

      • Dense

        public Dense​(int outSize,
                     Activation activation)
        Create a new dense layer.
        Parameters:
        outSize - size of output
        activation - activation to use
      • Dense

        public Dense​(int outSize,
                     Activation activation,
                     Initializer init)
        Create a new dense layer.
        Parameters:
        outSize - size of output
        activation - activation to use
        init - initialization method
    • Method Detail

      • setOptimizers

        public void setOptimizers​(Optimizer wOptimizer,
                                  Optimizer bOptimizer)
        Description copied from class: Layer
        Set optimizers for training the layer.
        Specified by:
        setOptimizers in class Layer
        Parameters:
        wOptimizer - optimizer for weights
        bOptimizer - optimizer for biases
      • initLayer

        public void initLayer​(int inSize,
                              Activation prevActivation)
        Description copied from class: Layer
        Create the layer.
        Specified by:
        initLayer in class Layer
        Parameters:
        inSize - size of the previous layer
        prevActivation - activation function or previous layer
      • getActivation

        public Activation getActivation()
        Description copied from class: Layer
        Get the activation of the layer.
        Specified by:
        getActivation in class Layer
        Returns:
        the activation object
      • getOutSize

        public int getOutSize()
        Description copied from class: Layer
        Get the output size of the layer.
        Specified by:
        getOutSize in class Layer
        Returns:
        the output size
      • forwardPropagate

        public Matrix forwardPropagate​(Matrix x)
        Description copied from class: Layer
        Forward propagate a batch of input.
        Specified by:
        forwardPropagate in class Layer
        Parameters:
        x - input matrix
        Returns:
        output matrix
      • getErrors

        public Matrix getErrors​(Matrix prevErrors)
        Description copied from class: Layer
        Get backpropagated errors.
        Specified by:
        getErrors in class Layer
        Parameters:
        prevErrors - errors from previous layer (layer after output)
        Returns:
        matrix of errors
      • getErrorsExpected

        public Matrix getErrorsExpected​(Matrix y)
        Description copied from class: Layer
        Get errors from output layer.
        Specified by:
        getErrorsExpected in class Layer
        Parameters:
        y - expected outputs
        Returns:
        matrix of errors
      • update

        public void update​(Matrix errors)
        Description copied from class: Layer
        Update the layer after calculating errors.
        Specified by:
        update in class Layer
        Parameters:
        errors - calculated errors
      • toString

        public java.lang.String toString()
        Description copied from class: Layer
        Get a string representation.
        Specified by:
        toString in class Layer
        Returns:
        the string
      • cloneSettings

        public Layer cloneSettings()
        Description copied from class: Layer
        Clone the settings.

        This will return a layer with the same size and activation, but with randomly initialized weights and biases.

        Specified by:
        cloneSettings in class Layer
        Returns:
        the clone
      • cloneLayer

        public Layer cloneLayer()
        Description copied from class: Layer
        Clone the layer, including weights and biases.
        Specified by:
        cloneLayer in class Layer
        Returns:
        the clone