Table of Contents

Class ReptileOptions<T, TInput, TOutput>

Namespace
AiDotNet.MetaLearning.Options
Assembly
AiDotNet.dll

Configuration options for the Reptile meta-learning algorithm.

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

Remarks

Reptile is a simple first-order meta-learning algorithm that doesn't require computing gradients through the adaptation process. Instead, it interpolates between current meta-parameters and adapted parameters.

For Beginners: Reptile is the simplest meta-learning algorithm to understand: 1. Train on a task for several steps 2. Move the starting point slightly toward where you ended up 3. Repeat with many tasks

After seeing many tasks, your starting point becomes great for learning any new task!

Key difference from MAML: Reptile doesn't compute gradients through adaptation. This makes it much simpler to implement and faster to run, with competitive performance.

Constructors

ReptileOptions(IFullModel<T, TInput, TOutput>)

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

public ReptileOptions(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.

Remarks

This is multiplied by InnerBatches to get the total number of inner steps. Total steps = AdaptationSteps * InnerBatches

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).

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.

GradientClipThreshold

Gets or sets the maximum gradient norm for gradient clipping.

public double? GradientClipThreshold { get; set; }

Property Value

double?

Default: 10.0.

InnerBatches

Gets or sets the number of inner batches per adaptation step.

public int InnerBatches { get; set; }

Property Value

int

Default: 1.

Remarks

Total inner loop steps = AdaptationSteps * InnerBatches. This allows fine-grained control over adaptation depth.

For Beginners: Reptile can use many inner steps since it doesn't need to backprop through them. More steps = better task adaptation, which can help with harder tasks.

InnerLearningRate

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

public double InnerLearningRate { get; set; }

Property Value

double

Default: 0.01.

Remarks

This controls how fast the model learns during adaptation on each task. Reptile typically uses standard SGD with this learning rate.

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 with InnerLearningRate).

Interpolation

Gets or sets the interpolation factor for meta-updates.

public double Interpolation { get; set; }

Property Value

double

Default: 1.0.

Remarks

This controls what fraction of the adaptation direction to use. The meta-update is: theta_new = theta_old + (OuterLearningRate * Interpolation) * (theta_adapted - theta_old)

For Beginners: This controls how far to move toward the adapted parameters: - 1.0: Move the full step (scaled by outer learning rate) - 0.5: Move only halfway - 0.1: Move just a little bit

Smaller values are more conservative but slower to learn.

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).

MetaBatchSize

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

public int MetaBatchSize { get; set; }

Property Value

int

Default: 5 (Reptile typically uses smaller batches than MAML).

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 (Reptile uses simple interpolation, not optimizer-based updates).

Remarks

Note: Reptile typically doesn't use an optimizer for outer-loop updates. Instead, it uses a simple interpolation step. This is provided for compatibility with the base interface but is not used in standard Reptile.

NumMetaIterations

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

public int NumMetaIterations { get; set; }

Property Value

int

Default: 10000 (Reptile often requires more iterations than MAML).

OuterLearningRate

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

public double OuterLearningRate { get; set; }

Property Value

double

Default: 1.0 (combined with Interpolation to control update magnitude).

Remarks

In Reptile, this is multiplied with the Interpolation factor to control how far to move toward the adapted parameters. The effective step size is OuterLearningRate * Interpolation.

RandomSeed

Gets or sets the random seed for reproducibility.

public int? RandomSeed { get; set; }

Property Value

int?

Default: null (non-deterministic).

UseFirstOrder

Gets or sets whether to use first-order approximation.

public bool UseFirstOrder { get; set; }

Property Value

bool

Default: true (Reptile is inherently first-order).

Remarks

Reptile is inherently a first-order algorithm - it never computes gradients through the adaptation process. This property is always effectively true.

UseSerialUpdate

Gets or sets whether to use the serial (single-task) or batched update variant.

public bool UseSerialUpdate { get; set; }

Property Value

bool

Default: false (use batched updates for stability).

Remarks

Serial Reptile: Updates meta-parameters after each single task (more variance) Batched Reptile: Averages updates across a batch of tasks (more stable)

The batched variant is recommended for most cases.

Methods

Clone()

Creates a deep copy of the Reptile options.

public IMetaLearnerOptions<T> Clone()

Returns

IMetaLearnerOptions<T>

A new ReptileOptions instance with the same configuration values.

IsValid()

Validates that all Reptile configuration options are properly set.

public bool IsValid()

Returns

bool

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