CAVIAOptions<T, TInput, TOutput>

Options & Configuration · AiDotNet.MetaLearning.Options

Configuration options for the CAVIA (Fast Context Adaptation via Meta-Learning) algorithm.

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

Implements: IMetaLearnerOptions<T>

For Beginners

CAVIA is like MAML but smarter about what it adapts.

Imagine you’re a chef learning to cook different cuisines:

  • Your cooking skills (shared params) stay the same across cuisines
  • But for each cuisine, you adjust your seasoning preferences (context params)
  • CAVIA only adjusts the “seasoning” for each new task, not all your skills
  • This makes adaptation much faster and less likely to overfit

The context vector is a small set of numbers that tells the model “this is the kind of task we’re dealing with.” During adaptation, only these numbers change - the main model stays fixed.

How It Works

CAVIA separates model parameters into two groups:

  1. Shared parameters (body): Updated only in the outer loop across all tasks
  2. Context parameters: Task-specific, adapted in the inner loop per task

By only adapting context parameters in the inner loop, CAVIA is:

  • Much faster than MAML (fewer parameters to differentiate through)
  • Less prone to meta-overfitting (fewer adapted parameters = stronger regularization)
  • Conceptually cleaner (explicit separation of shared vs. task-specific knowledge)

Reference: Zintgraf, L. M., Shiarli, K., Kurin, V., Hofmann, K., & Whiteson, S. (2019). Fast Context Adaptation via Meta-Learning. ICML 2019.

Constructors

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

Properties

Property Summary
CAVIAContextInjectionMode ContextInjectionMode { get; set; } Gets or sets how the context vector is injected into the model’s computation.
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 to be trained.
IGradientBasedOptimizer<T, TInput, TOutput> InnerOptimizer { get; set; } Optimizer for task adaptation.
IGradientBasedOptimizer<T, TInput, TOutput> MetaOptimizer { get; set; } Optimizer for the meta-update.
ILossFunction<T> LossFunction { get; set; } Loss function for meta-training; null uses the meta-model’s default loss.
bool EnableCheckpointing { get; set; } Gets or sets whether to save model checkpoints.
bool UseContextRegularization { get; set; } Gets or sets whether to apply L2 regularization on context parameters during adaptation.
bool UseFirstOrder { get; set; } Gets or sets whether to use first-order approximation for meta-gradients.
double ContextInitValue { get; set; } Gets or sets the initial value for context parameters at the start of each task.
double ContextRegularizationStrength { get; set; } Gets or sets the L2 regularization strength for context parameters.
double InnerLearningRate { get; set; } Gets or sets the learning rate for the inner loop (context parameter adaptation).
double OuterLearningRate { get; set; } Gets or sets the learning rate for the outer loop (shared parameter updates).
double? GradientClipThreshold { get; set; } Gets or sets the maximum gradient norm for gradient clipping.
int AdaptationSteps { get; set; } Gets or sets the number of gradient steps for inner loop context adaptation.
int CheckpointFrequency { get; set; } Gets or sets how often to save checkpoints.
int ContextDimension { get; set; } Gets or sets the dimension of the context parameter vector.
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 NumContextVectors { get; set; } Gets or sets the number of context vectors to use.
int NumMetaIterations { get; set; } Gets or sets the total number of meta-training iterations.
int? RandomSeed { get; set; } Gets or sets the random seed for reproducibility.

Methods

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