lcgp 0.1.2__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 (47) hide show
  1. lcgp-0.1.2/.github/workflows/ci.yml +56 -0
  2. lcgp-0.1.2/.github/workflows/publish.yml +37 -0
  3. lcgp-0.1.2/.github/workflows/ruff.yaml +12 -0
  4. lcgp-0.1.2/.gitignore +57 -0
  5. lcgp-0.1.2/.pre-commit-config.yaml +7 -0
  6. lcgp-0.1.2/.readthedocs.yaml +32 -0
  7. lcgp-0.1.2/CITATION.cff +30 -0
  8. lcgp-0.1.2/LICENSE.txt +21 -0
  9. lcgp-0.1.2/MANIFEST.in +4 -0
  10. lcgp-0.1.2/Makefile +56 -0
  11. lcgp-0.1.2/PKG-INFO +189 -0
  12. lcgp-0.1.2/README.md +151 -0
  13. lcgp-0.1.2/experiments/__init__.py +0 -0
  14. lcgp-0.1.2/experiments/run_experiments.py +98 -0
  15. lcgp-0.1.2/experiments/summary/dss_summary_latex.tex +20 -0
  16. lcgp-0.1.2/experiments/summary/nrmse_summary_latex.tex +20 -0
  17. lcgp-0.1.2/experiments/summary/pcover_summary_latex.tex +20 -0
  18. lcgp-0.1.2/experiments/summary/pwidth_summary_latex.tex +20 -0
  19. lcgp-0.1.2/experiments/summary/rmse_summary_latex.tex +20 -0
  20. lcgp-0.1.2/experiments/summary/traintime_summary_latex.tex +20 -0
  21. lcgp-0.1.2/experiments/testfunc_wrapper.py +46 -0
  22. lcgp-0.1.2/experiments/testfunctions/TestingfunctionBorehole.py +300 -0
  23. lcgp-0.1.2/experiments/testfunctions/TestingfunctionOTLcircuit.py +126 -0
  24. lcgp-0.1.2/experiments/testfunctions/TestingfunctionPiston.py +108 -0
  25. lcgp-0.1.2/experiments/testfunctions/TestingfunctionWingweight.py +481 -0
  26. lcgp-0.1.2/experiments/testfunctions/__init__.py +0 -0
  27. lcgp-0.1.2/lcgp/__init__.py +6 -0
  28. lcgp-0.1.2/lcgp/_version.py +4 -0
  29. lcgp-0.1.2/lcgp/covmat.py +84 -0
  30. lcgp-0.1.2/lcgp/evaluation.py +63 -0
  31. lcgp-0.1.2/lcgp/hyperparameter_tuning.py +28 -0
  32. lcgp-0.1.2/lcgp/lcgp.py +785 -0
  33. lcgp-0.1.2/lcgp/optim.py +162 -0
  34. lcgp-0.1.2/lcgp.egg-info/PKG-INFO +189 -0
  35. lcgp-0.1.2/lcgp.egg-info/SOURCES.txt +45 -0
  36. lcgp-0.1.2/lcgp.egg-info/dependency_links.txt +1 -0
  37. lcgp-0.1.2/lcgp.egg-info/requires.txt +3 -0
  38. lcgp-0.1.2/lcgp.egg-info/top_level.txt +4 -0
  39. lcgp-0.1.2/pyproject.toml +52 -0
  40. lcgp-0.1.2/real-data-example/vah_example.py +93 -0
  41. lcgp-0.1.2/reference_code/LBFGS.py +1109 -0
  42. lcgp-0.1.2/requirements.txt +11 -0
  43. lcgp-0.1.2/setup.cfg +4 -0
  44. lcgp-0.1.2/setup.py +6 -0
  45. lcgp-0.1.2/submethod-illustration/lcgp-submethod-illustration.py +92 -0
  46. lcgp-0.1.2/tests/__init__.py +0 -0
  47. lcgp-0.1.2/tests/test_lcgp.py +216 -0
