OptimizationDataBatcher<T, TInput, TOutput>

Models & Types · AiDotNet.Optimizers

Provides batch iteration utilities for optimization input data.

For Beginners

When training machine learning models, you typically don’t feed all your data at once. Instead, you break it into smaller “batches” and train on each batch. This class makes that process easy and efficient:

How It Works

OptimizationDataBatcher provides efficient batch iteration over optimization input data, integrating with the DataLoader batching infrastructure for consistent behavior.

Constructors

Constructor Summary
OptimizationDataBatcher(OptimizationInputData<T, TInput, TOutput> inputData, int batchSize, bool shuffle, bool dropLast, int? seed, IDataSampler sampler, int epoch) Initializes a new instance of the OptimizationDataBatcher class.

Properties

Property Summary
int BatchSize { get; } Gets the batch size.
int DataSize { get; } Gets the total number of samples in the training data.
int NumBatches { get; } Gets the number of batches per epoch.

Methods

Method Summary
IEnumerable<ValueTuple<TInput, TOutput, int[]>> GetBatches() Iterates through training data in batches.
IEnumerable<int[]> GetBatchIndices() Iterates through training data in batches, returning only the indices.
OptimizationDataBatcher<T, TInput, TOutput> WithClassBalancing(IReadOnlyList<int> labels, int numClasses) Creates a new batcher with weighted sampling for class balancing.
OptimizationDataBatcher<T, TInput, TOutput> WithCurriculumLearning(IEnumerable<TDifficulty> difficulties, int totalEpochs, CurriculumStrategy strategy) Creates a new batcher with curriculum learning.
OptimizationDataBatcher<T, TInput, TOutput> WithSampler(IDataSampler sampler) Creates a new batcher with a different sampler.