Table of Contents

Class GNNMetaOptions<T, TInput, TOutput>

Namespace
AiDotNet.MetaLearning.Options
Assembly
AiDotNet.dll

Configuration options for the Graph Neural Network Meta-learning algorithm.

public class GNNMetaOptions<T, TInput, TOutput> : IMetaLearnerOptions<T>

Type Parameters

T

The numeric data type used for calculations (e.g., float, double).

TInput

The input data type (e.g., Matrix<T>, Tensor<T>).

TOutput

The output data type (e.g., Vector<T>, Tensor<T>).

Inheritance
GNNMetaOptions<T, TInput, TOutput>
Implements
Inherited Members

Remarks

GNN-based meta-learning models tasks and examples as nodes in a graph, with edges representing relationships between them. The graph neural network learns to propagate information across the task structure to improve learning.

For Beginners: GNN Meta-learning treats the learning process as a graph problem: 1. Each task or example becomes a node in a graph 2. Relationships between tasks are edges (e.g., task similarity) 3. A graph neural network learns to propagate useful information 4. This allows the model to leverage task relationships for better adaptation

Imagine a social network where users are tasks and friendships are similarities. By looking at what similar tasks learned, new tasks can adapt faster.

Key Components: - Node Embeddings: Represent tasks/examples as vectors - Message Passing: Share information between connected nodes - Graph Aggregation: Combine node information for predictions

Constructors

GNNMetaOptions(IFullModel<T, TInput, TOutput>)

Initializes a new instance of the GNNMetaOptions class with the required meta-model.

public GNNMetaOptions(IFullModel<T, TInput, TOutput> metaModel)

Parameters

metaModel IFullModel<T, TInput, TOutput>

The meta-model to be trained (required).

Exceptions

ArgumentNullException

Thrown when metaModel is null.

Properties

AdaptationSteps

Gets or sets the number of gradient steps to take during inner loop adaptation.

public int AdaptationSteps { get; set; }

Property Value

int

Default: 5.

AggregationType

Gets or sets the aggregation method for graph-level representations.

public GNNAggregationType AggregationType { get; set; }

Property Value

GNNAggregationType

Default: Mean.

CheckpointFrequency

Gets or sets how often to save checkpoints.

public int CheckpointFrequency { get; set; }

Property Value

int

Default: 1000.

DataLoader

Gets or sets the episodic data loader for sampling tasks.

public IEpisodicDataLoader<T, TInput, TOutput>? DataLoader { get; set; }

Property Value

IEpisodicDataLoader<T, TInput, TOutput>

Default: null (tasks must be provided manually to MetaTrain).

DropoutRate

Gets or sets the dropout rate for GNN layers.

public double DropoutRate { get; set; }

Property Value

double

Default: 0.1.

EdgeFeatureDimension

Gets or sets the dimension of edge features in the task graph.

public int EdgeFeatureDimension { get; set; }

Property Value

int

Default: 64.

EdgeThreshold

Gets or sets the threshold for creating edges between tasks.

public double EdgeThreshold { get; set; }

Property Value

double

Default: 0.5 (tasks with similarity above this are connected).

EnableCheckpointing

Gets or sets whether to save checkpoints during training.

public bool EnableCheckpointing { get; set; }

Property Value

bool

Default: false.

EvaluationFrequency

Gets or sets how often to evaluate during meta-training.

public int EvaluationFrequency { get; set; }

Property Value

int

Default: 500.

EvaluationTasks

Gets or sets the number of tasks to use for evaluation.

public int EvaluationTasks { get; set; }

Property Value

int

Default: 100.

GNNHiddenDimension

Gets or sets the hidden dimension for the GNN layers.

public int GNNHiddenDimension { get; set; }

Property Value

int

Default: 256.

GradientClipThreshold

Gets or sets the maximum gradient norm for gradient clipping.

public double? GradientClipThreshold { get; set; }

Property Value

double?

Default: 10.0.

InnerLearningRate

