Interface Layer<T>

Type Parameters:
T - the data type (e.g., Real, Complex).
All Superinterfaces:
Serializable
All Known Implementing Classes:
ActivationLayer, Linear, ReLU, Sequential

public interface Layer<T> extends Serializable
Represents a layer in a neural network.

Unified interface supporting both automatic differentiation (training) and direct tensor operations (optimized inference).

Since:
2.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
  • Method Details

    • forward

      GraphNode<T> forward(GraphNode<T> input)
      Performs a forward pass using explicit autograd nodes.
      Parameters:
      input - the input node.
      Returns:
      the transformed output node.
    • forward

      default Tensor<T> forward(Tensor<T> input)
      Performs an optimized forward pass using raw tensors. By default, wraps the tensor in a non-grad node and delegates to forward(GraphNode).
      Parameters:
      input - the input tensor.
      Returns:
      the transformed output tensor.
    • getParameters

      Map<String, GraphNode<T>> getParameters()
      Returns the learnable parameters of this layer. Keys should be unique within the layer (e.g., "weights", "bias").
      Returns:
      a map of parameter graph nodes.
    • getGradients

      default Map<String, Tensor<T>> getGradients()
      Returns the gradients of the learnable parameters.
      Returns:
      a map of gradient tensors.
    • setTraining

      default void setTraining(boolean training)
      Sets the training mode.
      Parameters:
      training - true for training, false for inference.