@@ -0,0 +1,56 @@
1
+ name: CI
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ push:
6
+ branches: [ main ]
7
+ pull_request:
8
+ branches: [ main ]
9
+
10
+ jobs:
11
+ test:
12
+ runs-on:
13
+ ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ python-version: ["3.8", "3.9", "3.10", "3.11"]
17
+ steps:
18
+ - uses: actions/checkout@v3
19
+ - name: Set up Python ${{ matrix.python-version }}
20
+ uses: actions/setup-python@v4
21
+ with:
22
+ python-version: ${{ matrix.python-version }}
23
+ cache: 'pip'
24
+ - name: Install dependencies
25
+ run: |
26
+ pip install --upgrade pip setuptools 'setuptools_scm[toml]' setuptools_scm_git_archive numpy Cython
27
+ python setup.py --version
28
+ pip install --no-cache-dir -U -r requirements.txt | cat
29
+ pip install --upgrade numpy
30
+ pip install ruff pytest
31
+ - name: Lint with ruff
32
+ run: |
33
+ # stop the build if there are Python syntax errors or undefined names
34
+ ruff --format=github --select=E9,F63,F7,F82 --exclude=illustration-examples,reference_code .
35
+ # default set of ruff rules with GitHub Annotations
36
+ ruff --format=github --exclude=illustration-examples,reference_code,tests .
37
+ - name: Test with pytest
38
+ run: pytest
39
+ - name: Upload coverage data
40
+ run: |
41
+ coveralls --service=github
42
+ env:
43
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44
+ COVERALLS_FLAG_NAME: ${{ matrix.test-name }}
45
+ COVERALLS_PARALLEL: true
46
+
47
+ finish:
48
+ name: Finish Coveralls
49
+ needs: test
50
+ runs-on: ubuntu-latest
51
+ steps:
52
+ - name: Coveralls GitHub Action
53
+ uses: coverallsapp/github-action@v2
54
+ with:
55
+ github-token: ${{ secrets.GITHUB_TOKEN }}
56
+ parallel-finished: true
@@ -0,0 +1,37 @@
1
+ # This workflow publishes releases to https://pypi.org/project/surmise/
2
+
3
+ name: PyPI publisher
4
+
5
+ on:
6
+ release:
7
+ types: [ published ]
8
+
9
+ jobs:
10
+ pypi-publish:
11
+ name: Build and upload release to PyPI
12
+ runs-on: ubuntu-latest
13
+ environment:
14
+ name: pypi
15
+ url: https://pypi.org/project/lcgp/
16
+ permissions:
17
+ id-token: write
18
+ steps:
19
+ - uses: actions/checkout@v3
20
+ - name: Set up Python
21
+ uses: actions/setup-python@v4
22
+ with:
23
+ python-version: "3.x"
24
+ - name: Install pypa/build
25
+ run: >-
26
+ python3 -m pip install build --user
27
+ - name: Build a binary wheel and a source tarball
28
+ run: >-
29
+ python3 -m build
30
+ --sdist
31
+ --wheel
32
+ --outdir dist/
33
+ .
34
+ - name: Publish distribution 📦 to PyPI
35
+ uses: pypa/gh-action-pypi-publish@release/v1
36
+ with:
37
+ password: ${{ secrets.PYPI_ACCESS_TOKEN }}
@@ -0,0 +1,12 @@
1
+ name: Ruff
2
+ on: [push, pull_request]
3
+ jobs:
4
+ ruff:
5
+ runs-on: ubuntu-latest
6
+ steps:
7
+ - uses: actions/checkout@v3
8
+ - uses: chartboost/ruff-action@v1
9
+
10
+ with:
11
+ version: 0.0.280
12
+ args: --fix --exit-non-zero-on-fix
lcgp-0.1.2/.gitignore ADDED
@@ -0,0 +1,57 @@
1
+ # local virtual environment and pycharm files
2
+ .idea/
3
+
4
+ venv/
5
+ *.pyc
6
+ *.pclprof
7
+ *.dat
8
+
9
+ # build
10
+ build/
11
+ dist/
12
+ lcgp.egg-info/
13
+
14
+ # archive
15
+ src/archive/*
16
+ lcgp/archive/
17
+ lcgp/debug/
18
+ lcgp/reference_code/
19
+ lcgp/plot_code/
20
+
21
+ # data files
22
+ tests/data/*
23
+ tests/testfunctions/*
24
+
25
+ # documentation and coverage
26
+ docs/_build
27
+ docs/_static
28
+ docs/source
29
+ cover
30
+ .coverage
31
+
32
+ # illustrations
33
+ submethod-illustration/illustrate-submethod-loss.py
34
+ illustration-examples/lcgp-3d-illustration-addon.py
35
+ illustration-examples/lcgp-3d-mean-var.py
36
+ # figures
37
+ illustration-examples/output_fig/*
38
+ # notebooks
39
+ illustration-examples/notebooks/*
40
+
41
+ # output and plot files
42
+ */data/
43
+ */output/
44
+ */figures/
45
+ *plot.py
46
+
47
+ # debug files
48
+ illustration-examples/lcgp_debug.py
49
+
50
+ # other codes
51
+ reference_code/GPPCA/
52
+
53
+ # ignore version
54
+ lcgp/_version.py
55
+
56
+ # pdfs
57
+ literature/
@@ -0,0 +1,7 @@
1
+ repos:
2
+ - repo: https://github.com/astral-sh/ruff-pre-commit
3
+ # Ruff version.
4
+ rev: v0.0.282
5
+ hooks:
6
+ - id: ruff
7
+ args: [--fix, --exit-non-zero-on-fix]
@@ -0,0 +1,32 @@
1
+ # .readthedocs.yaml
2
+ # Read the Docs configuration file
3
+ # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4
+
5
+ # Required
6
+ version: 2
7
+
8
+ # Set the OS, Python version and other tools you might need
9
+ build:
10
+ os: ubuntu-22.04
11
+ tools:
12
+ python: "3.11"
13
+ # You can also specify other tool versions:
14
+ # nodejs: "19"
15
+ # rust: "1.64"
16
+ # golang: "1.19"
17
+
18
+ # Build documentation in the "docs/" directory with Sphinx
19
+ sphinx:
20
+ configuration: docs/conf.py
21
+
22
+ # Optionally build your docs in additional formats such as PDF and ePub
23
+ # formats:
24
+ # - pdf
25
+ # - epub
26
+
27
+ # Optional but recommended, declare the Python requirements required
28
+ # to build your documentation
29
+ # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
30
+ python:
31
+ install:
32
+ - requirements: docs/requirements.txt
@@ -0,0 +1,30 @@
1
+ # This CITATION.cff file was generated with cffinit.
2
+ # Visit https://bit.ly/cffinit to generate yours today!
3
+
4
+ cff-version: 1.2.0
5
+ title: Latent component Gaussian process
6
+ message: >-
7
+ If you use this software, please cite it using the
8
+ metadata from this file.
9
+ type: software
10
+ authors:
11
+ - given-names: Moses Y.-H.
12
+ family-names: Chan
13
+ email: mosesyhc@u.northwestern.edu
14
+ affiliation: Northwestern University
15
+ orcid: 'https://orcid.org/0000-0002-2181-5116'
16
+ identifiers:
17
+ - type: url
18
+ value: 'https://github.com/mosesyhc/lcgp'
19
+ repository-code: 'https://github.com/mosesyhc/lcgp'
20
+ url: 'https://lcgp.readthedocs.io'
21
+ abstract: >-
22
+ An emulator strategy for multivariate stochastic
23
+ simulations.
24
+ keywords:
25
+ - stochastic simulation
26
+ - multivariate output
27
+ - gaussian process
28
+ - emulator
29
+ - surrogate
30
+ license: MIT
lcgp-0.1.2/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Moses Chan <mosesyhc@u.northwestern.edu>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
lcgp-0.1.2/MANIFEST.in ADDED
@@ -0,0 +1,4 @@
1
+ include pyproject.toml
2
+ prune illustration-examples*
3
+ prune literature*
4
+ prune docs*
lcgp-0.1.2/Makefile ADDED
@@ -0,0 +1,56 @@
1
+ .PHONY: docmake docopen docinit docremove docupdate install test clean
2
+
3
+ PACKAGE := lcgp
4
+
5
+ docmake:
6
+ rm -rf docs/source
7
+ sphinx-apidoc -eMT -o docs/source/ $(PACKAGE)
8
+ rm docs/source/$(PACKAGE).rst
9
+ pandoc --from=markdown --to=rst --output=docs/readme.rst README.md
10
+ cd docs && make html
11
+
12
+ docopen:
13
+ open docs/_build/html/index.html
14
+
15
+ docinit:
16
+ $(eval BRANCH := $(shell git rev-parse --abbrev-ref HEAD))
17
+ git checkout -b gh-pages
18
+ git ls-tree HEAD \
19
+ | awk '$$4 !~ /\.nojekyll|docs|index\.html/ { print $$4 }' \
20
+ | xargs -I {} git rm -r {}
21
+ touch .nojekyll
22
+ echo '<meta http-equiv="refresh" content="0; url=./docs/_build/html/index.html" />' > index.html
23
+ git add .nojekyll index.html
24
+ git commit -m "Branch cleaned for docs"
25
+ git push origin gh-pages
26
+ git checkout $(BRANCH)
27
+
28
+ docremove:
29
+ git branch -D gh-pages
30
+ git push origin --delete gh-pages
31
+
32
+ docupdate: docmake
33
+ $(eval BRANCH := $(shell git rev-parse --abbrev-ref HEAD))
34
+ rm -rf docs/_build/html_new
35
+ mv docs/_build/html docs/_build/html_new
36
+ git checkout gh-pages
37
+ rm -rf docs/_build/html
38
+ mv docs/_build/html_new docs/_build/html
39
+ git add -f docs/_build/html
40
+ git commit -m "Update docs at $$(date +'%d %b %Y, %H:%M')"
41
+ git push origin gh-pages
42
+ git checkout $(BRANCH)
43
+
44
+ install:
45
+ pip install -r requirements.txt
46
+
47
+ test:
48
+ python setup.py --version
49
+ # pytest -v --cov=$(PACKAGE) --cov-report html:cover --cov-report term-missing
50
+
51
+ clean:
52
+ rm -rf docs/_build docs/source docs/readme.rst
53
+ git rm --cached -r docs
54
+ git add docs/Makefile docs/conf.py docs/index.rst docs/api.rst
55
+ rm -rf .coverage cover
56
+ find . | grep '\(\.DS_Store\|\.pyc\)$$' | xargs rm
lcgp-0.1.2/PKG-INFO ADDED
@@ -0,0 +1,189 @@
1
+ Metadata-Version: 2.1
2
+ Name: lcgp
3
+ Version: 0.1.2
4
+ Summary: Latent component Gaussian process
5
+ Author-email: Moses Chan <mosesyhc@u.northwestern.edu>
6
+ License: The MIT License (MIT)
7
+
8
+ Copyright (c) 2023 Moses Chan <mosesyhc@u.northwestern.edu>
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in
18
+ all copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
+ THE SOFTWARE.
27
+
28
+ Project-URL: Repository, https://github.com/mosesyhc/lcgp
29
+ Classifier: Programming Language :: Python :: 3
30
+ Classifier: License :: OSI Approved :: MIT License
31
+ Classifier: Operating System :: OS Independent
32
+ Requires-Python: >=3.8
33
+ Description-Content-Type: text/markdown
34
+ License-File: LICENSE.txt
35
+ Requires-Dist: torch>=2.0.1
36
+ Requires-Dist: numpy>=1.18.3
37
+ Requires-Dist: scipy>=1.10.1
38
+
39
+ # [Latent component Gaussian process (LCGP)](https://github.com/mosesyhc/LCGP)
40
+
41
+ [![CI](https://github.com/mosesyhc/lcgp/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/mosesyhc/LCGP/actions/workflows/ci.yml)
42
+ [![Coverage Status](https://coveralls.io/repos/github/mosesyhc/LCGP/badge.svg)](https://coveralls.io/github/mosesyhc/LCGP)
43
+ [![Documentation Status](https://readthedocs.org/projects/lcgp/badge/?version=latest)](https://lcgp.readthedocs.io/en/latest/?badge=latest)
44
+ [![PyPI version](https://badge.fury.io/py/lcgp.svg)](https://badge.fury.io/py/lcgp)
45
+
46
+ Implementation of latent component Gaussian process (LCGP). LCGP handles the emulation
47
+ of multivariate stochastic simulation outputs.
48
+
49
+ ___
50
+
51
+ List of Contents:
52
+
53
+ - [Installation](#installation)
54
+ - [Basic Usage](#basic-usage)
55
+ - [What most of us need](#what-most-of-us-need)
56
+ - [Specifying number of latent components](#specifying-number-of-latent-components)
57
+ - [Specifying diagonal error groups](#specifying-diagonal-error-groupings)
58
+ - [Calling different submethod](#define-lcgp-using-different-submethod)
59
+ - [Standardization choices](#standardization-choices)
60
+
61
+
62
+ ## Installation
63
+ The implementation of LCGP can be installed through
64
+
65
+ ```bash
66
+ pip install lcgp
67
+ ```
68
+
69
+ > **Note on LBFGS optimizer:**
70
+ >
71
+ > It is strongly recommended that
72
+ > [PyTorch-LBFGS](https://github.com/hjmshi/PyTorch-LBFGS) is installed to fully utilize
73
+ > this implementation.
74
+ > Installation guide on PyTorch-LBFGS can be found on
75
+ > [its repository](https://github.com/hjmshi/PyTorch-LBFGS).
76
+ > Note that PyTorch-LBFGS has an additional requirement `matplotlib`. The source code of a version
77
+ > of PyTorch-LBFGS that **does not** require `matplotlib` is included in [reference_code](reference_code/).
78
+ >
79
+
80
+ ## Basic usage
81
+ ### What most of us need:
82
+ ```python
83
+ import numpy as np
84
+ from lcgp import LCGP
85
+ from lcgp import evaluation # optional evaluation module
86
+
87
+ # Generate fifty 2-dimensional input and 4-dimensional output
88
+ x = np.random.randn(50, 2)
89
+ y = np.random.randn(4, 50)
90
+
91
+ # Define LCGP model
92
+ model = LCGP(y=y, x=x)
93
+
94
+ # Estimate error covariance and hyperparameters
95
+ model.fit()
96
+
97
+ # Prediction
98
+ p = model.predict(x0=x) # mean and variance
99
+ rmse = evaluation.rmse(y, p[0].numpy())
100
+ dss = evaluation.dss(y, p[0].numpy(), p[1].numpy(), use_diag=True)
101
+ print('Root mean squared error: {:.3E}'.format(rmse))
102
+ print('Dawid-Sebastiani score: {:.3f}'.format(dss))
103
+
104
+ # Access parameters
105
+ print(model)
106
+ ```
107
+
108
+ ### Specifying number of latent components
109
+ There are two ways to specify the number of latent components by
110
+ passing one of the following arguments in initializing an LCGP instance:
111
+
112
+ - `q = 5`: Five latent components will be used. `q` must be less than or
113
+ equal to the output dimension.
114
+ - `var_threshold = 0.99`: Include $q$ latent components such that 99% of the output
115
+ variance are explained, using a singular value decomposition.
116
+
117
+ > **Note**: Only one of the options should be provided at a time.
118
+
119
+ ```python
120
+ model_q = LCGP(y=y, x=x, q=5)
121
+ model_var = LCGP(y=y, x=x, var_threshold=0.99)
122
+ ```
123
+
124
+ ### Specifying diagonal error groupings
125
+ If errors of multiple output dimensions are expected to be similar, the error variances
126
+ can be grouped in estimation.
127
+
128
+ For example, the 6-dimensional output is split into two groups: the
129
+ first two have low errors and the remaining four have high errors.
130
+
131
+ ```python
132
+ import numpy as np
133
+
134
+ x = np.linspace(0, 1, 100)
135
+ y = np.row_stack((
136
+ np.sin(x), np.cos(x), np.tan(x),
137
+ np.sin(x/2), np.cos(x/2), np.tan(x/2)
138
+ ))
139
+
140
+ y[:2] += np.random.normal(2, 1e-3, size=(2, 100))
141
+ y[2:] += np.random.normal(-2, 1e-1, size=(4, 100))
142
+ ```
143
+
144
+ Then, LCGP can be defined with the argument `diag_error_structure` as a list
145
+ of output dimensions to group. The following code groups the first 2 and the remaining
146
+ 4 output dimensions.
147
+ ```python
148
+ model_diag = LCGP(y=y, x=x, diag_error_structure=[2, 4])
149
+ ```
150
+
151
+ By default, LCGP assigns a separate error variance to each dimension,
152
+ equivalent to
153
+
154
+ ```python
155
+ model_diag = LCGP(y=y, x=x, diag_error_structure=[1]*6)
156
+ ```
157
+
158
+ ### Define LCGP using different submethod
159
+ Three submethods are implemented under LCGP:
160
+
161
+ * Full posterior (`full`)
162
+ * ELBO (`elbo`)
163
+ * Profile likelihood (`proflik`)
164
+
165
+ Under circumstances where the simulation outputs are stochastic, the full posterior
166
+ approach should perform the best. If the simulation outputs are deterministic, the
167
+ profile likelihood method should suffice.
168
+
169
+ ```python
170
+ LCGP_models = []
171
+ submethods = ['full', 'elbo', 'proflik']
172
+ for submethod in submethods:
173
+ model = LCGP(y=y, x=x, submethod=submethod)
174
+ LCGP_models.append(model)
175
+ ```
176
+
177
+ ### Standardization choices
178
+ LCGP standardizes the simulation output by each dimension to facilitate hyperparameter
179
+ training. The two choices are implemented through `robust_mean = True` or
180
+ `robust_mean = False`.
181
+
182
+ * `robust_mean = False`: The empirical mean and standard deviation are used.
183
+ * `robust_mean = True`: The empirical median and median absolute error are used.
184
+
185
+ ```python
186
+ model = LCGP(y=y, x=x, robust_mean=False)
187
+ ```
188
+
189
+ ---
lcgp-0.1.2/README.md ADDED
@@ -0,0 +1,151 @@
1
+ # [Latent component Gaussian process (LCGP)](https://github.com/mosesyhc/LCGP)
2
+
3
+ [![CI](https://github.com/mosesyhc/lcgp/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/mosesyhc/LCGP/actions/workflows/ci.yml)
4
+ [![Coverage Status](https://coveralls.io/repos/github/mosesyhc/LCGP/badge.svg)](https://coveralls.io/github/mosesyhc/LCGP)
5
+ [![Documentation Status](https://readthedocs.org/projects/lcgp/badge/?version=latest)](https://lcgp.readthedocs.io/en/latest/?badge=latest)
6
+ [![PyPI version](https://badge.fury.io/py/lcgp.svg)](https://badge.fury.io/py/lcgp)
7
+
8
+ Implementation of latent component Gaussian process (LCGP). LCGP handles the emulation
9
+ of multivariate stochastic simulation outputs.
10
+
11
+ ___
12
+
13
+ List of Contents:
14
+
15
+ - [Installation](#installation)
16
+ - [Basic Usage](#basic-usage)
17
+ - [What most of us need](#what-most-of-us-need)
18
+ - [Specifying number of latent components](#specifying-number-of-latent-components)
19
+ - [Specifying diagonal error groups](#specifying-diagonal-error-groupings)
20
+ - [Calling different submethod](#define-lcgp-using-different-submethod)
21
+ - [Standardization choices](#standardization-choices)
22
+
23
+
24
+ ## Installation
25
+ The implementation of LCGP can be installed through
26
+
27
+ ```bash
28
+ pip install lcgp
29
+ ```
30
+
31
+ > **Note on LBFGS optimizer:**
32
+ >
33
+ > It is strongly recommended that
34
+ > [PyTorch-LBFGS](https://github.com/hjmshi/PyTorch-LBFGS) is installed to fully utilize
35
+ > this implementation.
36
+ > Installation guide on PyTorch-LBFGS can be found on
37
+ > [its repository](https://github.com/hjmshi/PyTorch-LBFGS).
38
+ > Note that PyTorch-LBFGS has an additional requirement `matplotlib`. The source code of a version
39
+ > of PyTorch-LBFGS that **does not** require `matplotlib` is included in [reference_code](reference_code/).
40
+ >
41
+
42
+ ## Basic usage
43
+ ### What most of us need:
44
+ ```python
45
+ import numpy as np
46
+ from lcgp import LCGP
47
+ from lcgp import evaluation # optional evaluation module
48
+
49
+ # Generate fifty 2-dimensional input and 4-dimensional output
50
+ x = np.random.randn(50, 2)
51
+ y = np.random.randn(4, 50)
52
+
53
+ # Define LCGP model
54
+ model = LCGP(y=y, x=x)
55
+
56
+ # Estimate error covariance and hyperparameters
57
+ model.fit()
58
+
59
+ # Prediction
60
+ p = model.predict(x0=x) # mean and variance
61
+ rmse = evaluation.rmse(y, p[0].numpy())
62
+ dss = evaluation.dss(y, p[0].numpy(), p[1].numpy(), use_diag=True)
63
+ print('Root mean squared error: {:.3E}'.format(rmse))
64
+ print('Dawid-Sebastiani score: {:.3f}'.format(dss))
65
+
66
+ # Access parameters
67
+ print(model)
68
+ ```
69
+
70
+ ### Specifying number of latent components
71
+ There are two ways to specify the number of latent components by
72
+ passing one of the following arguments in initializing an LCGP instance:
73
+
74
+ - `q = 5`: Five latent components will be used. `q` must be less than or
75
+ equal to the output dimension.
76
+ - `var_threshold = 0.99`: Include $q$ latent components such that 99% of the output
77
+ variance are explained, using a singular value decomposition.
78
+
79
+ > **Note**: Only one of the options should be provided at a time.
80
+
81
+ ```python
82
+ model_q = LCGP(y=y, x=x, q=5)
83
+ model_var = LCGP(y=y, x=x, var_threshold=0.99)
84
+ ```
85
+
86
+ ### Specifying diagonal error groupings
87
+ If errors of multiple output dimensions are expected to be similar, the error variances
88
+ can be grouped in estimation.
89
+
90
+ For example, the 6-dimensional output is split into two groups: the
91
+ first two have low errors and the remaining four have high errors.
92
+
93
+ ```python
94
+ import numpy as np
95
+
96
+ x = np.linspace(0, 1, 100)
97
+ y = np.row_stack((
98
+ np.sin(x), np.cos(x), np.tan(x),
99
+ np.sin(x/2), np.cos(x/2), np.tan(x/2)
100
+ ))
101
+
102
+ y[:2] += np.random.normal(2, 1e-3, size=(2, 100))
103
+ y[2:] += np.random.normal(-2, 1e-1, size=(4, 100))
104
+ ```
105
+
106
+ Then, LCGP can be defined with the argument `diag_error_structure` as a list
107
+ of output dimensions to group. The following code groups the first 2 and the remaining
108
+ 4 output dimensions.
109
+ ```python
110
+ model_diag = LCGP(y=y, x=x, diag_error_structure=[2, 4])
111
+ ```
112
+
113
+ By default, LCGP assigns a separate error variance to each dimension,
114
+ equivalent to
115
+
116
+ ```python
117
+ model_diag = LCGP(y=y, x=x, diag_error_structure=[1]*6)
118
+ ```
119
+
120
+ ### Define LCGP using different submethod
121
+ Three submethods are implemented under LCGP:
122
+
123
+ * Full posterior (`full`)
124
+ * ELBO (`elbo`)
125
+ * Profile likelihood (`proflik`)
126
+
127
+ Under circumstances where the simulation outputs are stochastic, the full posterior
128
+ approach should perform the best. If the simulation outputs are deterministic, the
129
+ profile likelihood method should suffice.
130
+
131
+ ```python
132
+ LCGP_models = []
133
+ submethods = ['full', 'elbo', 'proflik']
134
+ for submethod in submethods:
135
+ model = LCGP(y=y, x=x, submethod=submethod)
136
+ LCGP_models.append(model)
137
+ ```
138
+
139
+ ### Standardization choices
140
+ LCGP standardizes the simulation output by each dimension to facilitate hyperparameter
141
+ training. The two choices are implemented through `robust_mean = True` or
142
+ `robust_mean = False`.
143
+
144
+ * `robust_mean = False`: The empirical mean and standard deviation are used.
145
+ * `robust_mean = True`: The empirical median and median absolute error are used.
146
+
147
+ ```python
148
+ model = LCGP(y=y, x=x, robust_mean=False)
149
+ ```
150
+
151
+ ---
File without changes