POPSRegression 0.3.7__tar.gz → 0.4.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.
Files changed (59) hide show
  1. popsregression-0.4.0/.coveragerc +6 -0
  2. popsregression-0.4.0/.github/dependabot.yml +18 -0
  3. popsregression-0.4.0/.github/workflows/deploy-gh-pages.yml +51 -0
  4. popsregression-0.4.0/.github/workflows/lint.yml +28 -0
  5. popsregression-0.4.0/.github/workflows/publish.yml +28 -0
  6. popsregression-0.4.0/.github/workflows/python-app.yml +41 -0
  7. popsregression-0.4.0/.gitignore +78 -0
  8. popsregression-0.4.0/.pre-commit-config.yaml +16 -0
  9. popsregression-0.4.0/LICENSE +27 -0
  10. popsregression-0.4.0/PKG-INFO +165 -0
  11. popsregression-0.4.0/POPSRegression.py +13 -0
  12. popsregression-0.4.0/README.md +140 -0
  13. popsregression-0.4.0/SimpleExample.ipynb +59 -0
  14. popsregression-0.4.0/doc/Makefile +184 -0
  15. popsregression-0.4.0/doc/_static/css/project-template.css +59 -0
  16. popsregression-0.4.0/doc/_static/img/index_api.svg +97 -0
  17. popsregression-0.4.0/doc/_static/img/index_examples.svg +76 -0
  18. popsregression-0.4.0/doc/_static/img/index_getting_started.svg +66 -0
  19. popsregression-0.4.0/doc/_static/img/index_user_guide.svg +67 -0
  20. popsregression-0.4.0/doc/_static/img/logo.png +0 -0
  21. popsregression-0.4.0/doc/_static/js/copybutton.js +63 -0
  22. popsregression-0.4.0/doc/_templates/class.rst +26 -0
  23. popsregression-0.4.0/doc/_templates/function.rst +12 -0
  24. popsregression-0.4.0/doc/_templates/numpydoc_docstring.py +16 -0
  25. popsregression-0.4.0/doc/_templates/sidebar-search-bs.html +14 -0
  26. popsregression-0.4.0/doc/api.rst +27 -0
  27. popsregression-0.4.0/doc/conf.py +114 -0
  28. popsregression-0.4.0/doc/index.rst +108 -0
  29. popsregression-0.4.0/doc/make.bat +242 -0
  30. popsregression-0.4.0/doc/quick_start.rst +67 -0
  31. popsregression-0.4.0/doc/user_guide.rst +114 -0
  32. popsregression-0.4.0/example_image.png +0 -0
  33. popsregression-0.4.0/examples/README.txt +6 -0
  34. popsregression-0.4.0/examples/plot_pops_regression.py +220 -0
  35. popsregression-0.4.0/popsregression/__init__.py +11 -0
  36. popsregression-0.4.0/popsregression/_pops.py +509 -0
  37. popsregression-0.4.0/popsregression/_version.py +34 -0
  38. popsregression-0.4.0/popsregression/tests/__init__.py +2 -0
  39. popsregression-0.4.0/popsregression/tests/test_common.py +17 -0
  40. popsregression-0.4.0/popsregression/tests/test_pops.py +258 -0
  41. popsregression-0.4.0/popsregression/utils/__init__.py +2 -0
  42. popsregression-0.4.0/popsregression/utils/discovery.py +221 -0
  43. popsregression-0.4.0/popsregression/utils/tests/__init__.py +2 -0
  44. popsregression-0.4.0/popsregression/utils/tests/test_discovery.py +32 -0
  45. popsregression-0.4.0/popsregression.egg-info/PKG-INFO +165 -0
  46. popsregression-0.4.0/popsregression.egg-info/SOURCES.txt +49 -0
  47. {popsregression-0.3.7/POPSRegression.egg-info → popsregression-0.4.0/popsregression.egg-info}/top_level.txt +1 -0
  48. popsregression-0.4.0/pyproject.toml +146 -0
  49. popsregression-0.3.7/LICENSE +0 -21
  50. popsregression-0.3.7/PKG-INFO +0 -91
  51. popsregression-0.3.7/POPSRegression/POPSRegression.py +0 -530
  52. popsregression-0.3.7/POPSRegression/__init__.py +0 -1
  53. popsregression-0.3.7/POPSRegression.egg-info/PKG-INFO +0 -91
  54. popsregression-0.3.7/POPSRegression.egg-info/SOURCES.txt +0 -10
  55. popsregression-0.3.7/README.md +0 -74
  56. popsregression-0.3.7/pyproject.toml +0 -29
  57. {popsregression-0.3.7/POPSRegression.egg-info → popsregression-0.4.0/popsregression.egg-info}/dependency_links.txt +0 -0
  58. {popsregression-0.3.7/POPSRegression.egg-info → popsregression-0.4.0/popsregression.egg-info}/requires.txt +0 -0
  59. {popsregression-0.3.7 → popsregression-0.4.0}/setup.cfg +0 -0
