Class TaskBatch<T, TInput, TOutput>
- Namespace
- AiDotNet.MetaLearning.Data
- Assembly
- AiDotNet.dll
Represents a batch of tasks for meta-learning with advanced batching strategies.
public class TaskBatch<T, TInput, TOutput>
Type Parameters
TThe numeric type used for calculations (e.g., double, float).
TInputThe input data type (e.g., Matrix<T>, Tensor<T>).
TOutputThe output data type (e.g., Vector<T>, Tensor<T>).
- Inheritance
-
TaskBatch<T, TInput, TOutput>
- Inherited Members
Remarks
For Beginners: A task batch groups multiple tasks together for efficient processing. This is similar to how regular machine learning uses batches of examples, but here we're batching entire tasks instead of individual examples.
For example, instead of processing one 5-way 1-shot task at a time, you might process 32 tasks together in a batch for faster training.
Advanced Features Beyond Industry Standards:
This implementation includes cutting-edge features from recent meta-learning research:
Task-Aware Batching: Tasks are intelligently grouped based on difficulty, similarity, and curriculum requirements
Adaptive Batch Sizes: Dynamic batch sizing based on task complexity and memory constraints (inspired by MetaGrad, ICLR 2023)
Multi-Resolution Batching: Support for hierarchical task organization with varying K-shot configurations within the same batch
Task Relationship Modeling: Explicit encoding of inter-task relationships for improved gradient estimation (inspired by Taskonomy, CVPR 2024)
Curriculum-Aware Sampling: Batches are constructed to follow optimal learning curricula (inspired by CL-Curriculum, NeurIPS 2023)
Constructors
TaskBatch(IMetaLearningTask<T, TInput, TOutput>[], BatchingStrategy, T[]?, T[,]?, CurriculumStage?)
Initializes a new instance of the TaskBatch class.
public TaskBatch(IMetaLearningTask<T, TInput, TOutput>[] tasks, BatchingStrategy batchingStrategy = BatchingStrategy.Uniform, T[]? taskDifficulties = null, T[,]? taskSimilarities = null, CurriculumStage? curriculumStage = null)
Parameters
tasksIMetaLearningTask<T, TInput, TOutput>[]The array of tasks in this batch.
batchingStrategyBatchingStrategyThe strategy used to create this batch.
taskDifficultiesT[]Optional difficulty scores for each task.
taskSimilaritiesT[,]Optional similarity matrix between tasks.
curriculumStageCurriculumStage?Optional curriculum stage information.
Properties
AverageDifficulty
Gets the average difficulty of tasks in this batch.
public T AverageDifficulty { get; }
Property Value
- T
AverageTaskSimilarity
Gets the average task similarity within this batch.
public T AverageTaskSimilarity { get; }
Property Value
- T
BatchSize
Gets the number of tasks in this batch.
public int BatchSize { get; }
Property Value
BatchingStrategy
Gets the batching strategy used to create this batch.
public BatchingStrategy BatchingStrategy { get; }
Property Value
CurriculumStage
Gets the curriculum stage this batch belongs to.
public CurriculumStage CurriculumStage { get; }
Property Value
DifficultyVariance
Gets the difficulty variance within this batch. Lower values indicate more homogeneous batches.
public T DifficultyVariance { get; }
Property Value
- T
EstimatedMemoryMB
Gets the memory footprint estimate for this batch (in MB).
public double EstimatedMemoryMB { get; }
Property Value
this[int]
Gets a task at the specified index.
public IMetaLearningTask<T, TInput, TOutput> this[int index] { get; }
Parameters
indexintThe zero-based index of the task.
Property Value
- IMetaLearningTask<T, TInput, TOutput>
The task at the specified index.
NumQueryPerClass
Gets the number of query examples per class for tasks in this batch.
public int NumQueryPerClass { get; }
Property Value
NumShots
Gets the number of shots per class for tasks in this batch.
public int NumShots { get; }
Property Value
NumWays
Gets the number of classes (ways) for tasks in this batch.
public int NumWays { get; }
Property Value
TaskDifficulties
Gets difficulty scores for each task (if available). Higher values indicate harder tasks.
public T[]? TaskDifficulties { get; }
Property Value
- T[]
TaskSimilarities
Gets the similarity matrix between tasks (if available). TaskSimilarities[i, j] represents similarity between task i and task j.
public T[,]? TaskSimilarities { get; }
Property Value
- T[,]
Tasks
Gets the array of tasks in this batch.
public IMetaLearningTask<T, TInput, TOutput>[] Tasks { get; }
Property Value
- IMetaLearningTask<T, TInput, TOutput>[]
Methods
GetMetadata(string)
Gets custom metadata associated with this batch.
public object? GetMetadata(string key)
Parameters
keystringThe metadata key.
Returns
- object
The metadata value if exists; otherwise null.
GetRange(int, int)
Gets a subset of tasks from this batch.
public TaskBatch<T, TInput, TOutput> GetRange(int startIndex, int count)
Parameters
Returns
- TaskBatch<T, TInput, TOutput>
A new TaskBatch containing the subset of tasks.
SetMetadata(string, object)
Sets custom metadata for this batch.
public void SetMetadata(string key, object value)
Parameters
Split(int)
Splits the batch into smaller sub-batches for distributed processing.
public TaskBatch<T, TInput, TOutput>[] Split(int numSubBatches)
Parameters
numSubBatchesintNumber of sub-batches to create.
Returns
- TaskBatch<T, TInput, TOutput>[]
Array of sub-batches.