Lattice Grid Buy a licence

demo D236

Approximate figures, with the error bound shown

A constant-time estimate next to the figure it stands for, and the average over just the last few thousand ticks

grid.statistics.approximate · maintenanceTier(fn)

Building…
Loading a live grid…

The configuration

'approximate-and-windowed': () => {
  const rows = book(200_000);
  const KERNELS = ['sum', 'avg', 'median', 'p95', 'distinct', 'stddev'];
  return {
    rows,
    config: {
      rowKey: 'id',
      toolPanel: { side: 'left', panels: ['filters', 'columns'], exportName: 'book' },
      columnDefaults: { filter: true },
      columns: [
        { field: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
        { field: 'desk', title: 'Desk', filter: { type: 'set' } },
        { field: 'price', title: 'Price', type: 'number', format: { decimals: 4 }, total: 'median' },
        { field: 'volume', title: 'Volume', type: 'number', format: { notation: 'compact' }, total: 'p95' },
        { field: 'notional', title: 'Notional', type: 'number', format: gbp, total: 'sum' },
      ],
    },
    onGrid: (grid) => {
      const shell = grid.element?.closest('.demo-shell') ?? grid.element?.parentElement;
      const panel = document.createElement('div');
      panel.style.cssText = 'margin-top:14px;border:1px solid var(--rule);border-radius:11px;padding:14px 16px;background:var(--paper);font:13px system-ui';
      shell?.append(panel);
      const render = () => {
        const s = grid.statistics;
        if (!s?.maintenanceTier) { panel.textContent = 'maintenanceTier unavailable'; return; }
        const rows2 = KERNELS.map((fn) => {
          const tier = s.maintenanceTier(fn);
          const exact = tier.exact === 'maintained'
            ? 'exact, maintained per tick'
            : tier.exact === 'rescan' ? 'exact, full rescan per read' : 'no exact form';
          const approx = tier.approximate
            ? `${tier.approximate.sketch} — ${tier.approximate.bound.statement}`
            : 'no approximate form';
          return `<div style="padding:7px 0;border-top:1px solid var(--rule)">` +
            `<div style="font:600 13px ui-monospace,monospace">${fn}</div>` +
            `<div style="color:var(--ink-2);font-size:12.5px">${exact}</div>` +
            `<div style="color:var(--ink-3);font-size:12.5px">${approx}</div>` +
            `</div>`;
        }).join('');
        panel.innerHTML =
          `<p style="margin:0 0 8px;color:var(--ink-3);font-size:12.5px">grid.statistics.maintenanceTier(fn) — the honest label for each figure the totals row above is showing, and the sketch that would stand in for it with a stated error bound</p>` +
          rows2;
      };
      render();
      return () => panel.remove();
    },
    foot: ['the totals row above is computed exactly, over 200,000 rows', 'maintenanceTier names which reductions a sketch can approximate, and the bound it is verified to meet', 'a stated bound is the claim: distinct and the percentiles carry one, sum and avg need none'],
  };
}

Knowing what a figure actually costs, and what a shortcut would promise instead

A totals row over a large or fast-moving dataset can compute something like a distinct count or a p99 two ways: recompute it exactly on every read, or maintain an approximate version cheaply and say plainly what error bound it carries. Lattice Grid never swaps one in for the other silently; instead grid.statistics.maintenanceTier(fn) tells you, for any reduction, which of three honest positions it is actually in: exact, maintained (a running total that costs nothing extra per read, like a sum or an average), exact, rescan (correct, but a full pass over the data every time it is read, like a median or a percentile), or an approximate alternative with a named sketch and a stated bound, such as HyperLogLog for a distinct count or KLL for a quantile. grid.statistics.approximate is the same information as a lookup table, keyed by reduction name, each entry naming the sketch behind it and the bound it is verified to meet. The point of surfacing this rather than picking a tier for you is that “approximate” without a stated bound is just a wrong answer with better manners; a sketch that ships here is one this codebase runs against a real stream and asserts sits inside the bound it claims, so a figure with an error bound printed next to it is a claim you can check, not a disclaimer.

What is the difference between an exact and an approximate statistic in a data grid?

An exact reduction, whether maintained incrementally or recomputed on read, always matches a full pass over the data. An approximate one, backed by a sketch such as HyperLogLog or KLL, trades a small, stated error for constant memory and constant-time updates on a live or very large dataset. grid.statistics.maintenanceTier(fn) tells you which tier a given reduction is in and names the bound when an approximate form exists, so the choice is visible rather than buried in an implementation.

What is a stated error bound, and why does it matter?

A stated error bound is a specific, checkable claim: a HyperLogLog distinct count promises a standard error tied to its configured precision; a KLL quantile promises the true rank of the returned value is within a stated fraction of the requested rank. Reporting an approximate figure without that bound leaves a reader unable to tell a close estimate from a wrong one. Lattice Grid keeps the bound attached to the figure’s tier information specifically so an approximate result is never presented as an unqualified number.