@@ -0,0 +1,6 @@
1
+ # Configuration for coverage.py
2
+
3
+ [run]
4
+ branch = True
5
+ source = popsregression
6
+ include = */popsregression/*
@@ -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,51 @@
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: prefix-dev/setup-pixi@v0.9.4
24
+ with:
25
+ pixi-version: v0.41.4
26
+ environments: doc
27
+ frozen: false
28
+
29
+ - name: Build documentation
30
+ run: pixi run -e doc build-doc
31
+
32
+ - name: Upload pages artifact
33
+ if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
34
+ uses: actions/upload-pages-artifact@v3
35
+ with:
36
+ path: ./doc/_build/html
37
+
38
+ deploy:
39
+ if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
40
+ needs: build
41
+ runs-on: ubuntu-latest
42
+ permissions:
43
+ pages: write
44
+ id-token: write
45
+ environment:
46
+ name: github-pages
47
+ url: ${{ steps.deployment.outputs.page_url }}
48
+ steps:
49
+ - name: Deploy to GitHub Pages
50
+ id: deployment
51
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,28 @@
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: prefix-dev/setup-pixi@v0.9.4
22
+ with:
23
+ pixi-version: v0.41.4
24
+ environments: lint
25
+ frozen: false
26
+
27
+ - name: Run linter
28
+ run: pixi run -e lint lint
@@ -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
+ environment: [test]
21
+ runs-on: ${{ matrix.os }}
22
+ steps:
23
+ - uses: actions/checkout@v6
24
+ with:
25
+ fetch-depth: 0
26
+
27
+ - uses: prefix-dev/setup-pixi@v0.9.4
28
+ with:
29
+ pixi-version: v0.41.4
30
+ environments: ${{ matrix.environment }}
31
+ frozen: false
32
+
33
+ - name: Run tests
34
+ run: pixi run -e ${{ matrix.environment }} test
35
+
36
+ - name: Upload coverage reports to Codecov
37
+ uses: codecov/codecov-action@v5.5.2
38
+ continue-on-error: true
39
+ with:
40
+ token: ${{ secrets.CODECOV_TOKEN }}
41
+ slug: tomswinburne/popsregression
@@ -0,0 +1,78 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # scikit-learn specific
10
+ doc/_build/
11
+ doc/auto_examples/
12
+ doc/modules/generated/
13
+ doc/datasets/generated/
14
+
15
+ # Distribution / packaging
16
+
17
+ .Python
18
+ env/
19
+ build/
20
+ develop-eggs/
21
+ dist/
22
+ downloads/
23
+ eggs/
24
+ .eggs/
25
+ lib/
26
+ lib64/
27
+ parts/
28
+ sdist/
29
+ var/
30
+ *.egg-info/
31
+ .installed.cfg
32
+ *.egg
33
+
34
+ # PyInstaller
35
+ # Usually these files are written by a python script from a template
36
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
37
+ *.manifest
38
+ *.spec
39
+
40
+ # Installer logs
41
+ pip-log.txt
42
+ pip-delete-this-directory.txt
43
+
44
+ # Unit test / coverage reports
45
+ htmlcov/
46
+ .tox/
47
+ .coverage
48
+ .coverage.*
49
+ .cache
50
+ nosetests.xml
51
+ coverage.xml
52
+ *,cover
53
+ .hypothesis/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+
62
+ # Sphinx documentation
63
+ doc/_build/
64
+ doc/generated/
65
+ doc/sg_execution_times.rst
66
+
67
+ # PyBuilder
68
+ target/
69
+
70
+ .pixi
71
+
72
+ # General
73
+ .DS_Store
74
+ .AppleDouble
75
+ .LSOverride
76
+
77
+ # auto-generated files
78
+ popsregression/_version.py
@@ -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,165 @@
1
+ Metadata-Version: 2.4
2
+ Name: popsregression
3
+ Version: 0.4.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/tomswinburne/popsregression
7
+ Project-URL: Issues, https://github.com/tomswinburne/popsregression/issues
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.9
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
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.9
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: scikit-learn>=1.6.1
22
+ Requires-Dist: scipy>=1.6.0
23
+ Requires-Dist: numpy>=1.20.0
24
+ Dynamic: license-file
25
+
26
+ popsregression
27
+ =================================================
28
+
29
+ ![tests](https://github.com/tomswinburne/popsregression/actions/workflows/python-app.yml/badge.svg)
30
+ [![codecov](https://codecov.io/gh/tomswinburne/popsregression/graph/badge.svg?token=L0XPWwoPLw)](https://codecov.io/gh/tomswinburne/popsregression)
31
+ ![doc](https://github.com/tomswinburne/popsregression/actions/workflows/deploy-gh-pages.yml/badge.svg)
32
+
33
+ **popsregression** is a [scikit-learn](https://scikit-learn.org) compatible
34
+ package providing `POPSRegression`, a Bayesian regression method for low-noise
35
+ data that accounts for model misspecification uncertainty.
36
+
37
+ **Try it out!** [online demo from Kermode group](https://kermodegroup.github.io/demos/regression-demo.html) comparing multiple regression schemes.
38
+
39
+ ## Misspecification-aware Bayesian regression
40
+ Standard Bayesian regression (e.g. `BayesianRidge`) estimates epistemic and
41
+ aleatoric uncertainties, but provably ignore model misspecification- errors arising from limited model form (see example below). In the low-noise (weak aleatoric / near-deterministic) limit, weight uncertainties (`sigma_`) are significantly underestimated as they only capture epistemic uncertainty, which decays with increasing data. Any remaining error is attributed to aleatoric noise (`alpha_`), which is erroneous in low-noise settings.
42
+
43
+ `POPSRegression` efficiently estimates **model misspecification uncertainty**
44
+ via the Pointwise Optimal Parameter Sets (POPS) algorithm, finidng parameter perturbations that would fit each training point exactly.
45
+ The result is wider, more honest uncertainty estimates that properly cover the true function, even when the model class cannot perfectly represent the target.
46
+
47
+ The misspecified, near-deterministic regression problem that `POPSRegression` addresses is particularly relevant to the fitting of surrogate simulation models in computational science, i.e. interatomic potentials,where by construction the optimal surrogate model is structurally unable to capture the target function exactly.
48
+
49
+ ## Example
50
+ Fitting a quartic polynomial (P=5 parameters) to a complex oscillatory function with N=10, 50, 500 training points. Top row: BayesianRidge epistemic uncertainty vanishes with more data. Bottom rows: POPS correctly maintains uncertainty where the polynomial deviates from the truth.
51
+
52
+ ![Example comparison of BayesianRidge vs POPS uncertainty](example_image.png)
53
+
54
+ See the [SimpleExample.ipynb](SimpleExample.ipynb) notebook for a runnable version.
55
+
56
+ ## Installation
57
+
58
+ ```bash
59
+ pip install popsregression
60
+ ```
61
+
62
+ **Dependencies**: scikit-learn >= 1.6.1, scipy >= 1.6.0, numpy >= 1.20.0
63
+
64
+ ## Quick start
65
+
66
+ ```python
67
+ from popsregression import POPSRegression
68
+
69
+ X_train, X_test, y_train, y_test = ...
70
+
71
+ # Fit POPSRegression
72
+ # fit_intercept=False by default
73
+ model = POPSRegression()
74
+ model.fit(X_train, y_train)
75
+
76
+ # Prediction with misspecification & epistemic uncertainty
77
+ y_pred, y_std = model.predict(X_test, return_std=True)
78
+
79
+ # Also return min/max bounds over the posterior
80
+ y_pred, y_std, y_max, y_min = model.predict(
81
+ X_test, return_std=True, return_bounds=True
82
+ )
83
+ # Also return epistemic-only uncertainty separately
84
+ y_pred, y_std, y_max, y_min, y_epistemic_std = model.predict(
85
+ X_test,
86
+ return_std=True,
87
+ return_bounds=True,
88
+ return_epistemic_std=True,
89
+ )
90
+ ```
91
+
92
+ ## Key parameters
93
+
94
+ | Parameter | Default | Description |
95
+ |---|---|---|
96
+ | `posterior` | `'hypercube'` | Posterior form: `'hypercube'` (PCA-aligned box) or `'ensemble'` (raw corrections) |
97
+ | `resampling_method` | `'uniform'` | Sampling method: `'uniform'`, `'sobol'`, `'latin'`, `'halton'` |
98
+ | `resample_density` | `1.0` | Number of posterior samples per training point |
99
+ | `leverage_percentile` | `50.0` | Only use high-leverage training points for POPS posterior |
100
+ | `mode_threshold` | `1e-8` | Eigenvalue threshold for hypercube dimensionality |
101
+ | `percentile_clipping` | `0.0` | Percentile to clip from hypercube bounds (0–50) |
102
+
103
+ All `BayesianRidge` parameters (`max_iter`, `tol`, `alpha_1`, `alpha_2`,
104
+ `lambda_1`, `lambda_2`, `fit_intercept`, etc.) are also supported.
105
+
106
+ ## Key attributes (after fitting)
107
+
108
+ | Attribute | Description |
109
+ |---|---|
110
+ | `coef_` | Regression coefficients (posterior mean) |
111
+ | `sigma_` | Epistemic variance-covariance matrix |
112
+ | `misspecification_sigma_` | Misspecification variance-covariance matrix from POPS |
113
+ | `posterior_samples_` | Samples from the POPS posterior |
114
+ | `alpha_` | Estimated noise precision (not used for prediction) |
115
+
116
+ ## Pipeline compatibility
117
+
118
+ `POPSRegression` is fully compatible with scikit-learn pipelines and
119
+ hyperparameter search:
120
+
121
+ ```python
122
+ from sklearn.pipeline import make_pipeline
123
+
124
+ pipe = make_pipeline(
125
+ PolynomialFeatures(degree=4),
126
+ POPSRegression(resampling_method='sobol'),
127
+ )
128
+ pipe.fit(X_train, y_train)
129
+ y_pred = pipe.predict(X_test)
130
+ ```
131
+
132
+ ## scikit-learn style documentation
133
+
134
+ https://tomswinburne.github.io/popsregression
135
+
136
+ ## Development
137
+
138
+ ```bash
139
+ # Install in development mode
140
+ pip install -e .
141
+
142
+ # Run tests
143
+ pytest -vsl popsregression
144
+
145
+ # With pixi
146
+ pixi run test
147
+ pixi run lint
148
+ pixi run build-doc
149
+ ```
150
+
151
+ ## Citation
152
+
153
+ > *Parameter uncertainties for imperfect surrogate models in the low-noise regime*
154
+ >
155
+ > TD Swinburne and D Perez, [Machine Learning: Science and Technology 2025](http://iopscience.iop.org/article/10.1088/2632-2153/ad9fce)
156
+
157
+ ```bibtex
158
+ @article{swinburne2025,
159
+ author={Swinburne, Thomas and Perez, Danny},
160
+ title={Parameter uncertainties for imperfect surrogate models in the low-noise regime},
161
+ journal={Machine Learning: Science and Technology},
162
+ doi={10.1088/2632-2153/ad9fce},
163
+ year={2025}
164
+ }
165
+ ```
@@ -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"]
@@ -0,0 +1,140 @@
1
+ popsregression
2
+ =================================================
3
+
4
+ ![tests](https://github.com/tomswinburne/popsregression/actions/workflows/python-app.yml/badge.svg)
5
+ [![codecov](https://codecov.io/gh/tomswinburne/popsregression/graph/badge.svg?token=L0XPWwoPLw)](https://codecov.io/gh/tomswinburne/popsregression)
6
+ ![doc](https://github.com/tomswinburne/popsregression/actions/workflows/deploy-gh-pages.yml/badge.svg)
7
+
8
+ **popsregression** is a [scikit-learn](https://scikit-learn.org) compatible
9
+ package providing `POPSRegression`, a Bayesian regression method for low-noise
10
+ data that accounts for model misspecification uncertainty.
11
+
12
+ **Try it out!** [online demo from Kermode group](https://kermodegroup.github.io/demos/regression-demo.html) comparing multiple regression schemes.
13
+
14
+ ## Misspecification-aware Bayesian regression
15
+ Standard Bayesian regression (e.g. `BayesianRidge`) estimates epistemic and
16
+ aleatoric uncertainties, but provably ignore model misspecification- errors arising from limited model form (see example below). In the low-noise (weak aleatoric / near-deterministic) limit, weight uncertainties (`sigma_`) are significantly underestimated as they only capture epistemic uncertainty, which decays with increasing data. Any remaining error is attributed to aleatoric noise (`alpha_`), which is erroneous in low-noise settings.
17
+
18
+ `POPSRegression` efficiently estimates **model misspecification uncertainty**
19
+ via the Pointwise Optimal Parameter Sets (POPS) algorithm, finidng parameter perturbations that would fit each training point exactly.
20
+ The result is wider, more honest uncertainty estimates that properly cover the true function, even when the model class cannot perfectly represent the target.
21
+
22
+ The misspecified, near-deterministic regression problem that `POPSRegression` addresses is particularly relevant to the fitting of surrogate simulation models in computational science, i.e. interatomic potentials,where by construction the optimal surrogate model is structurally unable to capture the target function exactly.
23
+
24
+ ## Example
25
+ Fitting a quartic polynomial (P=5 parameters) to a complex oscillatory function with N=10, 50, 500 training points. Top row: BayesianRidge epistemic uncertainty vanishes with more data. Bottom rows: POPS correctly maintains uncertainty where the polynomial deviates from the truth.
26
+
27
+ ![Example comparison of BayesianRidge vs POPS uncertainty](example_image.png)
28
+
29
+ See the [SimpleExample.ipynb](SimpleExample.ipynb) notebook for a runnable version.
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install popsregression
35
+ ```
36
+
37
+ **Dependencies**: scikit-learn >= 1.6.1, scipy >= 1.6.0, numpy >= 1.20.0
38
+
39
+ ## Quick start
40
+
41
+ ```python
42
+ from popsregression import POPSRegression
43
+
44
+ X_train, X_test, y_train, y_test = ...
45
+
46
+ # Fit POPSRegression
47
+ # fit_intercept=False by default
48
+ model = POPSRegression()
49
+ model.fit(X_train, y_train)
50
+
51
+ # Prediction with misspecification & epistemic uncertainty
52
+ y_pred, y_std = model.predict(X_test, return_std=True)
53
+
54
+ # Also return min/max bounds over the posterior
55
+ y_pred, y_std, y_max, y_min = model.predict(
56
+ X_test, return_std=True, return_bounds=True
57
+ )
58
+ # Also return epistemic-only uncertainty separately
59
+ y_pred, y_std, y_max, y_min, y_epistemic_std = model.predict(
60
+ X_test,
61
+ return_std=True,
62
+ return_bounds=True,
63
+ return_epistemic_std=True,
64
+ )
65
+ ```
66
+
67
+ ## Key parameters
68
+
69
+ | Parameter | Default | Description |
70
+ |---|---|---|
71
+ | `posterior` | `'hypercube'` | Posterior form: `'hypercube'` (PCA-aligned box) or `'ensemble'` (raw corrections) |
72
+ | `resampling_method` | `'uniform'` | Sampling method: `'uniform'`, `'sobol'`, `'latin'`, `'halton'` |
73
+ | `resample_density` | `1.0` | Number of posterior samples per training point |
74
+ | `leverage_percentile` | `50.0` | Only use high-leverage training points for POPS posterior |
75
+ | `mode_threshold` | `1e-8` | Eigenvalue threshold for hypercube dimensionality |
76
+ | `percentile_clipping` | `0.0` | Percentile to clip from hypercube bounds (0–50) |
77
+
78
+ All `BayesianRidge` parameters (`max_iter`, `tol`, `alpha_1`, `alpha_2`,
79
+ `lambda_1`, `lambda_2`, `fit_intercept`, etc.) are also supported.
80
+
81
+ ## Key attributes (after fitting)
82
+
83
+ | Attribute | Description |
84
+ |---|---|
85
+ | `coef_` | Regression coefficients (posterior mean) |
86
+ | `sigma_` | Epistemic variance-covariance matrix |
87
+ | `misspecification_sigma_` | Misspecification variance-covariance matrix from POPS |
88
+ | `posterior_samples_` | Samples from the POPS posterior |
89
+ | `alpha_` | Estimated noise precision (not used for prediction) |
90
+
91
+ ## Pipeline compatibility
92
+
93
+ `POPSRegression` is fully compatible with scikit-learn pipelines and
94
+ hyperparameter search:
95
+
96
+ ```python
97
+ from sklearn.pipeline import make_pipeline
98
+
99
+ pipe = make_pipeline(
100
+ PolynomialFeatures(degree=4),
101
+ POPSRegression(resampling_method='sobol'),
102
+ )
103
+ pipe.fit(X_train, y_train)
104
+ y_pred = pipe.predict(X_test)
105
+ ```
106
+
107
+ ## scikit-learn style documentation
108
+
109
+ https://tomswinburne.github.io/popsregression
110
+
111
+ ## Development
112
+
113
+ ```bash
114
+ # Install in development mode
115
+ pip install -e .
116
+
117
+ # Run tests
118
+ pytest -vsl popsregression
119
+
120
+ # With pixi
121
+ pixi run test
122
+ pixi run lint
123
+ pixi run build-doc
124
+ ```
125
+
126
+ ## Citation
127
+
128
+ > *Parameter uncertainties for imperfect surrogate models in the low-noise regime*
129
+ >
130
+ > TD Swinburne and D Perez, [Machine Learning: Science and Technology 2025](http://iopscience.iop.org/article/10.1088/2632-2153/ad9fce)
131
+
132
+ ```bibtex
133
+ @article{swinburne2025,
134
+ author={Swinburne, Thomas and Perez, Danny},
135
+ title={Parameter uncertainties for imperfect surrogate models in the low-noise regime},
136
+ journal={Machine Learning: Science and Technology},
137
+ doi={10.1088/2632-2153/ad9fce},
138
+ year={2025}
139
+ }
140
+ ```
@@ -0,0 +1,59 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "ytetj8sdbwm",
6
+ "source": "## Simple test of `POPSRegression`\n\nComparing uncertainty estimates from `BayesianRidge` (epistemic only) vs `POPSRegression` (epistemic + misspecification) for a misspecified polynomial surrogate model fit to low-noise data.\n\nUsage is very similar to `sklearn.linear_model.BayesianRidge`.",
7
+ "metadata": {}
8
+ },
9
+ {
10
+ "cell_type": "code",
11
+ "id": "x4flve5v1wc",
12
+ "source": "from sklearn.linear_model import BayesianRidge\nfrom sklearn.preprocessing import PolynomialFeatures\nfrom popsregression import POPSRegression\n\nimport numpy as np\nimport matplotlib.pyplot as plt",
13
+ "metadata": {},
14
+ "execution_count": null,
15
+ "outputs": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "id": "dvuai5htn2t",
20
+ "source": "def target_function(x):\n return (x**3 + 0.01 * x**4) * 0.1 + np.sin(x) * x * 10.0\n\n\ndef generate_data(N):\n x_train = np.sort(\n np.append(np.random.uniform(-1, 1, N), np.linspace(-1, 1, 2)) * 10\n )\n x_dense = np.linspace(-1.1, 1.1, 51) * 10\n y_dense = target_function(x_dense)\n\n p = PolynomialFeatures(degree=4, include_bias=True)\n X_train = p.fit_transform(x_train.reshape(-1, 1))\n X_dense = p.fit_transform(x_dense.reshape(-1, 1))\n y_train = target_function(x_train)\n return X_train, x_train, y_train, X_dense, x_dense, y_dense\n\n\ndef plot_panel(ax, x_dense, y_dense, x_train, y_train, y_pred, y_std,\n y_max=None, y_min=None):\n if y_max is not None and y_min is not None:\n ax.fill_between(x_dense, y_min, y_max, alpha=0.2, facecolor=\"0.5\",\n label=\"max/min\")\n else:\n ax.fill_between(x_dense, y_pred - 4 * y_std, y_pred + 4 * y_std,\n alpha=0.2, facecolor=\"0.5\", label=r\"$\\pm4\\sigma$\")\n ax.fill_between(x_dense, y_pred - 2 * y_std, y_pred + 2 * y_std,\n alpha=0.5, facecolor=\"C1\", label=r\"$\\pm2\\sigma$\")\n ax.plot(x_dense, y_pred, \"C1-\", lw=4)\n ax.plot(x_train, y_train, \"b.\", label=\"Train\")\n ax.plot(x_dense, y_dense, \"k-\")",
21
+ "metadata": {},
22
+ "execution_count": null,
23
+ "outputs": []
24
+ },
25
+ {
26
+ "cell_type": "markdown",
27
+ "id": "pkoi63pvxmm",
28
+ "source": "### Compare BayesianRidge, POPS Ensemble, and POPS Hypercube\n\nFitting a quartic polynomial (P=5) to a complex oscillatory function with increasing N/P ratio. BayesianRidge epistemic uncertainty vanishes with more data, while POPS maintains honest uncertainty where the polynomial deviates from the truth.",
29
+ "metadata": {}
30
+ },
31
+ {
32
+ "cell_type": "code",
33
+ "id": "r4r3b1ezw6i",
34
+ "source": "np.random.seed(42)\n\ntitles = [\"Bayesian Ridge\", \"POPS Ensemble\", \"POPS Hypercube\"]\nfig, axs = plt.subplots(3, 3, figsize=(8, 7), sharex=True, sharey=True)\nN_array = [10, 50, 500]\nP = 5\n\nfor i, N in enumerate(N_array):\n X_train, x_train, y_train, X_dense, x_dense, y_dense = generate_data(N)\n\n ens = POPSRegression(leverage_percentile=0.0, posterior=\"ensemble\")\n hyc = POPSRegression(leverage_percentile=0.0, posterior=\"hypercube\")\n bay = BayesianRidge(fit_intercept=False)\n\n ens.fit(X_train, y_train)\n hyc.fit(X_train, y_train)\n bay.fit(X_train, y_train)\n\n # BayesianRidge - epistemic only (no aleatoric alpha_)\n b_pred = bay.predict(X_dense, return_std=False)\n b_std = np.sqrt(np.sum(np.dot(X_dense, bay.sigma_) * X_dense, axis=1))\n plot_panel(axs[0, i], x_dense, y_dense, x_train, y_train, b_pred, b_std)\n\n # POPS Ensemble\n y_pred, y_std, y_max, y_min = ens.predict(\n X_dense, return_std=True, return_bounds=True\n )\n plot_panel(axs[1, i], x_dense, y_dense, x_train, y_train, y_pred, y_std,\n y_max=y_max, y_min=y_min)\n\n # POPS Hypercube\n y_pred, y_std, y_max, y_min = hyc.predict(\n X_dense, return_std=True, return_bounds=True\n )\n plot_panel(axs[2, i], x_dense, y_dense, x_train, y_train, y_pred, y_std,\n y_max=y_max, y_min=y_min)\n\n axs[0, i].set_title(f\"N/P = {N // P}\")\n\nfor j, title in enumerate(titles):\n axs[j, 0].set_ylim(-250, 250)\n axs[j, 0].set_xlim(-10, 10)\n axs[j, 1].legend(fontsize=9, loc=\"lower center\")\n axs[j, 0].set_ylabel(title, fontsize=13)\n\nplt.tight_layout()\nplt.savefig(\"example_image.png\")\nplt.show()",
35
+ "metadata": {},
36
+ "execution_count": null,
37
+ "outputs": []
38
+ },
39
+ {
40
+ "cell_type": "markdown",
41
+ "id": "xf9qfm25vh",
42
+ "source": "### Observations\n\n- **N/P = 2**: Both methods show wide uncertainty, but POPS provides better coverage of the true function (black line).\n- **N/P = 10**: BayesianRidge epistemic uncertainty has already shrunk significantly. POPS correctly maintains wider bands where the polynomial deviates from the truth.\n- **N/P = 100**: BayesianRidge epistemic uncertainty is nearly invisible, yet the polynomial still cannot match the oscillatory target. POPS maintains honest uncertainty reflecting this structural limitation.\n\nThe **hypercube** posterior (bottom row) tends to give the most conservative bounds, while the **ensemble** posterior (middle row) directly uses the pointwise corrections.",
43
+ "metadata": {}
44
+ }
45
+ ],
46
+ "metadata": {
47
+ "kernelspec": {
48
+ "display_name": "Python 3",
49
+ "language": "python",
50
+ "name": "python3"
51
+ },
52
+ "language_info": {
53
+ "name": "python",
54
+ "version": "3.10.0"
55
+ }
56
+ },
57
+ "nbformat": 4,
58
+ "nbformat_minor": 5
59
+ }