Skip to main content

popsregression

Post-Bayesian regression for misspecified, near-deterministic models. This is the JAX implementation of Pointwise Optimal Parameter Sets (POPS) for models linear in their parameters, including polynomial surrogates and linear interatomic potentials.

A single coefficient vector can minimize the total training loss while leaving systematic residuals on individual observations. POPS uses pointwise constrained fits to estimate how far those coefficients must vary to account for model-form error. Sampling whole coefficient vectors lets that uncertainty propagate to downstream observables.

  • POPSRegression constructs the pointwise ensemble or its PCA-aligned hypercube.
  • POPSEllipseRegression fits an ellipsoidal parameter distribution with optional empirical-Bayes or PAC-Bayes regularization.

Method and tutorials · Python documentation for this branch · Kermode group regression demo · Standalone Julia implementation

Installation

Install this checkout with Python 3.10 or newer. The numerical dependencies are JAX, SciPy and NumPy.

git clone --branch jax-integration https://github.com/POPS-UQ/popsregression.git
cd popsregression
python -m pip install -e .

Quick start

import numpy as np
from popsregression import POPSRegression

x = np.linspace(-1, 1, 32)
X_train = np.polynomial.legendre.legvander(x, 4)
y_train = np.sin(2 * np.pi * x) + 0.3 * x**2
X_test = np.polynomial.legendre.legvander(np.linspace(-1, 1, 201), 4)

# Fit POPSRegression
# fit_intercept=False by default
model = POPSRegression()
model.fit(X_train, y_train)

# Prediction with misspecification & epistemic uncertainty
y_pred, y_std = model.predict(X_test, return_std=True)

# Also return min/max bounds over the posterior
y_pred, y_std, y_max, y_min = model.predict(
    X_test, return_std=True, return_bounds=True
)

# Also return epistemic-only uncertainty separately
y_pred, y_std, y_max, y_min, y_epistemic_std = model.predict(
    X_test,
    return_std=True,
    return_bounds=True,
    return_epistemic_std=True,
)

Key parameters

Parameter Default Description
posterior 'hypercube' Posterior form: 'hypercube' (PCA-aligned box) or 'ensemble' (raw corrections); the ellipsoid is POPSEllipseRegression (below)
random_state None Seed for the posterior resampling; None uses the global NumPy state
resampling_method 'uniform' Sampling method: 'uniform', 'sobol', 'latin', 'halton'
resample_density 1.0 Number of posterior samples per training point
prior_precision None Shape Λ (vector or matrix) of the Gaussian prior N(0, (λΛ)⁻¹) on the coefficients; the scale λ is learned. None is the isotropic prior
leverage_regularization 0.001 Regularizes the leverage in the pointwise corrections, e_i A⁻¹x_i / (h_i + eps) with eps this times the mean leverage; 0.0 is the exact (unstable for low-leverage points) pointwise fit
minimum_relative_correction 0.01 Relative threshold on the correction norm: only points with ||dθ_i|| >= this times the RMS norm enter the singular decomposition and bounds of the POPS posterior
mode_threshold 1e-8 Eigenvalue threshold for hypercube dimensionality
percentile_clipping 0.0 Percentile to clip from hypercube bounds (0–50)

The Bayesian ridge parameters of the mean fit (max_iter, tol, alpha_1, alpha_2, lambda_1, lambda_2, alpha_init, lambda_init, fit_intercept) are also supported.

Key attributes (after fitting)

Attribute Description
coef_, intercept_ Regression coefficients (posterior mean) and intercept
sigma_ Epistemic variance-covariance matrix
misspecification_sigma_ Misspecification variance-covariance matrix from POPS
posterior_samples_ Weight perturbations, with one sample per column
alpha_ Estimated noise precision (not used for prediction)
pointwise_corrections_, leverage_, selected_ Pointwise corrections, leverages and the points kept for the posterior

Ellipsoid posteriors: POPSEllipseRegression

Run the PAC-Ellipse tutorial to fit a bounded simulator, inspect its risk certificate and propagate joint predictions.

POPSEllipseRegression fits a parameter distribution that is uniform on an ellipsoid. For a linear model its predictive density at x has a closed form, so the zero-noise generalization error is minimized directly. Predictive densities, exact quantiles and parameter draws are available in closed form (for the hierarchical layers, exactly for the stored finite mixture of hyperparameter draws that represents the predictive). The regularization parameter chooses how the finite-data uncertainty of the ellipsoid itself is handled:

from popsregression import POPSEllipseRegression

bare = POPSEllipseRegression().fit(X_train, y_train)

# Empirical-Bayes layer (Ellipse+EB): a Laplace hyperposterior over the
# ellipsoid, with its prior centered on the fit. Cheap; its diagnostic_bound_
# is not a PAC bound.
eb = POPSEllipseRegression(regularization="empirical-bayes").fit(X_train, y_train)

