Skip to content

Numeric alignment ​

JsIndexNum is a port of the Python library PyIndexNum. This page documents how the JavaScript implementation is kept numerically aligned with — and tested against — the Python original.

Golden-value testing ​

The test suite replays the exact PyIndexNum pipeline on fixed datasets and compares every output with Python-computed expected values:

  • Datasets — a 5-product × 15-month panel and the 1,200-product performance dataset, including deterministic churn (dropped products) so unbalanced/matched-sample behaviour is covered.
  • Expected values — generated by scripts/generate_golden.py running PyIndexNum 0.4.0 in a local Python environment (gitignored local/ folder). The inputs and expected outputs are committed as JSON, so the JS test suite never needs Python.
  • Coverage — every utility function, all 8 bilateral methods (balanced and matched-sample), all 5 multilateral methods (balanced and unbalanced), imputation and panel removal.

The 8-significant-digit convention ​

JavaScript and Python/numpy both use IEEE 754 doubles, but summation order differs, so raw last-bits agreement is neither possible nor meaningful. Instead, all comparisons — and all user-facing values on this site — use one shared helper:

ts
roundSignificant(value, digits = 8) // via Number(value.toPrecision(digits))
  • In tests: a JS result passes when it equals the Python expected value after both are rounded to 8 significant digits (with a relative 1e-9 slack for knife-edge rounding boundaries).
  • In the app and exports: every number written to CSV, Excel, tables or chart tooltips is rounded the same way, so binary-float noise like 0.30000000000000004 never appears — 0.1 + 0.2 exports as 0.3 — while the retained 8 significant digits are far more precision than these index computations carry statistically.

The library itself always computes in full double precision; rounding is a presentation/export/comparison convention only.