CompressionAwareFitnessCalculator<T, TInput, TOutput>
Models & Types · AiDotNet.FitnessCalculators
A fitness calculator that considers both model accuracy and compression effectiveness.
Implements: IPreferredDataSetFitnessCalculator<T, TInput, TOutput>
For Beginners
When compressing a model, you have competing goals:
- Keep accuracy high - You don’t want the compressed model to make worse predictions
- Make the model smaller - Smaller models use less memory and storage
- Make inference faster - Smaller models often run faster
This fitness calculator combines all three goals into a single score that optimization algorithms (like AutoML or genetic algorithms) can use to find the best compression settings.
The weights control how much each goal matters:
- High accuracyWeight = prioritize keeping predictions accurate
- High compressionWeight = prioritize making the model smaller
- High speedWeight = prioritize making inference faster
Example:
- For edge devices with limited memory: increase compressionWeight
- For real-time applications: increase speedWeight
- For medical/financial applications: increase accuracyWeight
How It Works
This fitness calculator implements multi-objective optimization for model compression. It balances accuracy preservation against compression benefits (size reduction, speed improvement).
Constructors
| Constructor | Summary |
|---|---|
CompressionAwareFitnessCalculator(IFitnessCalculator<T, TInput, TOutput> baseFitnessCalculator, double accuracyWeight, double compressionWeight, double speedWeight) |
Initializes a new instance of the CompressionAwareFitnessCalculator class. |
Properties
| Property | Summary |
|---|---|
CompressionMetrics<T> CompressionMetrics { get; set; } |
Gets or sets the current compression metrics to use in fitness calculation. |
DataSetType PreferredDataSetType { get; } |
Forwards the wrapped calculator’s preferred dataset type when it implements IPreferredDataSetFitnessCalculator; otherwise falls back to Validation, which preserves the historical default for external calculators that don’t opt in to the… |
bool IsHigherScoreBetter { get; } |
Gets a value indicating whether higher fitness scores are better. |
Methods
| Method | Summary |
|---|---|
T CalculateFitnessScore(DataSetStats<T, TInput, TOutput> dataSet) |
Calculates a fitness score from dataset statistics. |
T CalculateFitnessScore(ModelEvaluationData<T, TInput, TOutput> evaluationData) |
Calculates a fitness score from dataset statistics. |
bool IsBetterFitness(T currentFitness, T bestFitness) |
Compares two fitness scores and determines if the current is better than the best. |