Table of Contents

Class MetaOptNetOptions<T, TInput, TOutput>

Namespace
AiDotNet.MetaLearning.Options
Assembly
AiDotNet.dll

Configuration options for Meta-learning with Differentiable Convex Optimization (MetaOptNet) algorithm.

public class MetaOptNetOptions<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
MetaOptNetOptions<T, TInput, TOutput>
Implements
Inherited Members

Remarks

MetaOptNet replaces the gradient-based inner-loop of MAML with a differentiable convex optimization solver. Instead of taking gradient steps, it solves a closed-form optimization problem (like ridge regression or SVM) to get the classifier.

For Beginners: In MAML, the inner loop does gradient descent: "take a step, take a step, take a step..." which can be slow and unstable. MetaOptNet says: "Why iterate? Just solve the optimal answer directly!"

It uses mathematical formulas that give the best classifier in one shot. This is: - Faster: No iterative optimization - More stable: Convex problems have unique solutions - Theoretically grounded: Based on well-understood optimization theory

Reference: Lee, K., Maji, S., Ravichandran, A., & Soatto, S. (2019). Meta-Learning with Differentiable Convex Optimization. CVPR 2019.

Constructors

MetaOptNetOptions(IFullModel<T, TInput, TOutput>)

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

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

Parameters

metaModel IFullModel<T, TInput, TOutput>

The feature encoder to be trained (required).

Exceptions

ArgumentNullException

Thrown when metaModel is null.

Properties

AdaptationSteps

Gets or sets the number of adaptation steps.

public int AdaptationSteps { get; set; }

Property Value

int

Default is 1 (MetaOptNet uses closed-form solution).

CheckpointFrequency

Gets or sets how often to save checkpoints.

public int CheckpointFrequency { get; set; }

Property Value

int

DataLoader

Gets or sets the episodic data loader for sampling tasks. Default: null (tasks must be provided manually to MetaTrain).

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

Property Value

IEpisodicDataLoader<T, TInput, TOutput>

EmbeddingDimension

Gets or sets the dimension of the feature embedding.

public int EmbeddingDimension { get; set; }

Property Value

int

Default is 512.

EnableCheckpointing

Gets or sets whether to save model checkpoints.

public bool EnableCheckpointing { get; set; }

Property Value

bool

EncoderL2Regularization

Gets or sets the L2 regularization strength for the encoder.

public double EncoderL2Regularization { get; set; }

Property Value

double

Default is 0.0 (no regularization).

EvaluationFrequency

Gets or sets how often to evaluate the meta-learner.

public int EvaluationFrequency { get; set; }

Property Value

int

EvaluationTasks

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

public int EvaluationTasks { get; set; }

Property Value

int

GradientClipThreshold

Gets or sets the maximum gradient norm for gradient clipping.

public double? GradientClipThreshold { get; set; }

Property Value

double?

Default is 10.0.

InitialTemperature

Gets or sets the initial temperature value.

public double InitialTemperature { get; set; }

Property Value

double

Default is 1.0.

InnerLearningRate

Gets or sets the learning rate for the inner loop (not used - solver is analytical).

public double InnerLearningRate { get; set; }

Property Value

double

Default is 0.01 (placeholder, not used).

InnerOptimizer

Gets or sets the optimizer for inner loop updates. Default: null (not used in MetaOptNet - inner loop is solved analytically).

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

Property Value

IGradientBasedOptimizer<T, TInput, TOutput>

LossFunction

Gets or sets the loss function for training. Default: null (uses cross-entropy loss internally).

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

Property Value

ILossFunction<T>

MaxSolverIterations

Gets or sets the maximum number of iterations for iterative solvers (like SVM).

public int MaxSolverIterations { get; set; }

Property Value

int

Default is 100.

MetaBatchSize

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

public int MetaBatchSize { get; set; }

Property Value

int

Default is 4.

MetaModel

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

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

Property Value

IFullModel<T, TInput, TOutput>

Remarks

The meta-model should be a feature encoder (typically a CNN for images). MetaOptNet learns the encoder while using a convex solver for classification.

MetaOptimizer

Gets or sets the optimizer for meta-parameter (outer loop) updates. Default: null (uses built-in Adam optimizer with OuterLearningRate).

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

Property Value

IGradientBasedOptimizer<T, TInput, TOutput>

NormalizeEmbeddings

Gets or sets whether to normalize embeddings before solving.

public bool NormalizeEmbeddings { get; set; }

Property Value

bool

Default is true.

NumClasses

Gets or sets the number of output classes.

public int NumClasses { get; set; }

Property Value

int

Default is 5.

NumMetaIterations

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

public int NumMetaIterations { get; set; }

Property Value

int

Default is 1000.

OuterLearningRate

Gets or sets the learning rate for the outer loop (encoder training).

public double OuterLearningRate { get; set; }

Property Value

double

Default is 0.001.

RandomSeed

Gets or sets the random seed for reproducibility.

public int? RandomSeed { get; set; }

Property Value

int?

RegularizationStrength

Gets or sets the regularization parameter for the convex solver.

public double RegularizationStrength { get; set; }

Property Value

double

Default is 1.0.

Remarks

For Beginners: Regularization prevents overfitting to the support set. Higher values mean more regularization (simpler solutions).

SolverTolerance

Gets or sets the convergence tolerance for iterative solvers.

public double SolverTolerance { get; set; }

Property Value

double

Default is 1e-6.

SolverType

Gets or sets the type of convex solver to use.

public ConvexSolverType SolverType { get; set; }

Property Value

ConvexSolverType

Default is RidgeRegression.

Remarks

For Beginners: - RidgeRegression: Simple and fast, works well for most tasks - SVM: More powerful but slower, better for hard classification boundaries

UseFirstOrder

Gets or sets whether to use first-order approximation.

public bool UseFirstOrder { get; set; }

Property Value

bool

Default is false (MetaOptNet uses implicit differentiation).

UseLearnedTemperature

Gets or sets whether to use a learned temperature for scaling.

public bool UseLearnedTemperature { get; set; }

Property Value

bool

Default is true.

Methods

Clone()

Creates a deep copy of the MetaOptNet options.

public IMetaLearnerOptions<T> Clone()

Returns

IMetaLearnerOptions<T>

A new MetaOptNetOptions instance with the same configuration.

IsValid()

Validates that all MetaOptNet configuration options are properly set.

public bool IsValid()

Returns

bool

True if the configuration is valid; otherwise, false.