FullyConnectedLayer<T>
Layers · AiDotNet.NeuralNetworks.Layers
Represents a fully connected layer in a neural network where every input neuron connects to every output neuron.
Inheritance: LayerBase<T> → FullyConnectedLayer<T>
Implements: IShapeContract
For Beginners
A fully connected layer connects every input to every output, like a complete web of connections.
Imagine you have inputs representing different features:
- Each feature (input) connects to every possible output
- Each connection has a strength (weight) that can be adjusted
- Each output also has a starting value (bias)
For example, in an image classification task:
- Inputs might be flattened features from convolutional layers
- Each output might represent a score for a different category
- The connections (weights) learn which features are important for each category
Fully connected layers are excellent at combining features to make final decisions. They’re often used toward the end of a neural network to interpret the features extracted by earlier layers.
How It Works
A fully connected layer, also known as a dense layer, is a fundamental building block in neural networks. It connects every input neuron to every output neuron with learnable weights. Each output neuron also has a learnable bias term. The layer applies a linear transformation followed by an activation function to produce its output. Fully connected layers are particularly useful for learning complex patterns and for classification tasks.
Constructors
| Constructor | Summary |
|---|---|
FullyConnectedLayer(IVectorActivationFunction<T> vectorActivationFunction, int inputSize, int outputSize) |
Initializes a new instance of the FullyConnectedLayer class with a vector activation function. |
FullyConnectedLayer(IVectorActivationFunction<T> vectorActivationFunction, int inputSize, int outputSize, BiasMode biasMode) |
Creates a layer with known input and output sizes and a vector activation function. |
FullyConnectedLayer(int inputSize, int outputSize) |
Same as the overload taking a BiasMode, with Auto (a bias). |
FullyConnectedLayer(int inputSize, int outputSize, IActivationFunction<T> activationFunction) |
Initializes a new instance of the FullyConnectedLayer class with a vector activation function. |
FullyConnectedLayer(int inputSize, int outputSize, IActivationFunction<T> activationFunction, BiasMode biasMode) |
Creates a layer with known input and output sizes and a vector activation function. |
FullyConnectedLayer(int outputSize) |
Same as the overload taking a BiasMode, with Auto (a bias). |
FullyConnectedLayer(int outputSize, IActivationFunction<T> activationFunction) |
Same as the overload taking a BiasMode, with Auto (a bias). |
FullyConnectedLayer(int outputSize, IActivationFunction<T> activationFunction, BiasMode biasMode) |
Initializes a new instance of the FullyConnectedLayer class with a vector activation function. |
FullyConnectedLayer(int outputSize, IVectorActivationFunction<T> vectorActivationFunction) |
Same as the overload taking a BiasMode, with Auto (a bias). |
FullyConnectedLayer(int outputSize, IVectorActivationFunction<T> vectorActivationFunction, BiasMode biasMode) |
Initializes a new instance of the FullyConnectedLayer class with a vector activation function. |
Properties
| Property | Summary |
|---|---|
bool HasUninitializedParameters { get; } |
|
bool SupportsTraining { get; } |
Gets a value indicating whether this layer supports training. |
bool UseBias { get; } |
Whether this layer adds its own bias after the matrix product. |
Methods
| Method | Summary |
|---|---|
Dictionary<string, string> GetParameterRoles() |
Returns parameter roles for per-role optimizer configuration (e.g., weight decay exemption for biases). |
FullyConnectedLayer<T> WithVectorActivation(int inputSize, int outputSize, IVectorActivationFunction<T> vectorActivationFunction) |
Same as the overload taking a BiasMode, with Auto (a bias). |
FullyConnectedLayer<T> WithVectorActivation(int inputSize, int outputSize, IVectorActivationFunction<T> vectorActivationFunction, BiasMode biasMode) |
Creates a layer with known input and output sizes and a vector activation function. |
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank) |
|
IReadOnlyList<Tensor<T>> GetTrainableParameters() |
Returns all trainable parameter tensors marked with [TrainableParameter]. |
Tensor<T> GetBiases() |
|
Tensor<T> GetWeights() |
|
void ClearGradients() |
Clears stored gradients for weights and biases. |
void ResetState() |
Resets the internal state of the layer. |
void SetTrainableParameters(IReadOnlyList<Tensor<T>> parameters) |
Replaces trainable parameter tensors (e.g., with ParameterBuffer views). |
void UpdateParameters(T learningRate) |
Updates the weights and biases using the calculated gradients and the specified learning rate. |
void ZeroGrad() |
Clears all gradient fields discovered by convention ({paramName}Gradient). |