Class BatchConfigurationBuilder<TBatch>
- Namespace
- AiDotNet.Extensions
- Assembly
- AiDotNet.dll
Builder for configuring batch iteration with a fluent API.
public class BatchConfigurationBuilder<TBatch> : IEnumerable<TBatch>, IEnumerable
Type Parameters
TBatchThe type of batch returned by iteration.
- Inheritance
-
BatchConfigurationBuilder<TBatch>
- Implements
-
IEnumerable<TBatch>
- Inherited Members
- Extension Methods
Remarks
This builder allows chaining configuration methods before iteration. Implements IEnumerable to support foreach loops and LINQ operations.
Constructors
BatchConfigurationBuilder(IBatchIterable<TBatch>, int?)
Initializes a new instance of the BatchConfigurationBuilder.
public BatchConfigurationBuilder(IBatchIterable<TBatch> source, int? batchSize)
Parameters
sourceIBatchIterable<TBatch>The batch iterable source.
batchSizeint?Optional batch size override.
Methods
DropLast()
Drops the last incomplete batch if the dataset doesn't divide evenly.
public BatchConfigurationBuilder<TBatch> DropLast()
Returns
- BatchConfigurationBuilder<TBatch>
This builder for method chaining.
Remarks
Useful when your model requires consistent batch sizes (e.g., batch normalization).
GetEnumerator()
Returns an enumerator that iterates through the batches.
public IEnumerator<TBatch> GetEnumerator()
Returns
- IEnumerator<TBatch>
An enumerator for the batch sequence.
KeepLast()
Keeps the last batch even if incomplete.
public BatchConfigurationBuilder<TBatch> KeepLast()
Returns
- BatchConfigurationBuilder<TBatch>
This builder for method chaining.
Remarks
This is the default behavior. Call this explicitly for clarity or after DropLast().
NoShuffle()
Disables shuffling of data before batching.
public BatchConfigurationBuilder<TBatch> NoShuffle()
Returns
- BatchConfigurationBuilder<TBatch>
This builder for method chaining.
Remarks
Use this when you need deterministic iteration order, such as during evaluation.
Shuffled()
Enables shuffling of data before batching.
public BatchConfigurationBuilder<TBatch> Shuffled()
Returns
- BatchConfigurationBuilder<TBatch>
This builder for method chaining.
Remarks
Shuffling is enabled by default. Call this explicitly for clarity or after NoShuffle().
WithSeed(int)
Sets a random seed for reproducible shuffling.
public BatchConfigurationBuilder<TBatch> WithSeed(int seed)
Parameters
seedintThe random seed value.
Returns
- BatchConfigurationBuilder<TBatch>
This builder for method chaining.
Remarks
Setting a seed ensures the same shuffle order each time for reproducibility.