ReadoutLayer<T>

Layers · AiDotNet.NeuralNetworks.Layers

Represents a readout layer that performs the final mapping from features to output in a neural network.

Inheritance: LayerBase<T> → ReadoutLayer<T>

Implements: IShapeContract

For Beginners

This layer serves as the final “decision maker” in a neural network.

Think of the ReadoutLayer as a panel of judges in a competition:

  • Each judge (output neuron) receives information from all contestants (input features)
  • Each judge has their own preferences (weights) for different skills
  • Judges combine all this information to make their final scores (outputs)
  • An activation function then shapes these scores into the desired format

For example, in an image classification network:

  • Previous layers extract features like edges, shapes, and patterns
  • The ReadoutLayer takes all these features and combines them into class scores
  • If there are 10 possible classes, the ReadoutLayer might have 10 outputs
  • Each output represents the network’s confidence that the image belongs to that class

This layer learns which features are most important for each output category during training.

How It Works

The ReadoutLayer is typically used as the final layer in a neural network to transform features extracted by previous layers into the desired output format. It applies a linear transformation (weights and bias) followed by an activation function. This layer is similar to a dense or fully connected layer but is specifically designed for outputting the final results.

Constructors

Constructor Summary
ReadoutLayer(int inputSize, int outputSize, IActivationFunction<T> scalarActivation, IInitializationStrategy<T> initializationStrategy) Initializes a new instance of the ReadoutLayer class with a vector activation function.
ReadoutLayer(int inputSize, int outputSize, IVectorActivationFunction<T> vectorActivation, IInitializationStrategy<T> initializationStrategy) Initializes a new instance of the ReadoutLayer class with a vector activation function.

Properties

Property Summary
bool SupportsTraining { get; }

Methods

Method Summary
Dictionary<string, string> GetParameterRoles() Returns parameter roles for per-role optimizer configuration (e.g., weight decay exemption for biases).
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank)
IReadOnlyList<Tensor<T>> GetTrainableParameters() Returns all trainable parameter tensors marked with [TrainableParameter].
void ClearGradients()
void ResetState() Resets the internal state of the readout layer.
void SetTrainableParameters(IReadOnlyList<Tensor<T>> parameters) Replaces trainable parameter tensors (e.g., with ParameterBuffer views).
void UpdateParameters(T learningRate) Updates the parameters of the readout layer using the calculated gradients.
void ZeroGrad() Clears all gradient fields discovered by convention ({paramName}Gradient).