IMemoryBank<T>
Interfaces · AiDotNet.SelfSupervisedLearning
Defines the contract for memory banks used in contrastive learning methods.
Known implementations: MemoryBank<T>
For Beginners
A memory bank is a queue that stores embeddings from previous batches. This provides a large pool of negative samples without needing huge batch sizes.
How It Works
Why use a memory bank?
Used by: MoCo, MoCo v2 (not MoCo v3, SimCLR, BYOL, or SimSiam)
Example usage:
Properties
| Property | Summary |
|---|---|
bool IsFull { get; } |
Gets whether the memory bank is full (has reached capacity). |
int Capacity { get; } |
Gets the maximum capacity of the memory bank (queue size). |
int CurrentSize { get; } |
Gets the current number of stored embeddings. |
int EmbeddingDimension { get; } |
Gets the embedding dimension of stored vectors. |
Methods
| Method | Summary |
|---|---|
Tensor<T> GetAll() |
Gets all stored embeddings for use as negative samples. |
Tensor<T> Sample(int count) |
Gets a random subset of stored embeddings. |
void Clear() |
Clears all stored embeddings and resets the memory bank. |
void Enqueue(Tensor<T> embeddings) |
Adds new embeddings to the memory bank (FIFO queue). |
void UpdateWithMomentum(int[] indices, Tensor<T> newEmbeddings, double momentum) |
Updates embeddings by averaging with new values (for soft updates). |