Skip to main content

python implementation of Dunning's T-Digest

Project description

qtdigest

python implementation of Dunning's T-Digest, inspired by nodejs tdigest

Install

pip install qtdigest

Usage

from qtdigest import Tdigest

t = Tdigest()
for i in xrange(1000):
    t.push(random())
P90 = t.percentile(0.9)
print 'P90 = ', P90

API

Tdigest(delta=0.01, K=25, CX=1.1)

  • delta: the compression factor, the max fraction of mass that can be owned by one centroid (bigger, up to 1.0, means more compression).

  • K: a size threshold that triggers recompression as the TDigest grows during input

  • CX: specifies how often to update cached cumulative totals used for quantile estimation during ingest.

  • return: Tdigest instance

Instance of Tdigest

  • push(x, n): add data with value x and weight n

  • size(): return the count of centroids

  • toList(): return the list of all centroids data

  • percentile(p): return the percentage of p(0..1)

  • serialize(): serialize tdigest instance to string, ie: 0.01~25~2~0.00064~0.0013~2~20

  • simpleSerialize(): simply serialize tdigest instance to string, ie: 0.00064~2~0.0013~20

  • deserialize(serialized_str): deserialize the serialized string to tdigest instance. it is a classmethod, so can be called by Tdigest.deserialize(serialized_str)

Performance

platform: MacBook Pro (2.6 GHz Intel Core i5)

data size (push times) cost time
1K 0.07s
10K 0.2s
100K 1.7s
1M 17s

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qtdigest-0.3.1.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file qtdigest-0.3.1.tar.gz.

File metadata

  • Download URL: qtdigest-0.3.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for qtdigest-0.3.1.tar.gz
Algorithm Hash digest
SHA256 bd4c80641a1d83c0a0b2fd3dc8308327a02d25911cc0360459fba5164d7c08eb
MD5 b93c8c02bcf2b85548053b16a28ac26a
BLAKE2b-256 df223fb1e57f71e6c999389ce3a2e6e11b1fe6de222127fd05583208295a0b51

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page