Class MANNOptions<T, TInput, TOutput>
- Namespace
- AiDotNet.MetaLearning.Options
- Assembly
- AiDotNet.dll
Configuration options for Memory-Augmented Neural Networks (MANN) algorithm.
public class MANNOptions<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
-
MANNOptions<T, TInput, TOutput>
- Implements
- Inherited Members
Remarks
Memory-Augmented Neural Networks combine a neural network controller with an external memory matrix. The network can read from and write to this memory, enabling rapid learning by storing new information directly in memory during adaptation.
For Beginners: MANN is like a neural network with a notebook:
- The "controller" (neural network) processes inputs
- The "memory" stores important information for later
- Read heads retrieve relevant memories
- Write heads store new information
This allows one-shot learning - see an example once, store it, use it later!
Constructors
MANNOptions(IFullModel<T, TInput, TOutput>)
Initializes a new instance of the MANNOptions class with the required meta-model.
public MANNOptions(IFullModel<T, TInput, TOutput> metaModel)
Parameters
metaModelIFullModel<T, TInput, TOutput>The controller network to be trained (required).
Examples
// Create MANN with minimal configuration
var options = new MANNOptions<double, Tensor<double>, Tensor<double>>(myController);
var mann = new MANNAlgorithm<double, Tensor<double>, Tensor<double>>(options);
// Create MANN with custom memory configuration
var options = new MANNOptions<double, Tensor<double>, Tensor<double>>(myController)
{
MemorySize = 256,
MemoryKeySize = 128,
NumReadHeads = 4
};
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 (MANN uses memory-based adaptation).
CheckpointFrequency
Gets or sets how often to save checkpoints.
public int CheckpointFrequency { get; set; }
Property Value
ClearMemoryBetweenTasks
Gets or sets whether to clear memory between tasks.
public bool ClearMemoryBetweenTasks { get; set; }
Property Value
- bool
Default is false.
Remarks
For Beginners: If true, memory is partially cleared between tasks. If false, memory persists, enabling lifelong learning.
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>
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.
InnerLearningRate
Gets or sets the learning rate for the inner loop (not used in MANN).
public double InnerLearningRate { get; set; }
Property Value
- double
Default is 0.01.
Remarks
Note: MANN doesn't perform gradient-based inner loop adaptation. This value is kept for interface compatibility.
LossFunction
Gets or sets the loss function for training. Default: null (uses cross-entropy loss internally).
public ILossFunction<T>? LossFunction { get; set; }
Property Value
MemoryKeySize
Gets or sets the dimension of memory keys.
public int MemoryKeySize { get; set; }
Property Value
- int
Default is 64.
Remarks
For Beginners: The size of the "index" used to find memories. Larger keys can encode more specific queries.
MemoryRegularization
Gets or sets the memory regularization strength.
public double MemoryRegularization { get; set; }
Property Value
- double
Default is 0.0 (no regularization).
MemoryRetentionRatio
Gets or sets the ratio of memory to retain when clearing.
public double MemoryRetentionRatio { get; set; }
Property Value
- double
Default is 0.5 (keep 50%).
MemorySize
Gets or sets the number of memory slots.
public int MemorySize { get; set; }
Property Value
- int
Default is 128.
Remarks
For Beginners: How many "pages" in the memory notebook. More slots = more storage, but more computation.
MemoryUsageThreshold
Gets or sets the threshold for memory usage when consolidating.
public double MemoryUsageThreshold { get; set; }
Property Value
- double
Default is 0.1.
MemoryValueSize
Gets or sets the dimension of memory values.
public int MemoryValueSize { get; set; }
Property Value
- int
Default is 64.
Remarks
For Beginners: How much information each memory slot can hold.
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 (controller network) 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 acts as the controller that processes inputs and generates keys for memory read/write operations.
For Beginners: This is the neural network that makes decisions about what to read from and write to memory.
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>
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.
NumReadHeads
Gets or sets the number of read heads.
public int NumReadHeads { get; set; }
Property Value
- int
Default is 1.
Remarks
For Beginners: How many different ways to query memory simultaneously. Multiple heads can retrieve different types of information.
NumWriteHeads
Gets or sets the number of write heads.
public int NumWriteHeads { get; set; }
Property Value
- int
Default is 1.
OuterLearningRate
Gets or sets the learning rate for the outer loop (controller 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?
ReadHeadOptions
Gets or sets options for the read head configuration.
public object? ReadHeadOptions { get; set; }
Property Value
UseCommonPatternsInitialization
Gets or sets whether to initialize with common patterns.
public bool UseCommonPatternsInitialization { get; set; }
Property Value
- bool
Default is false.
UseFirstOrder
Gets or sets whether to use first-order approximation.
public bool UseFirstOrder { get; set; }
Property Value
- bool
Default is true since MANN doesn't use gradient-based inner loop.
UseHierarchicalMemory
Gets or sets whether to use hierarchical memory organization.
public bool UseHierarchicalMemory { get; set; }
Property Value
- bool
Default is false.
UseMemoryConsolidation
Gets or sets whether to use memory consolidation.
public bool UseMemoryConsolidation { get; set; }
Property Value
- bool
Default is false.
Remarks
Memory consolidation periodically removes rarely-used memories to make room for new information.
UseMemoryPreInitialization
Gets or sets whether to pre-initialize memory.
public bool UseMemoryPreInitialization { get; set; }
Property Value
- bool
Default is false.
UseOutputSoftmax
Gets or sets whether to apply softmax to output.
public bool UseOutputSoftmax { get; set; }
Property Value
- bool
Default is true.
UseValueProjection
Gets or sets whether to project values before storing.
public bool UseValueProjection { get; set; }
Property Value
- bool
Default is false.
WriteHeadOptions
Gets or sets options for the write head configuration.
public object? WriteHeadOptions { get; set; }
Property Value
Methods
Clone()
Creates a deep copy of the MANN options.
public IMetaLearnerOptions<T> Clone()
Returns
- IMetaLearnerOptions<T>
A new MANNOptions instance with the same configuration.
IsValid()
Validates that all MANN configuration options are properly set.
public bool IsValid()
Returns
- bool
True if the configuration is valid; otherwise, false.