Skip to content

Commit 3cd360d

Browse files
Update version to 0.0.4, remove Python 3.8 and 3.9 from tox configuration, and update GitHub Actions to support Python 3.10, 3.11, 3.12, and 3.13. Enhance documentation to include HDRHistogram and improve examples with updated methods.
1 parent c3a5395 commit 3cd360d

12 files changed

Lines changed: 622 additions & 142 deletions

File tree

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
python-version: ["3.8", "3.9", "3.10", "3.11"]
11+
python-version: ["3.10", "3.11", "3.12", "3.13"]
1212

1313
steps:
1414
- uses: actions/checkout@v4

QuantileFlow/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from QuantileFlow.hdrhistogram.core import HDRHistogram
2323
from QuantileFlow.ddsketch.core import DDSketch
2424

25-
__version__ = "0.0.3"
25+
__version__ = "0.0.4"
2626
__all__ = [
2727
"MomentSketch",
2828
"HDRHistogram",

QuantileFlow/pytest.ini

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/api/hdrhistogram.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# HDRHistogram
2+
3+
HDRHistogram (High Dynamic Range Histogram) is a logarithmic-bucketed histogram implementation designed for efficient tracking of values across multiple orders of magnitude.
4+
5+
## Overview
6+
7+
HDRHistogram offers the following features:
8+
9+
* **Wide Value Range**: Efficiently tracks values across multiple orders of magnitude
10+
* **Configurable Precision**: Adjustable number of buckets for different accuracy needs
11+
* **Memory Efficient**: Uses logarithmic bucketing to minimize memory usage
12+
* **Summary Statistics**: Provides comprehensive statistics including min, max, quartiles, and count
13+
* **Visualization**: Built-in support for plotting distributions with logarithmic scales
14+
* **Serialization**: Supports converting histograms to/from dictionaries for storage and transmission
15+
* **Value Range Control**: Configurable minimum and maximum trackable values
16+
17+
## Main Class
18+
19+
```{eval-rst}
20+
.. autoclass:: QuantileFlow.HDRHistogram
21+
:members:
22+
:undoc-members:
23+
:special-members: __init__
24+
:exclude-members: __dict__, __weakref__
25+
:noindex:
26+
:show-inheritance:
27+
```
28+
29+
## Mathematical Background
30+
31+
HDRHistogram works by maintaining a fixed number of logarithmic buckets to efficiently track values across a wide range. The key aspects of the implementation are:
32+
33+
1. **Logarithmic Bucketing**: Values are assigned to buckets based on their logarithm, allowing efficient tracking of values across multiple orders of magnitude
34+
2. **Value Range Control**: Configurable minimum and maximum values ensure memory efficiency
35+
3. **Linear Interpolation**: Within each bucket, linear interpolation is used to estimate quantiles
36+
37+
### Bucket Calculation
38+
39+
The bucket index for a value $x$ is calculated as:
40+
41+
$$
42+
\text{bucket_index} = \lfloor \log_2(x) \rfloor
43+
$$
44+
45+
This ensures that:
46+
- Values in the same order of magnitude are grouped together
47+
- The number of buckets grows logarithmically with the value range
48+
- Memory usage remains constant regardless of the number of values inserted
49+
50+
### Quantile Estimation
51+
52+
Quantiles are estimated by:
53+
1. Finding the bucket containing the target quantile
54+
2. Using linear interpolation within the bucket to estimate the exact value
55+
56+
For a target quantile $q$ and total count $N$, the estimated value is:
57+
58+
$$
59+
\text{value} = \text{lower_bound} + (\text{upper_bound} - \text{lower_bound}) \times \frac{qN - \text{cumulative_count}}{\text{bucket_count}}
60+
$$
61+
62+
Where:
63+
- $\text{lower_bound}$ and $\text{upper_bound}$ are the bucket boundaries
64+
- $\text{cumulative_count}$ is the count of values in previous buckets
65+
- $\text{bucket_count}$ is the count of values in the current bucket
66+
67+
## Performance Characteristics
68+
69+
- **Memory Usage**: O(num_buckets)
70+
- **Insertion Time**: O(1) per value
71+
- **Query Time**: O(num_buckets) for quantile queries
72+
- **Merge Time**: O(num_buckets) for merging histograms
73+
74+
## Use Cases
75+
76+
HDRHistogram is particularly useful for:
77+
- Tracking metrics with wide value ranges (e.g., response times, request sizes)
78+
- Monitoring systems with multiple orders of magnitude in measurements
79+
- Applications requiring configurable precision and value range control
80+
- Distributed systems where histograms need to be merged
81+
- Real-time monitoring and alerting systems
82+
83+
## Usage Examples
84+
85+
For basic usage, see the [Getting Started](../getting-started.md) guide.
86+
87+
For more advanced examples, see the [Examples](../examples.md) page.

docs/code.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ This page provides links to the detailed API documentation for all components of
44

55
## Sketch Algorithms
66

7-
QuantileFlow provides two main algorithms for quantile estimation:
7+
QuantileFlow provides three main algorithms for quantile estimation:
88

99
- [DDSketch](api/ddsketch.md) - Distributed and Deterministic Sketch with configurable relative error
1010
- [MomentSketch](api/momentsketch.md) - Moment-based quantile sketch using maximum entropy optimization
11+
- [HDRHistogram](api/hdrhistogram.md) - High Dynamic Range Histogram for tracking values across multiple orders of magnitude
1112

1213
## API Reference
1314

0 commit comments

Comments
 (0)