Table of Contents

Class CompressionOptimizer<T>

Namespace
AiDotNet.AutoML
Assembly
AiDotNet.dll

Automatically finds the best compression configuration for a model.

public class CompressionOptimizer<T>

Type Parameters

T

The numeric type used for calculations (e.g., float, double).

Inheritance
CompressionOptimizer<T>
Inherited Members

Remarks

CompressionOptimizer uses automated machine learning techniques to find the optimal compression configuration for a neural network model. It evaluates different compression techniques and hyperparameters, tracking metrics like compression ratio, accuracy loss, and inference speed.

For Beginners: Think of this as an automated assistant that tries different ways to compress your model and finds the best one for your needs.

Instead of manually trying:

  • Different pruning levels (50%, 70%, 90% of weights removed)
  • Different quantization settings (8-bit, 5-bit, etc.)
  • Different compression techniques (pruning, clustering, Huffman)

The optimizer automatically:

  1. Generates compression configurations to try
  2. Applies each configuration and measures results
  3. Tracks which configurations work best
  4. Returns the best compression settings found

Example usage:

var optimizer = new CompressionOptimizer<double>(options);
var bestCompression = await optimizer.OptimizeAsync(modelWeights, evaluator);
Console.WriteLine($"Best technique: {bestCompression.Technique}");
Console.WriteLine($"Compression ratio: {bestCompression.Metrics.CompressionRatio}x");

Constructors

CompressionOptimizer(CompressionOptimizerOptions?)

Initializes a new instance of the CompressionOptimizer class.

public CompressionOptimizer(CompressionOptimizerOptions? options = null)

Parameters

options CompressionOptimizerOptions

Configuration options for the optimizer.

Properties

BestTrial

Gets the best compression trial found so far.

public CompressionTrial<T>? BestTrial { get; }

Property Value

CompressionTrial<T>

TrialHistory

Gets the history of all compression trials.

public IReadOnlyList<CompressionTrial<T>> TrialHistory { get; }

Property Value

IReadOnlyList<CompressionTrial<T>>

Methods

GetSummary()

Gets a summary of the optimization results.

public string GetSummary()

Returns

string

A formatted string containing optimization results.

Optimize(Vector<T>, Func<Vector<T>, T>)

Runs the compression optimization process.

public CompressionTrial<T> Optimize(Vector<T> weights, Func<Vector<T>, T> evaluateAccuracy)

Parameters

weights Vector<T>

The model weights to compress.

evaluateAccuracy Func<Vector<T>, T>

A function that evaluates model accuracy given compressed weights.

Returns

CompressionTrial<T>

The best compression trial found.

Remarks

For Beginners: This method tries different compression settings and returns the best one.

The evaluateAccuracy function should:

  1. Take compressed weights
  2. Apply them to your model
  3. Run inference on validation data
  4. Return the accuracy (0.0 to 1.0)

The optimizer will call this function many times with different compression settings.