RelationNetworkOptions<T, TInput, TOutput>

Options & Configuration · AiDotNet.MetaLearning.Options

Configuration options for Relation Networks algorithm.

Inheritance: ModelOptions → RelationNetworkOptions<T, TInput, TOutput>

Implements: IMetaLearnerOptions<T>

For Beginners

Relation Networks learns how to compare examples:

  1. Encode all examples (support and query) with a feature encoder
  2. Sum each class’s support embeddings into one class feature
  3. Concatenate each class feature with each query’s features and pass the pair through a relation module
  4. The relation module outputs a relation score between 0 and 1
  5. The class with the highest score is the prediction; training pushes the true class’s score to 1 and the

others to 0 with mean squared error

Instead of using predefined distances (like Euclidean), it learns a neural network to measure “how related” two examples are.

How It Works

Relation Networks learn to compare query examples with class examples by learning a relation function that measures similarity. Unlike metric learning approaches that use fixed distance functions, Relation Networks learn the relation function end-to-end.

Constructors

Constructor Summary
RelationNetworkOptions(IFullModel<T, TInput, TOutput> metaModel) Initializes a new instance of the RelationNetworkOptions class with the required meta-model.

Properties

Property Summary
IEpisodicDataLoader<T, TInput, TOutput> DataLoader { get; set; } Gets or sets the episodic data loader for sampling tasks.
IFullModel<T, TInput, TOutput> MetaModel { get; set; } Gets or sets the meta-model (feature encoder) to be trained.
IGradientBasedOptimizer<T, TInput, TOutput> InnerOptimizer { get; set; } Must stay null: this algorithm takes no plain gradient inner step (it adapts without one, or by its own update rule), so a supplied optimizer is rejected when the learner is built.
IGradientBasedOptimizer<T, TInput, TOutput> MetaOptimizer { get; set; } Optimizer for the meta-update.
ILossFunction<T> LossFunction { get; set; } Loss function for meta-training; null uses mean squared error.
RelationAggregationMethod AggregationMethod { get; set; } Gets or sets how a class’s support examples meet a query.
RelationModuleType RelationType { get; set; } Gets or sets the relation module’s architecture.
bool ApplyFeatureTransform { get; set; } Gets or sets whether to apply a learned linear map to the embeddings before pairing them.
bool EnableCheckpointing { get; set; } Gets or sets whether to save model checkpoints.
bool UseFirstOrder { get; set; } Gets or sets whether to use first-order approximation.
bool UseMultiHeadRelation { get; set; } Gets or sets whether to average several independently initialised relation modules.
double FeatureEncoderL2Reg { get; set; } Gets or sets the weight decay of the embedding module.
double InnerLearningRate { get; set; } Gets or sets the learning rate for the inner loop (not used in Relation Networks).
double OuterLearningRate { get; set; } Gets or sets the learning rate for the outer loop (encoder and relation module training).
double RelationDropout { get; set; } Gets or sets the dropout rate of the relation module’s pair representation while meta-training.
double RelationModuleL2Reg { get; set; } Gets or sets the weight decay of the relation modules.
double? GradientClipThreshold { get; set; } Gets or sets the maximum gradient norm for gradient clipping.
int AdaptationSteps { get; set; } Gets or sets the number of adaptation steps.
int CheckpointFrequency { get; set; } Gets or sets how often to save checkpoints.
int EvaluationFrequency { get; set; } Gets or sets how often to evaluate the meta-learner.
int EvaluationTasks { get; set; } Gets or sets the number of tasks to use for evaluation.
int MetaBatchSize { get; set; } Gets or sets the number of tasks to sample per meta-training iteration.
int NumClasses { get; set; } Gets or sets the number of output classes.
int NumHeads { get; set; } Gets or sets the number of relation modules averaged when UseMultiHeadRelation is on.
int NumMetaIterations { get; set; } Gets or sets the total number of meta-training iterations.
int RelationHiddenDimension { get; set; } Gets or sets the width of the relation module’s pair representation.
int? RandomSeed { get; set; } Gets or sets the random seed for reproducibility.

Methods

Method Summary
IMetaLearnerOptions<T> Clone() Creates a deep copy of the Relation Network options.
bool IsValid() Validates that all Relation Network configuration options are properly set.