Table of Contents

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

T

The numeric type used for calculations (e.g., double, float).

TInput

The input data type (e.g., Matrix<T>, Tensor<T>).

TOutput

The 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:

  1. Task-Aware Batching: Tasks are intelligently grouped based on difficulty, similarity, and curriculum requirements

  2. Adaptive Batch Sizes: Dynamic batch sizing based on task complexity and memory constraints (inspired by MetaGrad, ICLR 2023)

  3. Multi-Resolution Batching: Support for hierarchical task organization with varying K-shot configurations within the same batch

  4. Task Relationship Modeling: Explicit encoding of inter-task relationships for improved gradient estimation (inspired by Taskonomy, CVPR 2024)

  5. 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

tasks IMetaLearningTask<T, TInput, TOutput>[]

The array of tasks in this batch.

batchingStrategy BatchingStrategy

The strategy used to create this batch.

taskDifficulties T[]

Optional difficulty scores for each task.

taskSimilarities T[,]

Optional similarity matrix between tasks.

curriculumStage CurriculumStage?

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

int

BatchingStrategy

Gets the batching strategy used to create this batch.

public BatchingStrategy BatchingStrategy { get; }

Property Value

BatchingStrategy

CurriculumStage

Gets the curriculum stage this batch belongs to.

public CurriculumStage CurriculumStage { get; }

Property Value

CurriculumStage

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

double

this[int]

Gets a task at the specified index.

public IMetaLearningTask<T, TInput, TOutput> this[int index] { get; }

Parameters

index int

The 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

int

NumShots

Gets the number of shots per class for tasks in this batch.

public int NumShots { get; }

Property Value

int

NumWays

Gets the number of classes (ways) for tasks in this batch.

public int NumWays { get; }

Property Value

int

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

key string

The 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

startIndex int

Starting index (inclusive).

count int

Number of tasks to include.

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

key string

The metadata key.

value object

The metadata value.

Split(int)

Splits the batch into smaller sub-batches for distributed processing.

public TaskBatch<T, TInput, TOutput>[] Split(int numSubBatches)

Parameters

numSubBatches int

Number of sub-batches to create.

Returns

TaskBatch<T, TInput, TOutput>[]

Array of sub-batches.