Abstract
Frequency estimation is a fundamental task in big data processing, traditionally handled by the Count-Min Sketch (CMS). While recent "Learned" CMS (LCMS) variants leverage machine learning to improve accuracy, they suffer from slow construction times and a lack of theoretical reliability guarantees. This paper introduces Optimized Learned Count-Min Sketch (OptLCMS), a framework that replaces empirical parameter tuning with a rigorous analytical optimization approach. By utilizing Karush-Kuhn-Tucker (KKT) conditions and dynamic programming, OptLCMS achieves construction speeds up to four orders of magnitude faster than previous methods while significantly reducing the probability of large estimation errors.
Introduction
In large-scale data applications, such as network traffic monitoring and search query analysis, estimating element frequency under strict memory constraints is critical. The standard Count-Min Sketch (CMS) provides a robust but fixed trade-off between memory and accuracy. Learned CMS (LCMS) attempts to break this trade-off by using a predictive model to isolate frequent elements. However, LCMS faces two primary challenges: the "threshold" parameters for partitioning data are typically found through exhaustive, slow empirical testing, and the resulting structures lack the mathematical error bounds characteristic of classical sketches.
Methods
OptLCMS builds upon the Partitioned Learned CMS architecture but introduces a formal optimization layer to determine its parameters.
Architecture and Partitioning
An ML model assigns a score $s(x)$ to each element $x$. The score space is partitioned into $G$ groups, each managed by a separate CMS ($CMS_1, \dots, CMS_G$), plus a "Unique Bucket" (UB) for the most frequent items. This hierarchical structure allows the system to allocate more resources to elements predicted to be frequent.
Analytical Optimization
The core innovation of OptLCMS is the formulation of a mathematical optimization problem to minimize the probability of "intolerable errors"—cases where the estimation error exceeds a user-defined threshold $\epsilon N$.
- KKT Conditions: For a fixed set of score thresholds, the authors derived a closed-form analytical solution for the optimal CMS parameters ($\delta$) using Karush-Kuhn-Tucker conditions. This bypasses the need for slow validation-based searches.
- Dynamic Programming: To optimize the boundaries between the $G$ groups, the framework uses a dynamic programming approach that maximizes the Kullback–Leibler (KL) divergence between the data distribution and the query distribution.
- Relaxed Constraints: By treating discrete table dimensions as continuous variables during the optimization phase, the authors avoided the computational overhead of integer programming.
Experimental Evaluation
The framework was evaluated using the AOL query log dataset, comprising 21 million queries and 3.8 million unique terms following a Zipfian distribution. Performance was measured under two query patterns: Uniform (querying all unique terms) and Frequency-weighted (querying based on real-world frequency).
Key Results
OptLCMS demonstrates significant improvements over standard LCMS in construction efficiency and reliability.
Construction Speedup
For frequency-weighted queries, OptLCMS constructed the data structure in just 0.003 seconds, a massive improvement over the 10.7 seconds required by standard LCMS—representing a speedup of over 3,500x. This efficiency stems from the analytical derivation of parameters rather than empirical search.
Reliability and Accuracy
OptLCMS significantly enhances tail-end reliability. The probability of "intolerable errors" is up to 20x lower than that of LCMS across various memory budgets, as shown in the comparison of error probabilities.
Despite the focus on reliability, OptLCMS remains competitive in average estimation accuracy, matching the performance of state-of-the-art LCMS variants across different memory constraints.
Conclusion
OptLCMS bridges the gap between the high performance of learned data structures and the theoretical rigor of classical sketches. By replacing empirical tuning with analytical optimization, it provides a practical, fast, and reliable solution for frequency estimation in modern big data systems. Future work will explore extending this framework to more diverse datasets and integrating confidence-aware mechanisms.
Summary updated