def test_merge(): t = TDigest() t2 = TDigest() t3 = TDigest() a = np.random.uniform(0, 1, N) b = np.random.uniform(2, 3, N) data = np.concatenate([a, b]) t2.update(a) t3.update(b) t2_centroids = t2.centroids() t.merge(t2, t3) assert t.min() == min(t2.min(), t3.min()) assert t.max() == max(t2.max(), t3.max()) assert t.size() == t2.size() + t3.size() # Check no mutation of args assert (t2.centroids() == t2_centroids).all() # *Quantile q = np.array([0.001, 0.01, 0.1, 0.3, 0.5, 0.7, 0.9, 0.99, 0.999]) est = t.quantile(q) q_est = quantiles_to_q(data, est) np.testing.assert_allclose(q, q_est, atol=0.012, rtol=0) # *CDF x = q_to_x(data, q) q_est = t.cdf(x) np.testing.assert_allclose(q, q_est, atol=0.005) with pytest.raises(TypeError): t.merge(t2, 'not a tdigest')
def percentiles_from_tdigest(self, q, *digests): # pylint: disable = import-outside-toplevel from crick import TDigest t = TDigest() t.merge(*digests) return np.array(t.quantile(q))
def _percentiles_from_tdigest(qs, digests): from crick import TDigest t = TDigest() t.merge(*digests) return np.array(t.quantile(qs / 100.0))