com.clearspring.analytics.stream.quantile.QDigest.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(4.7k)|赞(0)|评价(0)|浏览(64)

本文整理了Java中com.clearspring.analytics.stream.quantile.QDigest.<init>方法的一些代码示例,展示了QDigest.<init>的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。QDigest.<init>方法的具体详情如下:
包路径:com.clearspring.analytics.stream.quantile.QDigest
类名称:QDigest
方法名:<init>

QDigest.<init>介绍

暂无

代码示例

代码示例来源:origin: addthis/stream-lib

public static QDigest deserialize(byte[] b) {
  ByteArrayInputStream bis = new ByteArrayInputStream(b);
  DataInputStream s = new DataInputStream(bis);
  try {
    long size = s.readLong();
    double compressionFactor = s.readDouble();
    long capacity = s.readLong();
    int count = s.readInt();
    QDigest d = new QDigest(compressionFactor);
    d.size = size;
    d.capacity = capacity;
    for (int i = 0; i < count; ++i) {
      long k = s.readLong();
      long n = s.readLong();
      d.node2count.put(k, n);
    }
    return d;
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: addthis/stream-lib

System.arraycopy(bSamples, 0, allSamples, aSamples.length, bSamples.length);
QDigest a = new QDigest(compressionFactor);
QDigest b = new QDigest(compressionFactor);
QDigest c = new QDigest(compressionFactor);
for (long x : aSamples) a.offer(x);
for (long x : bSamples) b.offer(x);

代码示例来源:origin: addthis/stream-lib

/**
   * Test for bug identified and corrected by http://github.com/addthis/stream-lib/pull/53
   */
  @Test
  public void testSerialization() {
    long[] samples = {0, 20};
    QDigest digestA = new QDigest(2);

    for (int i = 0; i < samples.length; i++) {
      digestA.offer(samples[i]);
    }
    byte[] serialized = QDigest.serialize(digestA);

    QDigest deserializedA = QDigest.deserialize(serialized);

    QDigest digestB = new QDigest(2);
    for (int i = 0; i < samples.length; i++) {
      digestB.offer(samples[i]);
    }

    QDigest.unionOf(digestA, deserializedA);

  }
}

代码示例来源:origin: addthis/stream-lib

public static QDigest unionOf(QDigest a, QDigest b) {
  if (a.compressionFactor != b.compressionFactor) {
    throw new IllegalArgumentException(
        "Compression factors must be the same: " +
        "left is " + a.compressionFactor + ", " +
        "right is " + b.compressionFactor);
  }
  if (a.capacity > b.capacity) {
    return unionOf(b, a);
  }
  QDigest res = new QDigest(a.compressionFactor);
  res.capacity = a.capacity;
  res.size = a.size + b.size;
  for (long k : a.node2count.keySet()) {
    res.node2count.put(k, a.node2count.get(k));
  }
  if (b.capacity > res.capacity) {
    res.rebuildToCapacity(b.capacity);
  }
  for (long k : b.node2count.keySet()) {
    res.node2count.put(k, b.get(k) + res.get(k));
  }
  res.compressFully();
  return res;
}

代码示例来源:origin: addthis/stream-lib

private void compare(AbstractContinousDistribution gen, String tag, long scale, Random rand) {
  for (double compression : new double[]{2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000}) {
    QDigest qd = new QDigest(compression);
    TDigest dist = new TDigest(compression, rand);
    List<Double> data = Lists.newArrayList();
    for (int i = 0; i < 100000; i++) {
      double x = gen.nextDouble();
      dist.add(x);
      qd.offer((long) (x * scale));
      data.add(x);
    }
    dist.compress();
    Collections.sort(data);
    for (double q : new double[]{0.001, 0.01, 0.1, 0.2, 0.3, 0.5, 0.7, 0.8, 0.9, 0.99, 0.999}) {
      double x1 = dist.quantile(q);
      double x2 = (double) qd.getQuantile(q) / scale;
      double e1 = cdf(x1, data) - q;
      System.out.printf("%s\t%.0f\t%.8f\t%.10g\t%.10g\t%d\t%d\n", tag, compression, q, e1, cdf(x2, data) - q, dist.smallByteSize(), QDigest.serialize(qd).length);
    }
  }
}

代码示例来源:origin: addthis/stream-lib

digests[i] = new QDigest(compressionFactor);
for (long x : samples[i]) {
  digests[i].offer(x);
long[] total = new long[numTotal];
int offset = 0;
QDigest totalDigest = new QDigest(compressionFactor);
long expectedSize = 0;
for (int j = 0; j <= i; ++j) {

代码示例来源:origin: addthis/hydra

public Histogram() {
  this.quantiles = new QDigest(1000);
  this.min = Long.MAX_VALUE;
  this.max = Long.MIN_VALUE;
}

代码示例来源:origin: LiveRamp/cascading_ext

@Override
public QDigest initialize() {
 return new QDigest(compressionFactor);
}

代码示例来源:origin: com.addthis/stream-lib

public static QDigest deserialize(byte[] b) {
  ByteArrayInputStream bis = new ByteArrayInputStream(b);
  DataInputStream s = new DataInputStream(bis);
  try {
    long size = s.readLong();
    double compressionFactor = s.readDouble();
    long capacity = s.readLong();
    int count = s.readInt();
    QDigest d = new QDigest(compressionFactor);
    d.size = size;
    d.capacity = capacity;
    for (int i = 0; i < count; ++i) {
      long k = s.readLong();
      long n = s.readLong();
      d.node2count.put(k, n);
    }
    return d;
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: com.addthis/stream-lib

public static QDigest unionOf(QDigest a, QDigest b) {
  if (a.compressionFactor != b.compressionFactor) {
    throw new IllegalArgumentException(
        "Compression factors must be the same: " +
        "left is " + a.compressionFactor + ", " +
        "right is " + b.compressionFactor);
  }
  if (a.capacity > b.capacity) {
    return unionOf(b, a);
  }
  QDigest res = new QDigest(a.compressionFactor);
  res.capacity = a.capacity;
  res.size = a.size + b.size;
  for (long k : a.node2count.keySet()) {
    res.node2count.put(k, a.node2count.get(k));
  }
  if (b.capacity > res.capacity) {
    res.rebuildToCapacity(b.capacity);
  }
  for (long k : b.node2count.keySet()) {
    res.node2count.put(k, b.get(k) + res.get(k));
  }
  res.compressFully();
  return res;
}

相关文章