philiprehberger-counter 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +13 -0
- data/lib/philiprehberger/counter/version.rb +1 -1
- data/lib/philiprehberger/counter.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: abc51d850f2a69c9c0394ac11b5a31a033d4f0753c476508a242ba98e19991f6
|
|
4
|
+
data.tar.gz: b8a5ebe0f5b363ddecd385d82a0b316d99afb07c1722363c84b1dc937366ca42
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fa6a9773aeb27ee63287220200f8236062fe917b72e47edd9f7d8f5de90586cd27d371bb7223bbfd437b39223e6e0c7ef45774c08aef6c981eeb51957765473e
|
|
7
|
+
data.tar.gz: aedb5cb2e5d7192669c1b2837ea43bbe391f1ab76923bde5c91bb501b3c04615297164a1a86c8e423c3355d8ad9f1bd1eecb0860a94b07b89db1ed4c6fc32a44
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this gem adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.6.0] - 2026-04-30
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `#unique_ratio` — ratio of unique keys to total observations (`size / total`); `0.0` for empty counters; pairs with `#entropy` as a simple diversity metric
|
|
14
|
+
|
|
10
15
|
## [0.5.0] - 2026-04-24
|
|
11
16
|
|
|
12
17
|
### Added
|
data/README.md
CHANGED
|
@@ -141,6 +141,18 @@ skewed = Philiprehberger::Counter.new(%w[a a a a b])
|
|
|
141
141
|
skewed.entropy # => ~0.7219 (less than uniform upper bound)
|
|
142
142
|
```
|
|
143
143
|
|
|
144
|
+
### Unique Ratio
|
|
145
|
+
|
|
146
|
+
Ratio of unique keys to total observations — a simple diversity metric.
|
|
147
|
+
`1.0` means every observation was unique; small values mean a few keys
|
|
148
|
+
dominate.
|
|
149
|
+
|
|
150
|
+
```ruby
|
|
151
|
+
Philiprehberger::Counter.new(%w[a b c d]).unique_ratio # => 1.0
|
|
152
|
+
Philiprehberger::Counter.new(%w[a a a a]).unique_ratio # => 0.25
|
|
153
|
+
Philiprehberger::Counter.new(%w[a a b b b c]).unique_ratio # => 0.5
|
|
154
|
+
```
|
|
155
|
+
|
|
144
156
|
## API
|
|
145
157
|
|
|
146
158
|
| Method | Description |
|
|
@@ -168,6 +180,7 @@ skewed.entropy # => ~0.7219 (less than uniform upper bound)
|
|
|
168
180
|
| `#values` | Return all count values |
|
|
169
181
|
| `#filter_by_count(min:, max:)` | Filter entries by count range |
|
|
170
182
|
| `#entropy` | Shannon entropy of the count distribution in bits |
|
|
183
|
+
| `#unique_ratio` | Ratio of unique keys to total observations (`size / total`); `0.0` for empty counters |
|
|
171
184
|
| `#to_h` | Convert to a plain hash |
|
|
172
185
|
| `#size` | Number of unique keys |
|
|
173
186
|
|
|
@@ -152,6 +152,20 @@ module Philiprehberger
|
|
|
152
152
|
(@counts[key].to_f / total * 100)
|
|
153
153
|
end
|
|
154
154
|
|
|
155
|
+
# Ratio of unique keys to total observations
|
|
156
|
+
#
|
|
157
|
+
# A simple diversity / repetition metric. `1.0` means every observation
|
|
158
|
+
# was unique; small values mean a few keys dominate the counter. Returns
|
|
159
|
+
# `0.0` for empty counters.
|
|
160
|
+
#
|
|
161
|
+
# @return [Float] `size.to_f / total`, or `0.0` when total is zero
|
|
162
|
+
def unique_ratio
|
|
163
|
+
t = total
|
|
164
|
+
return 0.0 if t.zero?
|
|
165
|
+
|
|
166
|
+
size.to_f / t
|
|
167
|
+
end
|
|
168
|
+
|
|
155
169
|
# Shannon entropy of the count distribution in bits
|
|
156
170
|
#
|
|
157
171
|
# @return [Float] entropy in bits, 0.0 for empty or single-key counters
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-counter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Count element frequencies from any enumerable with most-common and least-common
|
|
14
14
|
queries, merge and subtract operations, percentage calculations, and Enumerable
|