DigitCapsuleLayer<T>
Layers · AiDotNet.NeuralNetworks.Layers
Represents a digit capsule layer that implements the dynamic routing algorithm between capsules.
Inheritance: LayerBase<T> → DigitCapsuleLayer<T>
Implements: IShapeContract
For Beginners
A capsule layer is a special type of neural network layer that groups neurons together.
Think of regular neural networks as looking at individual puzzle pieces (like detecting edges or corners). A capsule network looks at how these pieces fit together to form objects.
For example, in image recognition:
- Regular neurons might detect a wheel, a window, and a door
- Capsules understand that these parts can make up a car, and how those parts relate to each other
This layer specifically handles digit recognition, taking information from previous capsule layers and determining which digit is most likely present in the input.
How It Works
A digit capsule layer extends the concept of traditional neural networks by using groups of neurons (capsules) that encapsulate various properties of entities. This implementation is based on the CapsNet architecture proposed by Hinton et al., which uses a dynamic routing algorithm to determine how lower-level capsules should send their output to higher-level capsules.
Constructors
| Constructor | Summary |
|---|---|
DigitCapsuleLayer(int inputCapsules, int inputCapsuleDimension, int numClasses, int outputCapsuleDimension, int routingIterations) |
Initializes a new instance of the DigitCapsuleLayer class. |
DigitCapsuleLayer(int numClasses, int outputCapsuleDimension, int routingIterations) |
Lazy constructor: resolves inputCapsules and inputCapsuleDimension from input.Shape[^2..] on first Forward. |
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 layer. |
void SetTrainableParameters(IReadOnlyList<Tensor<T>> parameters) |
Replaces trainable parameter tensors (e.g., with ParameterBuffer views). |
void UpdateParameters(T learningRate) |
Updates the layer’s weights using the calculated gradients and the specified learning rate. |
void ZeroGrad() |
Clears all gradient fields discovered by convention ({paramName}Gradient). |