pyinterp.TDigestFloat64

Contents

pyinterp.TDigestFloat64#

class pyinterp.TDigestFloat64(self, values: ndarray[dtype=float64, device='cpu'], weights: ndarray[dtype=float64, device='cpu'] | None = None, axis: collections.abc.Sequence[int] | None = None, compression: int | None = 100)#

Bases: object

T-Digest for incremental quantile estimation.

Computes quantiles using the t-digest algorithm which provides accurate estimates, especially at the tails of the distribution. Supports parallel and online computation with arbitrary weights.

Reference: Computing Extremely Accurate Quantiles Using t-Digests tdunning/t-digest

Parameters:
  • values – Input array of values.

  • weights – Optional array of weights (same shape as values).

  • axis – Optional axis or axes along which to compute quantiles.

  • compression – Compression parameter controlling accuracy vs memory tradeoff. Higher values provide better accuracy but use more memory. Typical values: 100-1000. Default is 100.

Example

>>> import numpy as np
>>> import pyinterp
>>> data = np.random.randn(10000)
>>> tdigest = pyinterp.TDigest(data)
>>> median = tdigest.quantile(0.5)
>>> print(f"Median: {median}")

Compute multiple quantiles

>>> quantiles = tdigest.quantile(np.array([0.25, 0.5, 0.75]))
>>> print(f"Q25, Q50, Q75: {quantiles}")

Compute along axis

>>> data_2d = np.random.randn(100, 50)
>>> tdigest_axis = pyinterp.TDigest(data_2d, axis=[0])
>>> medians = tdigest_axis.quantile(0.5)
>>> print(f"Medians shape: {medians.shape}")

Public Methods

count(self)

Return the count of samples.

max(self)

Return the maximum of samples.

mean(self)

Return the mean of samples.

min(self)

Return the minimum of samples.

quantile(-> numpy.ndarray[dtype=float64])

Overloaded function.

sum_of_weights(self)

Return the sum of weights.

Special Methods

__copy__(self)

Create a copy of this object.

__getstate__(self)

Get the state for pickling.

__iadd__(self, other)

Override the default behavior of the += operator.

__new__(*args, **kwargs)

__setstate__(self, state)

Set the state for unpickling.