Class TADAMOptions<T, TInput, TOutput>
- Namespace
- AiDotNet.MetaLearning.Options
- Assembly
- AiDotNet.dll
Configuration options for Task-Dependent Adaptive Metric (TADAM) algorithm.
public class TADAMOptions<T, TInput, TOutput> : IMetaLearnerOptions<T>
Type Parameters
TThe numeric data type used for calculations (e.g., float, double).
TInputThe input data type (e.g., Matrix<T>, Tensor<T>).
TOutputThe output data type (e.g., Vector<T>, Tensor<T>).
- Inheritance
-
TADAMOptions<T, TInput, TOutput>
- Implements
- Inherited Members
Remarks
TADAM extends prototypical networks by incorporating task-dependent metric learning. It uses task conditioning (TC) to modulate the feature extraction process based on the task at hand, and metric scaling to adapt distances in embedding space.
For Beginners: TADAM improves on Prototypical Networks by:
- Task Conditioning (TC): Adjusts features based on the specific task
- Metric Scaling: Learns how to weight different feature dimensions
- Auxiliary Co-Training: Uses additional classification to improve features
Think of it as ProtoNets that "pay attention" to what matters for each specific task.
Constructors
TADAMOptions(IFullModel<T, TInput, TOutput>)
Initializes a new instance of the TADAMOptions class with the required meta-model.
public TADAMOptions(IFullModel<T, TInput, TOutput> metaModel)
Parameters
metaModelIFullModel<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 (TADAM uses feed-forward task conditioning).
AuxiliaryLossWeight
Gets or sets the weight for auxiliary loss.
public double AuxiliaryLossWeight { get; set; }
Property Value
- double
Default is 0.5.
CheckpointFrequency
Gets or sets how often to save checkpoints.
public int CheckpointFrequency { get; set; }
Property Value
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 embedding dimension.
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
EvaluationFrequency
Gets or sets how often to evaluate the meta-learner.
public int EvaluationFrequency { get; set; }
Property Value
EvaluationTasks
Gets or sets the number of tasks to use for evaluation.
public int EvaluationTasks { get; set; }
Property Value
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 value for the learnable temperature parameter.
public double InitialTemperature { get; set; }
Property Value
- double
Default is 1.0.
Remarks
The temperature controls how "soft" or "hard" the distance-based classification is. Lower values make the softmax sharper (more confident predictions).
InnerLearningRate
Gets or sets the learning rate for the inner loop (not used in TADAM).
public double InnerLearningRate { get; set; }
Property Value
- double
Default is 0.01.
InnerOptimizer
Gets or sets the optimizer for inner loop updates. Default: null (TADAM uses feed-forward comparison with task conditioning).
public IGradientBasedOptimizer<T, TInput, TOutput>? InnerOptimizer { get; set; }
Property Value
- IGradientBasedOptimizer<T, TInput, TOutput>
L2Regularization
Gets or sets the L2 regularization strength.
public double L2Regularization { get; set; }
Property Value
- double
Default is 0.0 (no regularization).
LossFunction
Gets or sets the loss function for training. Default: null (uses cross-entropy loss internally).
public ILossFunction<T>? LossFunction { get; set; }
Property Value
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 that maps inputs to an embedding space. TADAM will apply task conditioning to modulate the extracted features.
For Beginners: This is typically a CNN for images. TADAM will learn to adjust how this encoder works based on each specific task.
MetaOptimizer
Gets or sets the optimizer for network 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.
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?
TaskEmbeddingDimension
Gets or sets the dimension of task embeddings.
public int TaskEmbeddingDimension { get; set; }
Property Value
- int
Default is 64.
UseAuxiliaryCoTraining
Gets or sets whether to use auxiliary co-training.
public bool UseAuxiliaryCoTraining { get; set; }
Property Value
- bool
Default is false.
Remarks
For Beginners: Auxiliary co-training adds an extra classification objective to help learn better features. It can improve performance but adds computational cost.
UseFirstOrder
Gets or sets whether to use first-order approximation.
public bool UseFirstOrder { get; set; }
Property Value
- bool
Default is true since TADAM doesn't use gradient-based inner loop.
UseMetricScaling
Gets or sets whether to use metric scaling.
public bool UseMetricScaling { get; set; }
Property Value
- bool
Default is true.
Remarks
For Beginners: Metric scaling learns to weight different dimensions of the embedding space differently when computing distances.
UseTaskConditioning
Gets or sets whether to use task conditioning (FiLM layers).
public bool UseTaskConditioning { get; set; }
Property Value
- bool
Default is true.
Remarks
For Beginners: Task conditioning adjusts the feature encoder based on what task is being solved. This helps the network adapt its representation.
Methods
Clone()
Creates a deep copy of the TADAM options.
public IMetaLearnerOptions<T> Clone()
Returns
- IMetaLearnerOptions<T>
A new TADAMOptions instance with the same configuration.
IsValid()
Validates that all TADAM configuration options are properly set.
public bool IsValid()
Returns
- bool
True if the configuration is valid; otherwise, false.