Class BOILOptions<T, TInput, TOutput>
- Namespace
- AiDotNet.MetaLearning.Options
- Assembly
- AiDotNet.dll
Configuration options for Body Only Inner Loop (BOIL) algorithm.
public class BOILOptions<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
-
BOILOptions<T, TInput, TOutput>
- Implements
- Inherited Members
Remarks
BOIL is the opposite of ANIL - it only adapts the feature extractor (body) during inner-loop adaptation while keeping the classification head frozen. This explores the hypothesis that task-specific features are more important than task-specific classifiers.
For Beginners: BOIL splits a neural network into two parts:
- Body (Feature Extractor): ADAPTED for each new task
- Head (Classifier): FROZEN during adaptation (uses meta-learned weights)
This is the opposite of ANIL (which freezes body, adapts head). BOIL tests whether it's better to adapt HOW we see things rather than HOW we decide.
When to use BOIL: - When tasks differ more in their visual/input patterns than their decision boundaries - When you have a good meta-learned classifier that works across tasks - When you want to experiment with different adaptation strategies
Reference: Oh, J., Yoo, H., Kim, C., & Yun, S. Y. (2021). BOIL: Towards Representation Change for Few-shot Learning.
Constructors
BOILOptions(IFullModel<T, TInput, TOutput>)
Initializes a new instance of the BOILOptions class with the required meta-model.
public BOILOptions(IFullModel<T, TInput, TOutput> metaModel)
Parameters
metaModelIFullModel<T, TInput, TOutput>The neural network to be trained (required).
Exceptions
- ArgumentNullException
Thrown when metaModel is null.
Properties
AdaptationSteps
Gets or sets the number of adaptation steps (gradient steps on support set).
public int AdaptationSteps { get; set; }
Property Value
- int
Default is 5.
BodyAdaptationFraction
Gets or sets the fraction of body parameters to adapt (for efficiency).
public double BodyAdaptationFraction { get; set; }
Property Value
- double
Default is 1.0 (adapt all body parameters).
Remarks
For Beginners: If your body has millions of parameters, adapting all of them might be slow. This setting lets you adapt only a fraction (e.g., 0.5 = adapt only half the body parameters).
BodyL2Regularization
Gets or sets the L2 regularization strength for the body.
public double BodyL2Regularization { get; set; }
Property Value
- double
Default is 0.0 (no regularization).
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>
EarlyLayerLrMultiplier
Gets or sets the learning rate multiplier for earlier layers (if using layerwise rates).
public double EarlyLayerLrMultiplier { get; set; }
Property Value
- double
Default is 0.1 (earlier layers update 10x slower).
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
FeatureDimension
Gets or sets the dimension of the final feature representation (before head).
public int FeatureDimension { get; set; }
Property Value
- int
Default is 512.
GradientClipThreshold
Gets or sets the maximum gradient norm for gradient clipping.
public double? GradientClipThreshold { get; set; }
Property Value
- double?
Default is 10.0.
InnerLearningRate
Gets or sets the learning rate for the inner loop (body adaptation).
public double InnerLearningRate { get; set; }
Property Value
- double
Default is 0.01.
InnerOptimizer
Gets or sets the optimizer for inner loop updates (body only). Default: null (uses SGD with InnerLearningRate).
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
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 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 neural network with a separable body (feature extractor) and head (classifier). Only the body will be adapted during the inner loop.
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>
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 (meta-update).
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?
ReinitializeBody
Gets or sets whether to reinitialize the body for each task.
public bool ReinitializeBody { get; set; }
Property Value
- bool
Default is false (use meta-learned initialization).
UseFirstOrder
Gets or sets whether to use first-order approximation.
public bool UseFirstOrder { get; set; }
Property Value
- bool
Default is true (BOIL typically uses first-order for efficiency).
UseLayerwiseLearningRates
Gets or sets whether to use layer-wise learning rates for the body.
public bool UseLayerwiseLearningRates { get; set; }
Property Value
- bool
Default is false.
Remarks
For Beginners: Different layers might need different learning rates. Earlier layers (close to input) might need smaller updates than later layers.
Methods
Clone()
Creates a deep copy of the BOIL options.
public IMetaLearnerOptions<T> Clone()
Returns
- IMetaLearnerOptions<T>
A new BOILOptions instance with the same configuration.
IsValid()
Validates that all BOIL configuration options are properly set.
public bool IsValid()
Returns
- bool
True if the configuration is valid; otherwise, false.