# PAC layer (Ellipse+PAC): the prior over the ellipsoid is fixed on a random
# half of the data, and a PAC-Bayes bound on the population log risk is
# evaluated on the other half (and vice versa). y_bounds must be known in
# advance (e.g. from a maximum principle), not read off the data.
pac = POPSEllipseRegression(regularization="PAC", y_bounds=(y_lower, y_upper))
pac.fit(X_train, y_train, groups=case_id)   # groups: rows of one simulator case
pac.certificate_.raw_bound, pac.certificate_.trivial_bound  # bound for the returned predictive

lo, hi = eb.predict_interval(X_test, level=0.9545)   # exact central interval
logp = eb.predict_logpdf(X_test, y_test)
fields = eb.sample_predictions(X_test, 1000)          # joint draws for propagation

All predictions refer to parameter uncertainty only; no noise term is added. The PAC bound certifies the log risk of the predictive density, not interval coverage. See the ellipse documentation and the glossary for the terms used above.

Comparison methods and paper studies

PACm, PAC²-T, predictive variational inference and a finite POPS-dictionary weighting ablation are implemented in examples/comparisons/, outside the package. The scripts in examples/ produce every figure and table of the accompanying paper; see examples/README.md.

Backend

All numerical kernels (the Bayesian ridge fit, the pointwise corrections, the ellipsoid optimization, the PAC certification and the mixture predictives) are written in JAX and compiled on first use.

  • The first call for a given problem shape pays a compilation cost of about a second; later calls with the same shapes reuse the compiled kernel.
  • Importing the package enables JAX double precision (jax_enable_x64), a process-wide JAX setting.
  • With a GPU build of JAX the same code runs on the accelerator.
  • Inputs and fitted attributes (coef_, sigma_, ...) are NumPy arrays.

scikit-learn is not required. The estimators keep the familiar fit / predict / get_params / set_params usage, so they still work inside scikit-learn pipelines and parameter searches when it is installed.

Pipeline compatibility

If scikit-learn is installed, both estimators can be used in its pipelines and hyperparameter search:

from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import PolynomialFeatures

pipe = make_pipeline(
    PolynomialFeatures(degree=4),
    POPSRegression(resampling_method='sobol'),
)
pipe.fit(X_train, y_train)
y_pred = pipe.predict(X_test)

Development

The repository is managed with uv; uv run resolves the pinned environment from uv.lock on first use.

uv run --group test pytest -vsl popsregression examples/comparisons  # tests
uv run --group lint ruff check popsregression examples               # linter
uv run --group lint black --check popsregression examples
uv run --group doc mkdocs serve                    # docs at localhost:8000
cd examples && uv run --extra examples python example_polynomial.py  # a figure

Without uv, pip install -e ".[examples]" and run the tools directly.

Citation

Parameter uncertainties for imperfect surrogate models in the low-noise regime

TD Swinburne and D Perez, Machine Learning: Science and Technology 2025

@article{swinburne2025,
    author={Swinburne, Thomas and Perez, Danny},
    title={Parameter uncertainties for imperfect surrogate models in the low-noise regime},
    journal={Machine Learning: Science and Technology},
    doi={10.1088/2632-2153/ad9fce},
    year={2025}
}

For the PAC-Bayes construction, see Thomas D. Swinburne, Omar Hussein, Ian Lynch and Danny Perez, PAC-Bayesian regression for misspecified, near-deterministic surrogate models.

Contributors

Thomas D. Swinburne and Danny Perez developed the original POPS method. James Kermode contributed the Gaussian parameter prior for the ellipsoid shape and its initialization in PR #15. The JAX adaptation uses the prior scale learned by the Bayesian ridge fit. Enable it with prior_kl=True on POPSEllipseRegression.

AI usage

Claude assisted with documentation and test cases. Thomas D. Swinburne reviewed the code described in the original release.

Metadata

Release files for popsregression 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for popsregression 0.5.0
File Size Uploaded Provenance Actions
popsregression-0.5.0.tar.gz 84.1 kB With provenance Details for popsregression-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for popsregression 0.5.0
File Interpreter ABI Platform Actions
popsregression-0.5.0-py3-none-any.whl Python 3 none any Details for popsregression-0.5.0-py3-none-any.whl

Total release size: 168.3 kB

Release files / popsregression-0.5.0.tar.gz

Download URL popsregression-0.5.0.tar.gz
Size 84.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9bd6055400de03e81da7830b1d079f554ae3dcae3e08b2bac5916e5a7f749f0b
BLAKE2b-256 checksum
How to use checksums
833e7fdb7d816932377ed40046a9a2e32209291c156ffebabb5453b947bd2777
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / popsregression-0.5.0-py3-none-any.whl

Download URL popsregression-0.5.0-py3-none-any.whl
Size 84.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0c84009db293cc840f278d802a6ae4ea52e6216203bbf52fc1f3c1f63451cf4
BLAKE2b-256 checksum
How to use checksums
e3184951c573691e345ce8bed348c40c1061c27d8690da8346bc889f0d724b91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Security for popsregression 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for popsregression-0.5.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page