Class Layer

  • All Implemented Interfaces:
    java.io.Serializable
    Direct Known Subclasses:
    Dense, InputLayer

    public abstract class Layer
    extends java.lang.Object
    implements java.io.Serializable
    Abstract layer class.
    See Also:
    Serialized Form
    • Constructor Detail

      • Layer

        public Layer()
    • Method Detail

      • initLayer

        public abstract void initLayer​(int prevSize,
                                       Activation prevActivation)
        Create the layer.
        Parameters:
        prevSize - size of the previous layer
        prevActivation - activation function or previous layer
      • setOptimizers

        public abstract void setOptimizers​(Optimizer wOptimizer,
                                           Optimizer bOptimizer)
        Set optimizers for training the layer.
        Parameters:
        wOptimizer - optimizer for weights
        bOptimizer - optimizer for biases
      • getActivation

        public abstract Activation getActivation()
        Get the activation of the layer.
        Returns:
        the activation object
      • getOutSize

        public abstract int getOutSize()
        Get the output size of the layer.
        Returns:
        the output size
      • forwardPropagate

        public abstract Matrix forwardPropagate​(Matrix x)
        Forward propagate a batch of input.
        Parameters:
        x - input matrix
        Returns:
        output matrix
      • getErrors

        public abstract Matrix getErrors​(Matrix prevErrors)
        Get backpropagated errors.
        Parameters:
        prevErrors - errors from previous layer (layer after output)
        Returns:
        matrix of errors
      • getErrorsExpected

        public abstract Matrix getErrorsExpected​(Matrix y)
        Get errors from output layer.
        Parameters:
        y - expected outputs
        Returns:
        matrix of errors
      • update

        public abstract void update​(Matrix errors)
        Update the layer after calculating errors.
        Parameters:
        errors - calculated errors
      • toString

        public abstract java.lang.String toString()
        Get a string representation.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the string
      • cloneSettings

        public abstract Layer cloneSettings()
        Clone the settings.

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

        Returns:
        the clone
      • cloneLayer

        public abstract Layer cloneLayer()
        Clone the layer, including weights and biases.
        Returns:
        the clone