MeanLayer<T>

Layers · AiDotNet.NeuralNetworks.Layers

Represents a layer that computes the mean (average) of input values along a specified axis.

Inheritance: LayerBase<T> → MeanLayer<T>

Implements: IShapeContract

For Beginners

This layer calculates the average of values in your data along one direction.

Think of it like calculating the average test score for each student across multiple subjects:

  • Input: A table of scores where rows are students and columns are subjects
  • MeanLayer with axis=1 (columns): Gives each student’s average score across all subjects

Some practical examples:

  • In image processing: Taking the average across color channels
  • In text analysis: Taking the average of word embeddings to get a sentence representation
  • In time series: Taking the average across time steps to get a summary

For instance, if you have data with shape [10, 5, 20] (e.g., 10 batches, 5 time steps, 20 features), a MeanLayer with axis=1 would output shape [10, 20], giving you the average across all time steps.

How It Works

The MeanLayer reduces the dimensionality of data by taking the average of values along a specified axis. This operation is useful for aggregating feature information or reducing sequence data to a fixed-size representation. The output shape has one fewer dimension than the input shape, with the specified axis being removed.

Constructors

Constructor Summary
MeanLayer(int axis) Initializes a new instance of the MeanLayer class with the specified input shape and axis.

Properties

Property Summary
bool SupportsGpuTraining { get; }
bool SupportsTraining { get; } Gets a value indicating whether this layer supports training.
int Axis { get; set; } Gets the axis along which the mean is calculated.

Methods

Method Summary
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank)
void ResetState() Resets the internal state of the mean layer.