POPSRegression 0.3.7__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- popsregression-0.5.0/.coveragerc +6 -0
- popsregression-0.5.0/.github/dependabot.yml +18 -0
- popsregression-0.5.0/.github/workflows/deploy-gh-pages.yml +50 -0
- popsregression-0.5.0/.github/workflows/lint.yml +30 -0
- popsregression-0.5.0/.github/workflows/publish.yml +28 -0
- popsregression-0.5.0/.github/workflows/python-app.yml +41 -0
- popsregression-0.5.0/.gitignore +76 -0
- popsregression-0.5.0/.pre-commit-config.yaml +16 -0
- popsregression-0.5.0/LICENSE +27 -0
- popsregression-0.5.0/MANIFEST.in +23 -0
- popsregression-0.5.0/PKG-INFO +241 -0
- popsregression-0.5.0/POPSRegression.py +13 -0
- popsregression-0.5.0/README.md +212 -0
- popsregression-0.5.0/popsregression/__init__.py +15 -0
- popsregression-0.5.0/popsregression/_base.py +196 -0
- popsregression-0.5.0/popsregression/_bayes.py +138 -0
- popsregression-0.5.0/popsregression/_ellipse.py +892 -0
- popsregression-0.5.0/popsregression/_ellipse_regression.py +1709 -0
- popsregression-0.5.0/popsregression/_optimize.py +179 -0
- popsregression-0.5.0/popsregression/_pops.py +662 -0
- popsregression-0.5.0/popsregression/_projected_ball.py +522 -0
- popsregression-0.5.0/popsregression/_version.py +24 -0
- popsregression-0.5.0/popsregression/tests/__init__.py +2 -0
- popsregression-0.5.0/popsregression/tests/test_ellipse_estimator.py +641 -0
- popsregression-0.5.0/popsregression/tests/test_ellipse_gradients.py +186 -0
- popsregression-0.5.0/popsregression/tests/test_ellipse_regression.py +511 -0
- popsregression-0.5.0/popsregression/tests/test_ellipse_statistics.py +103 -0
- popsregression-0.5.0/popsregression/tests/test_pops.py +593 -0
- popsregression-0.5.0/popsregression.egg-info/PKG-INFO +241 -0
- popsregression-0.5.0/popsregression.egg-info/SOURCES.txt +35 -0
- popsregression-0.5.0/popsregression.egg-info/requires.txt +8 -0
- popsregression-0.5.0/popsregression.egg-info/scm_file_list.json +109 -0
- popsregression-0.5.0/popsregression.egg-info/scm_version.json +8 -0
- {popsregression-0.3.7/POPSRegression.egg-info → popsregression-0.5.0/popsregression.egg-info}/top_level.txt +1 -0
- popsregression-0.5.0/pyproject.toml +123 -0
- popsregression-0.3.7/LICENSE +0 -21
- popsregression-0.3.7/PKG-INFO +0 -91
- popsregression-0.3.7/POPSRegression/POPSRegression.py +0 -530
- popsregression-0.3.7/POPSRegression/__init__.py +0 -1
- popsregression-0.3.7/POPSRegression.egg-info/PKG-INFO +0 -91
- popsregression-0.3.7/POPSRegression.egg-info/SOURCES.txt +0 -10
- popsregression-0.3.7/POPSRegression.egg-info/requires.txt +0 -3
- popsregression-0.3.7/README.md +0 -74
- popsregression-0.3.7/pyproject.toml +0 -29
- {popsregression-0.3.7/POPSRegression.egg-info → popsregression-0.5.0/popsregression.egg-info}/dependency_links.txt +0 -0
- {popsregression-0.3.7 → popsregression-0.5.0}/setup.cfg +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
# Maintain dependencies for GitHub Actions as recommended in SPEC8:
|
|
4
|
+
# https://github.com/scientific-python/specs/pull/325
|
|
5
|
+
# At the time of writing, release critical workflows such as
|
|
6
|
+
# pypa/gh-action-pypi-publish should use hash-based versioning for security
|
|
7
|
+
# reasons. This strategy may be generalized to all other github actions
|
|
8
|
+
# in the future.
|
|
9
|
+
- package-ecosystem: "github-actions"
|
|
10
|
+
directory: "/"
|
|
11
|
+
schedule:
|
|
12
|
+
interval: "weekly"
|
|
13
|
+
groups:
|
|
14
|
+
actions:
|
|
15
|
+
patterns:
|
|
16
|
+
- "*"
|
|
17
|
+
reviewers:
|
|
18
|
+
- "glemaitre"
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
name: Documentation
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
|
|
11
|
+
concurrency:
|
|
12
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
13
|
+
cancel-in-progress: true
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
build:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v6
|
|
20
|
+
with:
|
|
21
|
+
fetch-depth: 0
|
|
22
|
+
|
|
23
|
+
- uses: astral-sh/setup-uv@v6
|
|
24
|
+
with:
|
|
25
|
+
enable-cache: true
|
|
26
|
+
python-version: "3.12"
|
|
27
|
+
|
|
28
|
+
- name: Build documentation
|
|
29
|
+
run: uv run --locked --group doc mkdocs build
|
|
30
|
+
|
|
31
|
+
- name: Upload pages artifact
|
|
32
|
+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
|
|
33
|
+
uses: actions/upload-pages-artifact@v4
|
|
34
|
+
with:
|
|
35
|
+
path: ./site
|
|
36
|
+
|
|
37
|
+
deploy:
|
|
38
|
+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
|
|
39
|
+
needs: build
|
|
40
|
+
runs-on: ubuntu-latest
|
|
41
|
+
permissions:
|
|
42
|
+
pages: write
|
|
43
|
+
id-token: write
|
|
44
|
+
environment:
|
|
45
|
+
name: github-pages
|
|
46
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
47
|
+
steps:
|
|
48
|
+
- name: Deploy to GitHub Pages
|
|
49
|
+
id: deployment
|
|
50
|
+
uses: actions/deploy-pages@v4
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: Linter
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
|
|
11
|
+
concurrency:
|
|
12
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
13
|
+
cancel-in-progress: true
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
build:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v6
|
|
20
|
+
|
|
21
|
+
- uses: astral-sh/setup-uv@v6
|
|
22
|
+
with:
|
|
23
|
+
enable-cache: true
|
|
24
|
+
python-version: "3.12"
|
|
25
|
+
|
|
26
|
+
- name: Check formatting
|
|
27
|
+
run: uv run --locked --group lint black --check --diff popsregression examples
|
|
28
|
+
|
|
29
|
+
- name: Run linter
|
|
30
|
+
run: uv run --locked --group lint ruff check --output-format=full popsregression examples
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
permissions:
|
|
11
|
+
id-token: write
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v6
|
|
14
|
+
with:
|
|
15
|
+
fetch-depth: 0
|
|
16
|
+
|
|
17
|
+
- uses: actions/setup-python@v6
|
|
18
|
+
with:
|
|
19
|
+
python-version: "3.12"
|
|
20
|
+
|
|
21
|
+
- name: Install build tools
|
|
22
|
+
run: pip install build
|
|
23
|
+
|
|
24
|
+
- name: Build package
|
|
25
|
+
run: python -m build
|
|
26
|
+
|
|
27
|
+
- name: Publish to PyPI
|
|
28
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: Unit Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
|
|
11
|
+
concurrency:
|
|
12
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
13
|
+
cancel-in-progress: true
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
build:
|
|
17
|
+
strategy:
|
|
18
|
+
matrix:
|
|
19
|
+
os: [windows-latest, ubuntu-latest, macos-latest]
|
|
20
|
+
runs-on: ${{ matrix.os }}
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@v6
|
|
23
|
+
with:
|
|
24
|
+
fetch-depth: 0
|
|
25
|
+
|
|
26
|
+
- uses: astral-sh/setup-uv@v6
|
|
27
|
+
with:
|
|
28
|
+
enable-cache: true
|
|
29
|
+
python-version: "3.12"
|
|
30
|
+
|
|
31
|
+
- name: Run tests
|
|
32
|
+
run: >-
|
|
33
|
+
uv run --locked --group test
|
|
34
|
+
pytest -vsl --cov=popsregression --cov-report=xml popsregression examples/comparisons
|
|
35
|
+
|
|
36
|
+
- name: Upload coverage reports to Codecov
|
|
37
|
+
uses: codecov/codecov-action@v5.5.3
|
|
38
|
+
continue-on-error: true
|
|
39
|
+
with:
|
|
40
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
|
41
|
+
slug: POPS-UQ/popsregression
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
|
|
11
|
+
.Python
|
|
12
|
+
env/
|
|
13
|
+
build/
|
|
14
|
+
develop-eggs/
|
|
15
|
+
dist/
|
|
16
|
+
downloads/
|
|
17
|
+
eggs/
|
|
18
|
+
.eggs/
|
|
19
|
+
lib/
|
|
20
|
+
lib64/
|
|
21
|
+
parts/
|
|
22
|
+
sdist/
|
|
23
|
+
var/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
|
|
28
|
+
# PyInstaller
|
|
29
|
+
# Usually these files are written by a python script from a template
|
|
30
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
31
|
+
*.manifest
|
|
32
|
+
*.spec
|
|
33
|
+
|
|
34
|
+
# Installer logs
|
|
35
|
+
pip-log.txt
|
|
36
|
+
pip-delete-this-directory.txt
|
|
37
|
+
|
|
38
|
+
# Unit test / coverage reports
|
|
39
|
+
htmlcov/
|
|
40
|
+
.tox/
|
|
41
|
+
.coverage
|
|
42
|
+
.coverage.*
|
|
43
|
+
.cache
|
|
44
|
+
nosetests.xml
|
|
45
|
+
coverage.xml
|
|
46
|
+
*,cover
|
|
47
|
+
.hypothesis/
|
|
48
|
+
|
|
49
|
+
# Translations
|
|
50
|
+
*.mo
|
|
51
|
+
*.pot
|
|
52
|
+
|
|
53
|
+
# Django stuff:
|
|
54
|
+
*.log
|
|
55
|
+
|
|
56
|
+
# MkDocs documentation
|
|
57
|
+
site/
|
|
58
|
+
|
|
59
|
+
# PyBuilder
|
|
60
|
+
target/
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
# General
|
|
64
|
+
.DS_Store
|
|
65
|
+
.AppleDouble
|
|
66
|
+
.LSOverride
|
|
67
|
+
|
|
68
|
+
# auto-generated files
|
|
69
|
+
popsregression/_version.py
|
|
70
|
+
|
|
71
|
+
# Local virtual environments
|
|
72
|
+
.venv/
|
|
73
|
+
venv/
|
|
74
|
+
|
|
75
|
+
# Per-point prediction exports (large, regenerable)
|
|
76
|
+
examples/generated/predictions/
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
3
|
+
rev: v4.3.0
|
|
4
|
+
hooks:
|
|
5
|
+
- id: check-yaml
|
|
6
|
+
- id: end-of-file-fixer
|
|
7
|
+
- id: trailing-whitespace
|
|
8
|
+
- repo: https://github.com/psf/black
|
|
9
|
+
rev: 23.3.0
|
|
10
|
+
hooks:
|
|
11
|
+
- id: black
|
|
12
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
13
|
+
rev: v0.0.272
|
|
14
|
+
hooks:
|
|
15
|
+
- id: ruff
|
|
16
|
+
args: ["--fix", "--show-source"]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Copyright (c) 2025, Thomas D Swinburne, Danny Perez and contributors
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
|
8
|
+
list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
|
12
|
+
and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
* Neither the name of popsregression nor the names of its
|
|
15
|
+
contributors may be used to endorse or promote products derived from
|
|
16
|
+
this software without specific prior written permission.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# What ships to PyPI.
|
|
2
|
+
#
|
|
3
|
+
# setuptools_scm hands the sdist every git-tracked file, so without these rules
|
|
4
|
+
# `pip install popsregression` from source would also download the example
|
|
5
|
+
# scripts, their bundled ACE data and every figure. Those belong on GitHub
|
|
6
|
+
# only; the sdist keeps just what is needed to build, install and test.
|
|
7
|
+
|
|
8
|
+
include LICENSE
|
|
9
|
+
include README.md
|
|
10
|
+
include pyproject.toml
|
|
11
|
+
|
|
12
|
+
prune examples
|
|
13
|
+
prune docs
|
|
14
|
+
|
|
15
|
+
exclude MERGE_NOTES.md
|
|
16
|
+
exclude SimpleExample.ipynb
|
|
17
|
+
exclude mkdocs.yml
|
|
18
|
+
exclude uv.lock
|
|
19
|
+
|
|
20
|
+
# Belt and braces: never ship bulk data or figures, wherever they are added.
|
|
21
|
+
global-exclude *.npz *.npy *.pkl *.pickle
|
|
22
|
+
global-exclude *.png *.pdf *.ipynb
|
|
23
|
+
global-exclude __pycache__/* *.py[cod]
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: popsregression
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: Bayesian regression for low-noise data with misspecification uncertainty (POPS algorithm).
|
|
5
|
+
Author-email: Thomas D Swinburne <tswin@umich.edu>, Danny Perez <danny_perez@lanl.gov>
|
|
6
|
+
Project-URL: Homepage, https://github.com/POPS-UQ/popsregression
|
|
7
|
+
Project-URL: Issues, https://github.com/POPS-UQ/popsregression/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
14
|
+
Classifier: Operating System :: POSIX
|
|
15
|
+
Classifier: Operating System :: Unix
|
|
16
|
+
Classifier: Operating System :: MacOS
|
|
17
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: jax>=0.4.35
|
|
22
|
+
Requires-Dist: scipy>=1.7.0
|
|
23
|
+
Requires-Dist: numpy>=1.22.0
|
|
24
|
+
Provides-Extra: examples
|
|
25
|
+
Requires-Dist: matplotlib; extra == "examples"
|
|
26
|
+
Requires-Dist: pandas>=2.3.3; extra == "examples"
|
|
27
|
+
Requires-Dist: scikit-learn>=1.6.1; extra == "examples"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# popsregression
|
|
31
|
+
|
|
32
|
+
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.
|
|
33
|
+
|
|
34
|
+
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.
|
|
35
|
+
|
|
36
|
+
- **`POPSRegression`** constructs the pointwise ensemble or its PCA-aligned hypercube.
|
|
37
|
+
- **`POPSEllipseRegression`** fits an ellipsoidal parameter distribution with optional empirical-Bayes or PAC-Bayes regularization.
|
|
38
|
+
|
|
39
|
+
[Method and tutorials](https://pops-uq.github.io/) · [Python documentation for this branch](docs/index.md) · [Kermode group regression demo](https://kermodegroup.github.io/demos/regression-demo.html) · [Standalone Julia implementation](https://github.com/POPS-UQ/POPSRegression.jl)
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
Install this checkout with Python 3.10 or newer. The numerical dependencies are JAX, SciPy and NumPy.
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
git clone --branch jax-integration https://github.com/POPS-UQ/popsregression.git
|
|
47
|
+
cd popsregression
|
|
48
|
+
python -m pip install -e .
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Quick start
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import numpy as np
|
|
55
|
+
from popsregression import POPSRegression
|
|
56
|
+
|
|
57
|
+
x = np.linspace(-1, 1, 32)
|
|
58
|
+
X_train = np.polynomial.legendre.legvander(x, 4)
|
|
59
|
+
y_train = np.sin(2 * np.pi * x) + 0.3 * x**2
|
|
60
|
+
X_test = np.polynomial.legendre.legvander(np.linspace(-1, 1, 201), 4)
|
|
61
|
+
|
|
62
|
+
# Fit POPSRegression
|
|
63
|
+
# fit_intercept=False by default
|
|
64
|
+
model = POPSRegression()
|
|
65
|
+
model.fit(X_train, y_train)
|
|
66
|
+
|
|
67
|
+
# Prediction with misspecification & epistemic uncertainty
|
|
68
|
+
y_pred, y_std = model.predict(X_test, return_std=True)
|
|
69
|
+
|
|
70
|
+
# Also return min/max bounds over the posterior
|
|
71
|
+
y_pred, y_std, y_max, y_min = model.predict(
|
|
72
|
+
X_test, return_std=True, return_bounds=True
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
# Also return epistemic-only uncertainty separately
|
|
76
|
+
y_pred, y_std, y_max, y_min, y_epistemic_std = model.predict(
|
|
77
|
+
X_test,
|
|
78
|
+
return_std=True,
|
|
79
|
+
return_bounds=True,
|
|
80
|
+
return_epistemic_std=True,
|
|
81
|
+
)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Key parameters
|
|
85
|
+
|
|
86
|
+
| Parameter | Default | Description |
|
|
87
|
+
|---|---|---|
|
|
88
|
+
| `posterior` | `'hypercube'` | Posterior form: `'hypercube'` (PCA-aligned box) or `'ensemble'` (raw corrections); the ellipsoid is `POPSEllipseRegression` (below) |
|
|
89
|
+
| `random_state` | `None` | Seed for the posterior resampling; `None` uses the global NumPy state |
|
|
90
|
+
| `resampling_method` | `'uniform'` | Sampling method: `'uniform'`, `'sobol'`, `'latin'`, `'halton'` |
|
|
91
|
+
| `resample_density` | `1.0` | Number of posterior samples per training point |
|
|
92
|
+
| `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 |
|
|
93
|
+
| `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 |
|
|
94
|
+
| `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 |
|
|
95
|
+
| `mode_threshold` | `1e-8` | Eigenvalue threshold for hypercube dimensionality |
|
|
96
|
+
| `percentile_clipping` | `0.0` | Percentile to clip from hypercube bounds (0–50) |
|
|
97
|
+
|
|
98
|
+
The Bayesian ridge parameters of the mean fit (`max_iter`, `tol`, `alpha_1`,
|
|
99
|
+
`alpha_2`, `lambda_1`, `lambda_2`, `alpha_init`, `lambda_init`,
|
|
100
|
+
`fit_intercept`) are also supported.
|
|
101
|
+
|
|
102
|
+
> [!WARNING]
|
|
103
|
+
> `minimum_relative_error` is deprecated: training points are now selected by
|
|
104
|
+
> the norm of their pointwise correction rather than by their residual. A
|
|
105
|
+
> value passed to it is forwarded to `minimum_relative_correction` with a
|
|
106
|
+
> `FutureWarning`. `leverage_percentile`, `compute_score`, `copy_X` and
|
|
107
|
+
> `verbose` have been removed.
|
|
108
|
+
|
|
109
|
+
## Key attributes (after fitting)
|
|
110
|
+
|
|
111
|
+
| Attribute | Description |
|
|
112
|
+
|---|---|
|
|
113
|
+
| `coef_`, `intercept_` | Regression coefficients (posterior mean) and intercept |
|
|
114
|
+
| `sigma_` | Epistemic variance-covariance matrix |
|
|
115
|
+
| `misspecification_sigma_` | Misspecification variance-covariance matrix from POPS |
|
|
116
|
+
| `posterior_samples_` | Weight perturbations, with one sample per column |
|
|
117
|
+
| `alpha_` | Estimated noise precision (not used for prediction) |
|
|
118
|
+
| `pointwise_corrections_`, `leverage_`, `selected_` | Pointwise corrections, leverages and the points kept for the posterior |
|
|
119
|
+
|
|
120
|
+
## Ellipsoid posteriors: `POPSEllipseRegression`
|
|
121
|
+
[Run the PAC-Ellipse tutorial](docs/pac-ellipse.md) to fit a bounded simulator, inspect its risk certificate and propagate joint predictions.
|
|
122
|
+
|
|
123
|
+
`POPSEllipseRegression` fits a parameter distribution that is uniform on an
|
|
124
|
+
ellipsoid. For a linear model its predictive density at `x` has a closed form,
|
|
125
|
+
so the zero-noise generalization error is minimized directly. Predictive
|
|
126
|
+
densities, exact quantiles and parameter draws are available in closed form
|
|
127
|
+
(for the hierarchical layers, exactly for the stored finite mixture of
|
|
128
|
+
hyperparameter draws that represents the predictive). The `regularization` parameter chooses how the finite-data uncertainty
|
|
129
|
+
of the ellipsoid itself is handled:
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from popsregression import POPSEllipseRegression
|
|
133
|
+
|
|
134
|
+
bare = POPSEllipseRegression().fit(X_train, y_train)
|
|
135
|
+
|
|
136
|
+
# Empirical-Bayes layer (Ellipse+EB): a Laplace hyperposterior over the
|
|
137
|
+
# ellipsoid, with its prior centered on the fit. Cheap; its diagnostic_bound_
|
|
138
|
+
# is not a PAC bound.
|
|
139
|
+
eb = POPSEllipseRegression(regularization="empirical-bayes").fit(X_train, y_train)
|
|
140
|
+
|
|
141
|
+
# PAC layer (Ellipse+PAC): the prior over the ellipsoid is fixed on a random
|
|
142
|
+
# half of the data, and a PAC-Bayes bound on the population log risk is
|
|
143
|
+
# evaluated on the other half (and vice versa). y_bounds must be known in
|
|
144
|
+
# advance (e.g. from a maximum principle), not read off the data.
|
|
145
|
+
pac = POPSEllipseRegression(regularization="PAC", y_bounds=(y_lower, y_upper))
|
|
146
|
+
pac.fit(X_train, y_train, groups=case_id) # groups: rows of one simulator case
|
|
147
|
+
pac.certificate_.raw_bound, pac.certificate_.trivial_bound # bound for the returned predictive
|
|
148
|
+
|
|
149
|
+
lo, hi = eb.predict_interval(X_test, level=0.9545) # exact central interval
|
|
150
|
+
logp = eb.predict_logpdf(X_test, y_test)
|
|
151
|
+
fields = eb.sample_predictions(X_test, 1000) # joint draws for propagation
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
All predictions refer to parameter uncertainty only; no noise term is added.
|
|
155
|
+
The PAC bound certifies the log risk of the predictive density, not interval
|
|
156
|
+
coverage. See the
|
|
157
|
+
[ellipse documentation](docs/ellipse.md)
|
|
158
|
+
and the [glossary](docs/glossary.md) for the
|
|
159
|
+
terms used above.
|
|
160
|
+
|
|
161
|
+
## Comparison methods and paper studies
|
|
162
|
+
|
|
163
|
+
PACm, PAC²-T, predictive variational inference and a finite
|
|
164
|
+
POPS-dictionary weighting ablation are implemented in `examples/comparisons/`,
|
|
165
|
+
outside the package. The scripts in `examples/` produce every figure and table
|
|
166
|
+
of the accompanying paper; see [examples/README.md](examples/README.md).
|
|
167
|
+
|
|
168
|
+
## Backend
|
|
169
|
+
|
|
170
|
+
All numerical kernels (the Bayesian ridge fit, the pointwise corrections, the
|
|
171
|
+
ellipsoid optimization, the PAC certification and the mixture predictives) are
|
|
172
|
+
written in [JAX](https://jax.readthedocs.io) and compiled on first use.
|
|
173
|
+
|
|
174
|
+
- The first call for a given problem shape pays a compilation cost of about a
|
|
175
|
+
second; later calls with the same shapes reuse the compiled kernel.
|
|
176
|
+
- Importing the package enables JAX double precision
|
|
177
|
+
(`jax_enable_x64`), a process-wide JAX setting.
|
|
178
|
+
- With a GPU build of JAX the same code runs on the accelerator.
|
|
179
|
+
- Inputs and fitted attributes (`coef_`, `sigma_`, ...) are NumPy arrays.
|
|
180
|
+
|
|
181
|
+
scikit-learn is not required. The estimators keep the familiar
|
|
182
|
+
`fit` / `predict` / `get_params` / `set_params` usage, so they still work
|
|
183
|
+
inside scikit-learn pipelines and parameter searches when it is installed.
|
|
184
|
+
|
|
185
|
+
## Pipeline compatibility
|
|
186
|
+
|
|
187
|
+
If scikit-learn is installed, both estimators can be used in its pipelines and
|
|
188
|
+
hyperparameter search:
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
from sklearn.pipeline import make_pipeline
|
|
192
|
+
from sklearn.preprocessing import PolynomialFeatures
|
|
193
|
+
|
|
194
|
+
pipe = make_pipeline(
|
|
195
|
+
PolynomialFeatures(degree=4),
|
|
196
|
+
POPSRegression(resampling_method='sobol'),
|
|
197
|
+
)
|
|
198
|
+
pipe.fit(X_train, y_train)
|
|
199
|
+
y_pred = pipe.predict(X_test)
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Development
|
|
203
|
+
|
|
204
|
+
The repository is managed with [uv](https://docs.astral.sh/uv/); `uv run`
|
|
205
|
+
resolves the pinned environment from `uv.lock` on first use.
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
uv run --group test pytest -vsl popsregression examples/comparisons # tests
|
|
209
|
+
uv run --group lint ruff check popsregression examples # linter
|
|
210
|
+
uv run --group lint black --check popsregression examples
|
|
211
|
+
uv run --group doc mkdocs serve # docs at localhost:8000
|
|
212
|
+
cd examples && uv run --extra examples python example_polynomial.py # a figure
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Without uv, `pip install -e ".[examples]"` and run the tools directly.
|
|
216
|
+
|
|
217
|
+
## Citation
|
|
218
|
+
|
|
219
|
+
> *Parameter uncertainties for imperfect surrogate models in the low-noise regime*
|
|
220
|
+
>
|
|
221
|
+
> TD Swinburne and D Perez, [Machine Learning: Science and Technology 2025](https://doi.org/10.1088/2632-2153/ad9fce)
|
|
222
|
+
|
|
223
|
+
```bibtex
|
|
224
|
+
@article{swinburne2025,
|
|
225
|
+
author={Swinburne, Thomas and Perez, Danny},
|
|
226
|
+
title={Parameter uncertainties for imperfect surrogate models in the low-noise regime},
|
|
227
|
+
journal={Machine Learning: Science and Technology},
|
|
228
|
+
doi={10.1088/2632-2153/ad9fce},
|
|
229
|
+
year={2025}
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
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](https://openreview.net/forum?id=gD3LoosP0w).
|
|
234
|
+
|
|
235
|
+
## Contributors
|
|
236
|
+
|
|
237
|
+
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](https://github.com/POPS-UQ/popsregression/pull/15). The [JAX adaptation](https://github.com/POPS-UQ/popsregression/commit/8c129db) uses the prior scale learned by the Bayesian ridge fit. Enable it with `prior_kl=True` on `POPSEllipseRegression`.
|
|
238
|
+
|
|
239
|
+
## AI usage
|
|
240
|
+
|
|
241
|
+
Claude assisted with documentation and test cases. Thomas D. Swinburne reviewed the code described in the original release.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Backwards compatibility shim. Remove in a future release.
|
|
2
|
+
import warnings
|
|
3
|
+
|
|
4
|
+
warnings.warn(
|
|
5
|
+
"Importing from 'POPSRegression' is deprecated. "
|
|
6
|
+
"Use 'from popsregression import POPSRegression' instead.",
|
|
7
|
+
DeprecationWarning,
|
|
8
|
+
stacklevel=2,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
from popsregression import POPSRegression # noqa: F401, E402
|
|
12
|
+
|
|
13
|
+
__all__ = ["POPSRegression"]
|