Class HybridHuffmanClusteringCompression<T>
- Namespace
- AiDotNet.ModelCompression
- Assembly
- AiDotNet.dll
public class HybridHuffmanClusteringCompression<T> : ModelCompressionBase<T>, IModelCompressionStrategy<T>
Type Parameters
T
- Inheritance
-
HybridHuffmanClusteringCompression<T>
- Implements
- Inherited Members
Constructors
HybridHuffmanClusteringCompression(int, int, double, int, int?)
Initializes a new instance of the HybridHuffmanClusteringCompression class.
public HybridHuffmanClusteringCompression(int numClusters = 256, int maxIterations = 100, double tolerance = 1E-06, int huffmanPrecision = 0, int? randomSeed = null)
Parameters
numClustersintNumber of clusters for weight clustering (default: 256).
maxIterationsintMaximum K-means iterations (default: 100).
tolerancedoubleK-means convergence tolerance (default: 1e-6).
huffmanPrecisionintPrecision for Huffman encoding (default: 0 for cluster indices).
randomSeedint?Random seed for reproducibility.
Remarks
For Beginners: These parameters control both compression stages.
Clustering parameters:
numClusters: How many groups to create (256 = 8-bit, very common)
- More clusters = better quality, less compression
- Fewer clusters = more compression, lower quality
maxIterations/tolerance: How hard to work on finding optimal clusters
- Defaults are usually fine
Huffman parameters:
- huffmanPrecision: Set to 0 for cluster indices (they're already integers)
- Higher values only matter for floating-point data
The magic happens when these work together:
- Clustering creates patterns
- Huffman exploits those patterns
- Total compression is better than either alone
Methods
Compress(Vector<T>)
Compresses weights using clustering followed by Huffman encoding.
public override (Vector<T> compressedWeights, ICompressionMetadata<T> metadata) Compress(Vector<T> weights)
Parameters
weightsVector<T>The original model weights.
Returns
- (Vector<T> compressedWeights, ICompressionMetadata<T> metadata)
Compressed weights and hybrid metadata.
Decompress(Vector<T>, ICompressionMetadata<T>)
Decompresses weights by reversing Huffman encoding then clustering.
public override Vector<T> Decompress(Vector<T> compressedWeights, ICompressionMetadata<T> metadata)
Parameters
compressedWeightsVector<T>The compressed weights.
metadataICompressionMetadata<T>The hybrid compression metadata.
Returns
- Vector<T>
The decompressed weights.
GetCompressedSize(Vector<T>, ICompressionMetadata<T>)
Gets the total compressed size from both compression stages.
public override long GetCompressedSize(Vector<T> compressedWeights, ICompressionMetadata<T> metadata)
Parameters
compressedWeightsVector<T>metadataICompressionMetadata<T>