Table of Contents

Class CurriculumSampler<T>

Namespace
AiDotNet.Data.Sampling
Assembly
AiDotNet.dll

A sampler that implements curriculum learning by progressively introducing harder samples.

public class CurriculumSampler<T> : EpochAdaptiveSamplerBase<T>, IDataSampler

Type Parameters

T

The numeric type for difficulty scores.

Inheritance
CurriculumSampler<T>
Implements
Inherited Members

Remarks

CurriculumSampler implements the idea that models learn better when training starts with easy examples and gradually progresses to harder ones, similar to how humans learn complex subjects step by step.

For Beginners: Imagine teaching someone math: you start with 2+2, not calculus. Curriculum learning applies this principle to machine learning:

  • Epoch 1: Mostly easy samples (simple patterns, clear examples)
  • Epoch 5: Mix of easy and medium samples
  • Epoch 10: All samples including hard ones

This often leads to faster convergence and better final performance.

Example:

// Difficulty scores (0 = easy, 1 = hard)
var difficulties = samples.Select(s => ComputeDifficulty(s)).ToList();
var sampler = new CurriculumSampler<float>(difficulties, totalEpochs: 20);

for (int epoch = 0; epoch < 20; epoch++)
{
    sampler.OnEpochStart(epoch);
    foreach (var idx in sampler.GetIndices())
    {
        // Earlier epochs sample more easy examples
    }
}

Constructors

CurriculumSampler(IEnumerable<T>, int, CurriculumStrategy, int?)

Initializes a new instance of the CurriculumSampler class.

public CurriculumSampler(IEnumerable<T> difficulties, int totalEpochs, CurriculumStrategy strategy = CurriculumStrategy.Linear, int? seed = null)

Parameters

difficulties IEnumerable<T>

Difficulty score for each sample (0 = easiest, 1 = hardest).

totalEpochs int

Total number of epochs for curriculum completion.

strategy CurriculumStrategy

The curriculum progression strategy.

seed int?

Optional random seed for reproducibility.

Properties

CurrentDifficultyThreshold

Gets the current difficulty threshold based on epoch and strategy.

public double CurrentDifficultyThreshold { get; }

Property Value

double

Length

Gets the total number of samples this sampler will produce per epoch.

public override int Length { get; }

Property Value

int

Remarks

This may differ from the dataset size for oversampling or undersampling strategies.

Methods

GetIndicesCore()

Core implementation for generating indices. Override this in derived classes.

protected override IEnumerable<int> GetIndicesCore()

Returns

IEnumerable<int>

An enumerable of sample indices.

SetCompetence(double)

Sets the model's current competence level for competence-based curriculum.

public void SetCompetence(double competence)

Parameters

competence double

Competence level from 0 (beginner) to 1 (expert).