Gets or sets the learning rate for the inner loop (task adaptation).

public double InnerLearningRate { get; set; }

Property Value

double

Default: 0.01.

InnerOptimizer

Gets or sets the optimizer for inner-loop adaptation.

public IGradientBasedOptimizer<T, TInput, TOutput>? InnerOptimizer { get; set; }

Property Value

IGradientBasedOptimizer<T, TInput, TOutput>

Default: null (uses built-in SGD optimizer).

LearnEdgeWeights

Gets or sets whether to learn edge weights during training.

public bool LearnEdgeWeights { get; set; }

Property Value

bool

Default: true.

LossFunction

Gets or sets the loss function for training.

public ILossFunction<T>? LossFunction { get; set; }

Property Value

ILossFunction<T>

Default: null (uses model's default loss function if available).

MaxNeighbors

Gets or sets the maximum number of neighbors per node in sparse graph.

public int MaxNeighbors { get; set; }

Property Value

int

Default: 10.

MetaBatchSize

Gets or sets the number of tasks to sample per meta-training iteration.

public int MetaBatchSize { get; set; }

Property Value

int

Default: 4.

MetaModel

Gets or sets the meta-model to be trained. This is the only required property.

public IFullModel<T, TInput, TOutput> MetaModel { get; set; }

Property Value

IFullModel<T, TInput, TOutput>

MetaOptimizer

Gets or sets the optimizer for meta-parameter updates (outer loop).

public IGradientBasedOptimizer<T, TInput, TOutput>? MetaOptimizer { get; set; }

Property Value

IGradientBasedOptimizer<T, TInput, TOutput>

Default: null (uses built-in Adam optimizer).

NodeEmbeddingDimension

Gets or sets the dimension of node embeddings in the task graph.

public int NodeEmbeddingDimension { get; set; }

Property Value

int

Default: 128.

NumAttentionHeads

Gets or sets the number of attention heads for graph attention.

public int NumAttentionHeads { get; set; }

Property Value

int

Default: 4.

NumMessagePassingLayers

Gets or sets the number of message passing layers in the GNN.

public int NumMessagePassingLayers { get; set; }

Property Value

int

Default: 3.

NumMetaIterations

Gets or sets the total number of meta-training iterations to perform.

public int NumMetaIterations { get; set; }

Property Value

int

Default: 10000.

OuterLearningRate

Gets or sets the learning rate for the outer loop (meta-update).

public double OuterLearningRate { get; set; }

Property Value

double

Default: 0.001.

RandomSeed

Gets or sets the random seed for reproducibility.

public int? RandomSeed { get; set; }

Property Value

int?

Default: null (non-deterministic).

SimilarityMetric

Gets or sets how task similarity is computed for building the task graph.

public TaskSimilarityMetric SimilarityMetric { get; set; }

Property Value

TaskSimilarityMetric

Default: ParameterDistance.

UseFirstOrder

Gets or sets whether to use first-order approximation.

public bool UseFirstOrder { get; set; }

Property Value

bool

Default: true.

UseFullyConnectedGraph

Gets or sets whether to use a fully connected task graph.

public bool UseFullyConnectedGraph { get; set; }

Property Value

bool

Default: false (uses sparse graph based on similarity).

UseLayerNorm

Gets or sets whether to use layer normalization in GNN layers.

public bool UseLayerNorm { get; set; }

Property Value

bool

Default: true.

UseResidualConnections

Gets or sets whether to use residual connections in GNN layers.

public bool UseResidualConnections { get; set; }

Property Value

bool

Default: true.

Methods

Clone()

Creates a deep copy of the GNN Meta options.

public IMetaLearnerOptions<T> Clone()

Returns

IMetaLearnerOptions<T>

A new GNNMetaOptions instance with the same configuration values.

IsValid()

Validates that all GNN Meta configuration options are properly set.

public bool IsValid()

Returns

bool

True if the configuration is valid for GNN Meta training; otherwise, false.