npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

conformal-js

v0.1.0

Published

Distribution-free uncertainty quantification for JavaScript. Split conformal prediction, Adaptive Conformal Inference (ACI), Welford online statistics, and KS drift detection. Zero dependencies.

Downloads

92

Readme

conformal-js

Distribution-free uncertainty quantification for JavaScript.

The first conformal prediction library for the JS/TS ecosystem.

Zero dependencies. Works in browsers, Node.js, Deno, Bun, and service workers.

Install

npm install conformal-js

Quick Start

import { calibrate, conformalSet, bernoulliNonconformity } from "conformal-js";

// 1. Compute nonconformity scores on calibration data
const calibScores = calibData.map(({ pHat, y }) =>
  bernoulliNonconformity(pHat, y)
);

// 2. Get calibration threshold (90% coverage)
const qHat = calibrate(calibScores, 0.1);

// 3. Make prediction sets on new data
const { include0, include1 } = conformalSet(newPHat, qHat);
// include0=true, include1=true → uncertain
// include0=false, include1=true → confident class 1

What's Inside

| Module | Functions | Use Case | |--------|-----------|----------| | Split Conformal | calibrate, conformalSet, conformalInterval | Static calibration with coverage guarantees | | ACI | createACI, aciPredict, aciUpdate | Online adaptation under distribution shift | | Welford | createWelford, welfordUpdate, welfordStats | Streaming mean/variance (numerically stable) | | KS Test | ksStatistic, ksPValue | Two-sample drift detection | | Scoring | bernoulliNonconformity, brierScore, expectedCalibrationError | Calibration metrics |

Adaptive Conformal Inference (ACI)

For online settings where data distribution may shift:

import { createACI, aciPredict, aciUpdate, bernoulliNonconformity } from "conformal-js";

const state = createACI({ targetAlpha: 0.1, gamma: 0.005 });

// On each new observation:
const pred = aciPredict(state, pHat); // → { include0, include1, qHat, n }

// After observing true outcome:
const score = bernoulliNonconformity(pHat, trueY);
const covered = trueY === 1 ? pred.include1 : pred.include0;
aciUpdate(state, score, covered);  // α adapts automatically

Guarantee: Under exchangeability, empirical miscoverage converges to targetAlpha. Under distribution shift, ACI adapts via the update rule from Gibbs & Candes (2021).

Regression Intervals

import { createACI, aciPredict } from "conformal-js";

const state = createACI({ targetAlpha: 0.1 });
const pred = aciPredict(state, yHat, "regression");
// → { lower, upper, qHat, n }

Drift Detection

import { ksStatistic, ksPValue } from "conformal-js";

const D = ksStatistic(recentScores, priorScores);
const p = ksPValue(D, recentScores.length, priorScores.length);
if (p < 0.05) console.warn("Distribution shift detected!");

Online Statistics

import { createWelford, welfordUpdate, welfordStats } from "conformal-js";

let state = createWelford();
for (const x of stream) {
  state = welfordUpdate(state, x);
}
const { mean, variance, std, n } = welfordStats(state);

Mathematical Foundations

Split Conformal (Vovk et al. 2005)

q̂ = Quantile(scores, ceil((n+1)(1-α))/n)
C(x) = { y : s(x,y) ≤ q̂ }
Guarantee: P(Y ∈ C(X)) ≥ 1 - α

ACI Update Rule (Gibbs & Candes 2021)

errₜ = 1{yₜ ∉ Cₜ(xₜ)}
αₜ₊₁ = clamp(αₜ + γ(α_target - errₜ), α_min, α_max)

Welford Recurrence (1962)

δ  = xₜ - μₜ₋₁
μₜ = μₜ₋₁ + δ/nₜ
M₂ = M₂ + δ·(xₜ - μₜ)

KS Test (Marsaglia Approximation)

D = sup|F̂_A(x) - F̂_B(x)|
λ = (√(nm/(n+m)) + 0.12 + 0.11/√(nm/(n+m))) · D
p ≈ 2·Σ (-1)^(k-1) · exp(-2k²λ²)

References

  1. Gibbs & Candes (2021). "Adaptive Conformal Inference Under Distribution Shift". NeurIPS.
  2. Vovk, Gammerman & Shafer (2005). "Algorithmic Learning in a Random World". Springer.
  3. Angelopoulos & Bates (2021). "A Gentle Introduction to Conformal Prediction".
  4. Welford (1962). "Note on a Method for Calculating Corrected Sums of Squares and Products". Technometrics.

License

MIT