ImportanceSampler<T>
Models & Types ยท AiDotNet.Data.Sampling
A sampler that implements importance sampling for variance reduction.
Inheritance: DataSamplerBase โ ImportanceSampler<T>
For Beginners
Not all training samples are equally useful. Importance sampling focuses training on the most informative samples:
- High gradient norm = Sample provides strong learning signal
- High loss = Model is uncertain, needs more training
- High uncertainty = Model needs to see this more
This can reduce training time by 2-3x compared to uniform sampling!
Example:
How It Works
ImportanceSampler samples data points based on their importance, typically computed from gradient norms, loss values, or uncertainty estimates. This can accelerate training by focusing on samples that contribute most to learning.
Constructors
| Constructor | Summary |
|---|---|
ImportanceSampler(int datasetSize, double smoothingFactor, bool stabilize, int? seed) |
Initializes a new instance of the ImportanceSampler class. |
Properties
| Property | Summary |
|---|---|
IReadOnlyList<T> ImportanceScores { get; } |
Gets the importance scores for all samples. |
int Length { get; } |
Methods
| Method | Summary |
|---|---|
IEnumerable<int> GetIndicesWithoutReplacement(int count) |
Gets importance-weighted sample indices without replacement. |
T GetCorrectionFactor(int index) |
Gets the sampling weight correction factor for a sample. |
void SetImportances(IReadOnlyList<T> importances) |
Sets all importance scores at once. |
void UpdateImportance(int index, T importance) |
Updates the importance score for a single sample. |
void UpdateImportances(IReadOnlyList<int> indices, IReadOnlyList<T> importances) |
Batch updates importance scores. |