histogram.qrde([options])


  • options <Object>
    • bins <number> 要返回的等概率密度区间数量。必须在 1 到 1000 之间。不能与 probabilities 一起使用。默认值: 100。
    • probabilities <number[]> 自定义概率边界。数组必须包含 2 到 1001 个严格递增的值,以 0 开始,以 1 结束。不能与 bins 一起使用。
    • dequantize <string> 控制重复的桶值是否在它们的等值范围内以确定性的方式分布。可以是 'none'、'hdr' 或 'all'。默认值: 'hdr'。
    • cache <boolean> 当 true 时,会保留扩展的直方图快照以供后续使用 cache: true 调用。当直方图被修改时,该快照会失效。默认值: false。
  • 返回:<Promise> 填充有一个包含以下内容的<Object>:
    • probabilities Float64Array 用于估算的概率边界。
    • quantiles Float64Array 概率边界处的分位数。
    • densities Float64Array 每个分位区间内的密度。
    • count <bigint> 直方图快照中的数值数量。
    • bucketCount <number> 已占用 HDR 桶的数量。
    • corrections <number> 被限制到前一个分位数的非单调浮点结果的数量。
    • dequantize <string> 所选的去量化模式。

基于 Harrell-Davis 分位数估计器返回一个尊重分位数的密度估计。默认情况下,bins 生成等概率边界。probabilities 选项则可以让估计集中在诸如 p90、p99、p99.9 和 p99.99 的区域。区间 i 的密度包含概率质量 probabilities[i + 1] - probabilities[i]。在调用该方法时,会对直方图进行快照。快照扩展和估计是在 libuv 线程池中计算的。高度集中的 beta 权重使用二阶渐近近似,以避免在大样本数下出现数值收敛损失。

🌐 Returns a quantile-respectful density estimate based on the Harrell-Davis quantile estimator. By default, bins generates equal probability boundaries. The probabilities option can instead focus the estimate on regions such as p90, p99, p99.9, and p99.99. The density for interval i contains probability mass probabilities[i + 1] - probabilities[i]. The histogram is snapshotted when the method is called. Snapshot expansion and the estimate are calculated in the libuv thread pool. Highly concentrated beta weights use a second-order asymptotic approximation to avoid numerical convergence loss at large sample counts.

将 cache 设置为 true 可以避免在未改变的直方图上多次请求估算时重复捕获和展开快照。保留的快照占用的内存与已使用的 HDR 桶数量成正比,并且在下次修改直方图时会被释放。

🌐 Setting cache to true avoids repeating snapshot capture and expansion when several estimates are requested from an unchanged histogram. The retained snapshot uses memory proportional to the number of occupied HDR buckets and is released when the histogram is next modified.

QRDE 临时大约使用额外一个 HDR 计数数组,加上每个占用桶 32 字节。使用 cache: true 时,每个桶扩展的 32 字节快照仍然保持分配。以下估算使用 lowest: 1 和 highest: Number.MAX_SAFE_INTEGER,不包含分配器和 JavaScript 对象的开销:

🌐 QRDE temporarily uses approximately one additional HDR count array plus 32 bytes per occupied bucket. With cache: true, the expanded 32-byte-per-bucket snapshot remains allocated. The following estimates use lowest: 1 and highest: Number.MAX_SAFE_INTEGER and exclude allocator and JavaScript object overhead:

figures直方图最大展开快照峰值缓存未命中 QRDE
16.3 KiB25 KiB31 KiB
247 KiB188 KiB235 KiB
3352 KiB1.4 MiB1.7 MiB
45.0 MiB20 MiB25 MiB
537 MiB148 MiB185 MiB

最大快照列假设每个可表示的桶都被占用。较低的 highest 值会减小直方图和临时副本的大小。每次并发调用如果没有命中缓存,都需要自己的临时副本和扩展的快照。

🌐 The maximum snapshot column assumes every representable bucket is occupied. Lower highest values reduce histogram and temporary copy sizes. Concurrent calls that miss the cache each require their own temporary copy and expanded snapshot.

HDR 直方图将观察值汇总到等值的桶中。'hdr' 反量化模式将宽于一个单位的桶中的重复值建模为在桶分辨率上的连续均匀分布。这可以在保留单位分辨率重复值作为点质量的同时,减少 HDR 量化引入的密度伪影。'all' 模式也会反量化单位分辨率的重复值。使用 'none' 可以直接使用桶的中点来计算分组的 Harrell-Davis 估计量。

🌐 HDR histograms aggregate observations into equivalent-value buckets. The 'hdr' dequantization mode models repeated values in buckets wider than one unit as a continuous uniform distribution over the bucket resolution. This reduces density artifacts introduced by HDR quantization while preserving repeated unit-resolution values as point masses. The 'all' mode also dequantizes repeated unit-resolution values. Use 'none' to calculate the grouped Harrell-Davis estimator using bucket midpoints directly.

一个空的直方图会返回请求的 probabilities,但会生成空的 quantiles 和 densities 数组。一个非去量化的区间,如果其分位数边界相等,会有无限的密度。

🌐 An empty histogram returns the requested probabilities but produces empty quantiles and densities arrays. A non-dequantized interval whose quantile boundaries are equal has an infinite density.