GraphSAGELayer<T>
Layers · AiDotNet.NeuralNetworks.Layers
Implements GraphSAGE (Graph Sample and Aggregate) layer for inductive learning on graphs.
Inheritance: LayerBase<T> → GraphSAGELayer<T>
Implements: IGraphConvolutionLayer<T>, IShapeContract
How It Works
GraphSAGE, introduced by Hamilton et al., is designed for inductive learning on graphs, meaning it can generalize to unseen nodes and graphs. Instead of learning embeddings for each node directly, it learns aggregator functions that generate embeddings by sampling and aggregating features from a node’s local neighborhood.
The layer performs: h_v = sigma(W_self * h_v + W_neigh * AGGREGATE({h_u : u in N(v)}) + b) where h_v is the representation of node v, N(v) is the neighborhood of v, AGGREGATE is an aggregation function (mean, max, sum), and sigma is an activation function.
Production-Ready Features:
- Fully vectorized operations using IEngine for GPU acceleration
- Tensor-based weights for all parameters
- Dual backward pass: BackwardManual() for efficiency, BackwardViaAutodiff() for accuracy
- Full gradient computation through aggregation paths
- Complete GetParameters()/SetParameters() for model persistence
Constructors
| Constructor | Summary |
|---|---|
GraphSAGELayer(int inputFeatures, int outputFeatures, SAGEAggregatorType aggregatorType, bool normalize, IActivationFunction<T> activationFunction, IInitializationStrategy<T> initializationStrategy) |
Initializes a new instance of the GraphSAGELayer class. |
Properties
| Property | Summary |
|---|---|
bool SupportsTraining { get; } |
|
int InputFeatures { get; } |
|
int OutputFeatures { 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]. |
IReadOnlyList<ValueTuple<string, Tensor<T>>> GetRegisteredBuffers() |
|
Tensor<T> GetAdjacencyMatrix() |
|
void ClearGradients() |
|
void ResetState() |
|
void SetAdjacencyMatrix(Tensor<T> adjacencyMatrix) |
|
void SetTrainableParameters(IReadOnlyList<Tensor<T>> parameters) |
Replaces trainable parameter tensors (e.g., with ParameterBuffer views). |
void UpdateParameters(T learningRate) |
|
void ZeroGrad() |
Clears all gradient fields discovered by convention ({paramName}Gradient). |