errorcalculus 0.1.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.
- errorcalculus-0.1.0/CHANGELOG.md +30 -0
- errorcalculus-0.1.0/CITATION.cff +25 -0
- errorcalculus-0.1.0/CONTRIBUTING.md +56 -0
- errorcalculus-0.1.0/LICENSE +28 -0
- errorcalculus-0.1.0/MANIFEST.in +5 -0
- errorcalculus-0.1.0/PKG-INFO +130 -0
- errorcalculus-0.1.0/README.md +83 -0
- errorcalculus-0.1.0/docs/GUARANTEES.md +60 -0
- errorcalculus-0.1.0/docs/api.md +85 -0
- errorcalculus-0.1.0/docs/changelog.md +3 -0
- errorcalculus-0.1.0/docs/comparison.md +63 -0
- errorcalculus-0.1.0/docs/concepts.md +114 -0
- errorcalculus-0.1.0/docs/conf.py +35 -0
- errorcalculus-0.1.0/docs/getting-started.md +122 -0
- errorcalculus-0.1.0/docs/index.md +30 -0
- errorcalculus-0.1.0/docs/references.md +23 -0
- errorcalculus-0.1.0/pyproject.toml +56 -0
- errorcalculus-0.1.0/setup.cfg +4 -0
- errorcalculus-0.1.0/src/errorcalculus/__init__.py +15 -0
- errorcalculus-0.1.0/src/errorcalculus/_array.py +1067 -0
- errorcalculus-0.1.0/src/errorcalculus/_core.py +1349 -0
- errorcalculus-0.1.0/src/errorcalculus/_functions.py +358 -0
- errorcalculus-0.1.0/src/errorcalculus/_rules.py +256 -0
- errorcalculus-0.1.0/src/errorcalculus/calculus.py +90 -0
- errorcalculus-0.1.0/src/errorcalculus/compare.py +574 -0
- errorcalculus-0.1.0/src/errorcalculus/errors.py +111 -0
- errorcalculus-0.1.0/src/errorcalculus/linalg.py +249 -0
- errorcalculus-0.1.0/src/errorcalculus/operators.py +207 -0
- errorcalculus-0.1.0/src/errorcalculus.egg-info/PKG-INFO +130 -0
- errorcalculus-0.1.0/src/errorcalculus.egg-info/SOURCES.txt +58 -0
- errorcalculus-0.1.0/src/errorcalculus.egg-info/dependency_links.txt +1 -0
- errorcalculus-0.1.0/src/errorcalculus.egg-info/requires.txt +23 -0
- errorcalculus-0.1.0/src/errorcalculus.egg-info/top_level.txt +1 -0
- errorcalculus-0.1.0/tests/_helpers.py +145 -0
- errorcalculus-0.1.0/tests/_reference_cases.py +88 -0
- errorcalculus-0.1.0/tests/conftest.py +19 -0
- errorcalculus-0.1.0/tests/parity/test_g15_parity.py +171 -0
- errorcalculus-0.1.0/tests/test_api_names.py +61 -0
- errorcalculus-0.1.0/tests/test_compare_api.py +212 -0
- errorcalculus-0.1.0/tests/test_g01_g02_global_rules.py +44 -0
- errorcalculus-0.1.0/tests/test_g03_gamma_symmetric_positive.py +48 -0
- errorcalculus-0.1.0/tests/test_g04_gamma_via_bias.py +39 -0
- errorcalculus-0.1.0/tests/test_g05_transport.py +85 -0
- errorcalculus-0.1.0/tests/test_g06_identity_does_not_amplify.py +33 -0
- errorcalculus-0.1.0/tests/test_g07_orders_bitwise.py +55 -0
- errorcalculus-0.1.0/tests/test_g08_first_order_refusals.py +74 -0
- errorcalculus-0.1.0/tests/test_g09_correlated.py +108 -0
- errorcalculus-0.1.0/tests/test_g10_contributions.py +73 -0
- errorcalculus-0.1.0/tests/test_g11_assumed_zero_bias.py +70 -0
- errorcalculus-0.1.0/tests/test_g12_sigma_points.py +95 -0
- errorcalculus-0.1.0/tests/test_g13_monte_carlo.py +110 -0
- errorcalculus-0.1.0/tests/test_g14_taylor2.py +119 -0
- errorcalculus-0.1.0/tests/test_g16_array_vs_scalar.py +128 -0
- errorcalculus-0.1.0/tests/test_g17_domain.py +181 -0
- errorcalculus-0.1.0/tests/test_g18_linalg.py +391 -0
- errorcalculus-0.1.0/tests/test_g19_wrap.py +93 -0
- errorcalculus-0.1.0/tests/test_g20_sensitivities.py +195 -0
- errorcalculus-0.1.0/tests/test_g21_g22_models.py +68 -0
- errorcalculus-0.1.0/tests/test_g23_g24_operator_scale.py +76 -0
- errorcalculus-0.1.0/tests/test_regressions.py +274 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes are listed here. The 0.x series has no stable API: a minor version may change names and
|
|
4
|
+
signatures, and says so below.
|
|
5
|
+
|
|
6
|
+
## Unreleased
|
|
7
|
+
|
|
8
|
+
## 0.1.0 — 2026-12-03
|
|
9
|
+
|
|
10
|
+
First release: layer 1 of the library, the error calculus in finite dimension.
|
|
11
|
+
|
|
12
|
+
- `Model(order=1 | 2)`: a registry of error sources and the order of the calculus (mandatory). Independent inputs
|
|
13
|
+
(`input`, `input_array`) and correlated inputs (`correlated`: Cholesky, or a spectral factorisation of the
|
|
14
|
+
correlation matrix for a singular covariance). Input biases are declared at order 2; an undeclared bias is taken as
|
|
15
|
+
zero and reported (`assumed_zero_bias`), or refused with `require_bias=True`.
|
|
16
|
+
- `Quantity` and `QuantityArray` (NumPy protocols for the supported ufuncs and functions): value, sharp, error
|
|
17
|
+
variance Γ, standard deviation, bias A (order 2; `FirstOrderError` at order 1).
|
|
18
|
+
- 23 elementary functions with explicit domain rules (`DomainError`, `NonDifferentiableError`, `NonFiniteError`:
|
|
19
|
+
never a nan or an inf returned in silence).
|
|
20
|
+
- `linalg.solve`, `linalg.inv`, `linalg.det`, computed on a matrix equilibrated by powers of 2, refused above a
|
|
21
|
+
scaled condition number κ_s = ρ(|a⁻¹||a|) of 1/(100 ε).
|
|
22
|
+
- `wrap` (user functions with given or numerical derivatives, checked by step halving) and `sensitivities` (exact
|
|
23
|
+
gradient and Hessian, the latter by a paired mode of the engine).
|
|
24
|
+
- Readings: `gamma`, `covariance_matrix`, `correlation_matrix`, `contributions` (error variance by group or source;
|
|
25
|
+
bias by source with `bias_breakdown=True`), `summary(scale=s)`.
|
|
26
|
+
- `BiasOperator`: the bias operator on functions, `gamma_via_bias`, transport by a diffeomorphism.
|
|
27
|
+
- `compare_methods` and `errorcalculus.compare`: error calculus, first order, sensitivities, sigma points, Monte Carlo
|
|
28
|
+
and second-order Taylor moments of the same model.
|
|
29
|
+
- Guarantees G1–G24, each with its test file ([docs/GUARANTEES.md](docs/GUARANTEES.md)); parity with
|
|
30
|
+
`uncertainties`, GTC, soerp and folx (G15).
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use errorcalculus, please cite it as below."
|
|
3
|
+
title: "errorcalculus: Bouleau's error calculus for Python"
|
|
4
|
+
type: software
|
|
5
|
+
version: 0.1.0
|
|
6
|
+
date-released: 2026-12-03
|
|
7
|
+
authors:
|
|
8
|
+
- family-names: Rabiet
|
|
9
|
+
given-names: Victor
|
|
10
|
+
orcid: "https://orcid.org/0009-0003-3678-3457"
|
|
11
|
+
license: BSD-3-Clause
|
|
12
|
+
repository-code: "https://github.com/HubHubHubHubHub/errorcalculus"
|
|
13
|
+
url: "https://errorcalculus.readthedocs.io"
|
|
14
|
+
abstract: >-
|
|
15
|
+
errorcalculus propagates error variances (the quadratic error Γ) and, at second
|
|
16
|
+
order, biases (A) through computations, following the error calculus of
|
|
17
|
+
N. Bouleau: explicit first- or second-order models, correlated inputs, NumPy
|
|
18
|
+
arrays, linear algebra, user functions, the bias operator and its transport,
|
|
19
|
+
and a comparison with sigma points, Monte Carlo and second-order Taylor moments.
|
|
20
|
+
keywords:
|
|
21
|
+
- error calculus
|
|
22
|
+
- uncertainty propagation
|
|
23
|
+
- bias
|
|
24
|
+
- second order
|
|
25
|
+
- Dirichlet forms
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Contributing to errorcalculus
|
|
2
|
+
|
|
3
|
+
errorcalculus is maintained by one person. Reports, questions and proposals are welcome, and every one is read.
|
|
4
|
+
|
|
5
|
+
## Reporting a problem
|
|
6
|
+
|
|
7
|
+
Open an issue: <https://github.com/HubHubHubHubHub/errorcalculus/issues>. Give the version
|
|
8
|
+
(`errorcalculus.__version__`), the Python and NumPy versions, the operating system and the shortest code that shows
|
|
9
|
+
the problem.
|
|
10
|
+
|
|
11
|
+
The most valuable report is a **wrong number returned without an error**: a sharp, an error variance or a bias that
|
|
12
|
+
differs from the chain rule, or a nan or inf returned in silence. Please report it even if you are not sure.
|
|
13
|
+
|
|
14
|
+
Support is given on a best-effort basis, through the issue tracker only.
|
|
15
|
+
|
|
16
|
+
## Proposing a change
|
|
17
|
+
|
|
18
|
+
1. For anything beyond a typo, open an issue first and describe the change.
|
|
19
|
+
2. Then open a pull request against `main`, focused on one change; say in its description what changes for a user.
|
|
20
|
+
3. Add a line under `## Unreleased` in [CHANGELOG.md](CHANGELOG.md).
|
|
21
|
+
4. Code, comments, messages and documentation are in English.
|
|
22
|
+
5. Contributions are accepted under the license of the project, BSD-3-Clause ([LICENSE](LICENSE)).
|
|
23
|
+
|
|
24
|
+
**The rule every change must keep: no guarantee weakens silently.** Each guarantee of
|
|
25
|
+
[docs/GUARANTEES.md](docs/GUARANTEES.md) is checked by a named test file. A change that alters a guarantee changes
|
|
26
|
+
the register and the changelog in the same pull request.
|
|
27
|
+
|
|
28
|
+
## Running the tests
|
|
29
|
+
|
|
30
|
+
From a clone of the repository:
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
python -m venv .venv
|
|
34
|
+
.venv/bin/python -m pip install -e '.[test]'
|
|
35
|
+
.venv/bin/python -m pytest
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
On Windows, use `.venv\Scripts\python`. The parity tests (guarantee G15) run only where the compared libraries are
|
|
39
|
+
installed:
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
.venv/bin/python -m pip install -e '.[test,parity]'
|
|
43
|
+
.venv/bin/python -m pytest -m parity
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Building the documentation
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
.venv/bin/python -m pip install -e '.[docs]'
|
|
50
|
+
.venv/bin/python -m sphinx -W --keep-going -b html docs docs/_build/html
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Versions
|
|
54
|
+
|
|
55
|
+
The 0.x series has no stable API. Versions follow `MAJOR.MINOR.PATCH`; each release is tagged `vX.Y.Z` and listed in
|
|
56
|
+
the changelog.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Victor Rabiet
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: errorcalculus
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Bouleau's error calculus for Python: error variances (Γ) and biases (A) propagated through computations
|
|
5
|
+
Author: Victor Rabiet
|
|
6
|
+
License-Expression: BSD-3-Clause
|
|
7
|
+
Project-URL: Documentation, https://errorcalculus.readthedocs.io
|
|
8
|
+
Project-URL: Repository, https://github.com/HubHubHubHubHub/errorcalculus
|
|
9
|
+
Project-URL: Issues, https://github.com/HubHubHubHubHub/errorcalculus/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/HubHubHubHubHub/errorcalculus/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: error calculus,uncertainty propagation,error propagation,bias,second order,Dirichlet forms,measurement uncertainty
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: numpy>=1.24
|
|
28
|
+
Provides-Extra: scipy
|
|
29
|
+
Requires-Dist: scipy; extra == "scipy"
|
|
30
|
+
Provides-Extra: test
|
|
31
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
32
|
+
Requires-Dist: hypothesis; extra == "test"
|
|
33
|
+
Requires-Dist: sympy; extra == "test"
|
|
34
|
+
Requires-Dist: mpmath; extra == "test"
|
|
35
|
+
Requires-Dist: scipy; extra == "test"
|
|
36
|
+
Provides-Extra: parity
|
|
37
|
+
Requires-Dist: uncertainties>=3.2; extra == "parity"
|
|
38
|
+
Requires-Dist: soerp>=1.0.1; extra == "parity"
|
|
39
|
+
Requires-Dist: GTC>=1.5; extra == "parity"
|
|
40
|
+
Requires-Dist: folx>=0.2; extra == "parity"
|
|
41
|
+
Requires-Dist: jax; extra == "parity"
|
|
42
|
+
Provides-Extra: docs
|
|
43
|
+
Requires-Dist: sphinx>=8; extra == "docs"
|
|
44
|
+
Requires-Dist: furo; extra == "docs"
|
|
45
|
+
Requires-Dist: myst-parser>=4; extra == "docs"
|
|
46
|
+
Dynamic: license-file
|
|
47
|
+
|
|
48
|
+
# errorcalculus
|
|
49
|
+
|
|
50
|
+
**Bouleau's error calculus for Python.** errorcalculus propagates the *error variance* Γ (the quadratic error) and,
|
|
51
|
+
at second order, the *bias* A of quantities through a computation, exactly in the sense of the chain rule, at the
|
|
52
|
+
nominal values. It follows the error calculus of N. Bouleau (*Error Calculus for Finance and Physics: The Language of
|
|
53
|
+
Dirichlet Forms*, de Gruyter, 2003), in which Γ and A are two operators with their own calculus: a C² function F of
|
|
54
|
+
quantities x₁, …, xₙ satisfies
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
F♯ = Σᵢ ∂ᵢF · xᵢ♯ (the "sharp": a linear error)
|
|
58
|
+
Γ[F] = Σᵢⱼ ∂ᵢF ∂ⱼF Γ[xᵢ, xⱼ]
|
|
59
|
+
A[F] = Σᵢ ∂ᵢF A[xᵢ] + ½ Σᵢⱼ ∂ᵢⱼF Γ[xᵢ, xⱼ]
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
> **Status: 0.1.0, alpha.** This is the first layer of the library (finite dimension). The API of the 0.x series is
|
|
63
|
+
> not stable: names and signatures may still change, and every change is listed in the [changelog](https://github.com/HubHubHubHubHub/errorcalculus/blob/main/CHANGELOG.md).
|
|
64
|
+
|
|
65
|
+
## Install
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
python -m pip install errorcalculus
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Python 3.10 or later; NumPy is the only dependency (SciPy is used when present, for vectorised `erf`/`erfc`).
|
|
72
|
+
|
|
73
|
+
## A first computation
|
|
74
|
+
|
|
75
|
+
The order of the calculus is explicit: `order=1` propagates error variances only (Gauss); `order=2` propagates error
|
|
76
|
+
variances and biases.
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
import errorcalculus as ec
|
|
80
|
+
|
|
81
|
+
m = ec.Model(order=2)
|
|
82
|
+
x = m.input(2.0, std=0.1, bias=0.01, name="x")
|
|
83
|
+
y = m.input(3.0, std=0.2, name="y") # no bias declared: assumed zero, and reported
|
|
84
|
+
|
|
85
|
+
f = x * ec.exp(y / 10)
|
|
86
|
+
print(f) # 2.6997176151520064 ± 0.1453842429031768 [bias 0.014038531598790434]
|
|
87
|
+
print(f.gamma) # Γ[f], the error variance of f (not the variance of f)
|
|
88
|
+
print(dict(f.sharp)) # {'x': 0.13498588075760032, 'y': 0.05399435230304014}
|
|
89
|
+
print(ec.contributions(f)) # Γ[f] split by input
|
|
90
|
+
print(f.summary(scale=1.0)) # ... (bias assumed zero for: y)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
In a first-order model, asking for a bias raises `FirstOrderError` instead of returning 0 or `None`: Gauss's calculus
|
|
94
|
+
excludes biases by construction, and the library says so.
|
|
95
|
+
|
|
96
|
+
## What is in 0.1.0
|
|
97
|
+
|
|
98
|
+
- `Model`, `Quantity`, `QuantityArray`: independent and correlated inputs (Cholesky, or a spectral factorisation for
|
|
99
|
+
singular covariances), NumPy arrays of quantities, 23 elementary functions with their domain rules, linear algebra
|
|
100
|
+
(`errorcalculus.linalg.solve`, `inv`, `det`);
|
|
101
|
+
- user functions: `wrap` (with given or numerical derivatives, checked by step halving) and `sensitivities` (exact
|
|
102
|
+
gradient and Hessian);
|
|
103
|
+
- readings: `gamma`, `covariance_matrix`, `correlation_matrix`, `contributions` (of the error variance, and of the
|
|
104
|
+
bias by source), `summary(scale=s)` with s = ε² (Bouleau's gauge);
|
|
105
|
+
- `BiasOperator`: the bias operator L as an operator on functions, the identity Γ(φ, ψ) = L(φψ) − φL(ψ) − ψL(φ), and
|
|
106
|
+
its transport by a diffeomorphism;
|
|
107
|
+
- `compare_methods`: the same model computed by several methods (error calculus, first order, sensitivities, sigma
|
|
108
|
+
points, Monte Carlo, second-order Taylor moments), side by side.
|
|
109
|
+
|
|
110
|
+
Every guarantee is tested; the register of the 24 guarantees, each with its test file, is
|
|
111
|
+
[docs/GUARANTEES.md](https://github.com/HubHubHubHubHub/errorcalculus/blob/main/docs/GUARANTEES.md).
|
|
112
|
+
|
|
113
|
+
## Relation to other libraries
|
|
114
|
+
|
|
115
|
+
The propagation engine is the forward recursion of value, gradient and Laplacian known as the *Forward Laplacian*
|
|
116
|
+
(R. Li et al., 2023, arXiv:2307.08214), here applied to error variances and biases; it is cited, not claimed. The
|
|
117
|
+
first-order part covers what `uncertainties` and GTC compute, and the second-order moments are those of soerp and of
|
|
118
|
+
R `propagate`. The test suite checks parity with `uncertainties`, GTC, soerp and folx (guarantee G15).
|
|
119
|
+
|
|
120
|
+
## Documentation
|
|
121
|
+
|
|
122
|
+
<https://errorcalculus.readthedocs.io>
|
|
123
|
+
|
|
124
|
+
## Contributing, support
|
|
125
|
+
|
|
126
|
+
See [CONTRIBUTING.md](https://github.com/HubHubHubHubHub/errorcalculus/blob/main/CONTRIBUTING.md). Questions and reports: <https://github.com/HubHubHubHubHub/errorcalculus/issues>.
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
BSD-3-Clause ([LICENSE](https://github.com/HubHubHubHubHub/errorcalculus/blob/main/LICENSE)).
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# errorcalculus
|
|
2
|
+
|
|
3
|
+
**Bouleau's error calculus for Python.** errorcalculus propagates the *error variance* Γ (the quadratic error) and,
|
|
4
|
+
at second order, the *bias* A of quantities through a computation, exactly in the sense of the chain rule, at the
|
|
5
|
+
nominal values. It follows the error calculus of N. Bouleau (*Error Calculus for Finance and Physics: The Language of
|
|
6
|
+
Dirichlet Forms*, de Gruyter, 2003), in which Γ and A are two operators with their own calculus: a C² function F of
|
|
7
|
+
quantities x₁, …, xₙ satisfies
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
F♯ = Σᵢ ∂ᵢF · xᵢ♯ (the "sharp": a linear error)
|
|
11
|
+
Γ[F] = Σᵢⱼ ∂ᵢF ∂ⱼF Γ[xᵢ, xⱼ]
|
|
12
|
+
A[F] = Σᵢ ∂ᵢF A[xᵢ] + ½ Σᵢⱼ ∂ᵢⱼF Γ[xᵢ, xⱼ]
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
> **Status: 0.1.0, alpha.** This is the first layer of the library (finite dimension). The API of the 0.x series is
|
|
16
|
+
> not stable: names and signatures may still change, and every change is listed in the [changelog](https://github.com/HubHubHubHubHub/errorcalculus/blob/main/CHANGELOG.md).
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
python -m pip install errorcalculus
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Python 3.10 or later; NumPy is the only dependency (SciPy is used when present, for vectorised `erf`/`erfc`).
|
|
25
|
+
|
|
26
|
+
## A first computation
|
|
27
|
+
|
|
28
|
+
The order of the calculus is explicit: `order=1` propagates error variances only (Gauss); `order=2` propagates error
|
|
29
|
+
variances and biases.
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import errorcalculus as ec
|
|
33
|
+
|
|
34
|
+
m = ec.Model(order=2)
|
|
35
|
+
x = m.input(2.0, std=0.1, bias=0.01, name="x")
|
|
36
|
+
y = m.input(3.0, std=0.2, name="y") # no bias declared: assumed zero, and reported
|
|
37
|
+
|
|
38
|
+
f = x * ec.exp(y / 10)
|
|
39
|
+
print(f) # 2.6997176151520064 ± 0.1453842429031768 [bias 0.014038531598790434]
|
|
40
|
+
print(f.gamma) # Γ[f], the error variance of f (not the variance of f)
|
|
41
|
+
print(dict(f.sharp)) # {'x': 0.13498588075760032, 'y': 0.05399435230304014}
|
|
42
|
+
print(ec.contributions(f)) # Γ[f] split by input
|
|
43
|
+
print(f.summary(scale=1.0)) # ... (bias assumed zero for: y)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
In a first-order model, asking for a bias raises `FirstOrderError` instead of returning 0 or `None`: Gauss's calculus
|
|
47
|
+
excludes biases by construction, and the library says so.
|
|
48
|
+
|
|
49
|
+
## What is in 0.1.0
|
|
50
|
+
|
|
51
|
+
- `Model`, `Quantity`, `QuantityArray`: independent and correlated inputs (Cholesky, or a spectral factorisation for
|
|
52
|
+
singular covariances), NumPy arrays of quantities, 23 elementary functions with their domain rules, linear algebra
|
|
53
|
+
(`errorcalculus.linalg.solve`, `inv`, `det`);
|
|
54
|
+
- user functions: `wrap` (with given or numerical derivatives, checked by step halving) and `sensitivities` (exact
|
|
55
|
+
gradient and Hessian);
|
|
56
|
+
- readings: `gamma`, `covariance_matrix`, `correlation_matrix`, `contributions` (of the error variance, and of the
|
|
57
|
+
bias by source), `summary(scale=s)` with s = ε² (Bouleau's gauge);
|
|
58
|
+
- `BiasOperator`: the bias operator L as an operator on functions, the identity Γ(φ, ψ) = L(φψ) − φL(ψ) − ψL(φ), and
|
|
59
|
+
its transport by a diffeomorphism;
|
|
60
|
+
- `compare_methods`: the same model computed by several methods (error calculus, first order, sensitivities, sigma
|
|
61
|
+
points, Monte Carlo, second-order Taylor moments), side by side.
|
|
62
|
+
|
|
63
|
+
Every guarantee is tested; the register of the 24 guarantees, each with its test file, is
|
|
64
|
+
[docs/GUARANTEES.md](https://github.com/HubHubHubHubHub/errorcalculus/blob/main/docs/GUARANTEES.md).
|
|
65
|
+
|
|
66
|
+
## Relation to other libraries
|
|
67
|
+
|
|
68
|
+
The propagation engine is the forward recursion of value, gradient and Laplacian known as the *Forward Laplacian*
|
|
69
|
+
(R. Li et al., 2023, arXiv:2307.08214), here applied to error variances and biases; it is cited, not claimed. The
|
|
70
|
+
first-order part covers what `uncertainties` and GTC compute, and the second-order moments are those of soerp and of
|
|
71
|
+
R `propagate`. The test suite checks parity with `uncertainties`, GTC, soerp and folx (guarantee G15).
|
|
72
|
+
|
|
73
|
+
## Documentation
|
|
74
|
+
|
|
75
|
+
<https://errorcalculus.readthedocs.io>
|
|
76
|
+
|
|
77
|
+
## Contributing, support
|
|
78
|
+
|
|
79
|
+
See [CONTRIBUTING.md](https://github.com/HubHubHubHubHub/errorcalculus/blob/main/CONTRIBUTING.md). Questions and reports: <https://github.com/HubHubHubHubHub/errorcalculus/issues>.
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
BSD-3-Clause ([LICENSE](https://github.com/HubHubHubHubHub/errorcalculus/blob/main/LICENSE)).
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Guarantees
|
|
2
|
+
|
|
3
|
+
A guarantee is a property of the code that a named test file checks, against an oracle that does not use the code
|
|
4
|
+
under test wherever that is possible (symbolic derivatives with sympy, extended precision with mpmath, closed forms,
|
|
5
|
+
other libraries). The register below is the contract of version 0.1.0: a change that weakens a guarantee changes this
|
|
6
|
+
page and the changelog in the same pull request.
|
|
7
|
+
|
|
8
|
+
**Tolerances.** "Relative to the scale of the terms" means that the gap is divided by the sum of the absolute values of
|
|
9
|
+
the terms of the formula being checked (for A[F] = ∇F·b + ½ tr(∇²F C), the sum of the absolute values of the products
|
|
10
|
+
that make it up), not by the result itself, which may be small by cancellation.
|
|
11
|
+
|
|
12
|
+
**Notation.** x: nominal values of the inputs; L: their sharps (one row per input, one column per error source), so
|
|
13
|
+
that C = L Lᵀ is the matrix of Γ[xᵢ, xⱼ]; b: the input biases; F: a C² function; s = ε²: the scale.
|
|
14
|
+
|
|
15
|
+
| # | Guarantee | Oracle | Tolerance | Test file |
|
|
16
|
+
|---|---|---|---|---|
|
|
17
|
+
| G1 | The sharp follows the global rule: q♯ = ∇F(x)ᵀ L, for any composition of supported operations | 200 random compositions (depth 3 to 6, correlated inputs) against symbolic derivatives (sympy, 40 digits) | 1e-12, scale of the terms (with a floor of 1e-15 of the total scale) | `tests/test_g01_g02_global_rules.py` |
|
|
18
|
+
| G2 | The bias follows the global rule: A[F] = ∇F·b + ½ tr(∇²F C), whatever the way F is written | the same compositions, non-zero input biases | 1e-12, scale of the terms | `tests/test_g01_g02_global_rules.py` |
|
|
19
|
+
| G3 | Γ is exactly symmetric and Γ[F] exactly non-negative; `covariance_matrix` and `QuantityArray.cov()` are symmetric (explicitly symmetrised) and positive semidefinite | property-based tests (hypothesis) | exact; eigenvalues ≥ −1e-12 · trace | `tests/test_g03_gamma_symmetric_positive.py` |
|
|
20
|
+
| G4 | Γ by the bias: `gamma_via_bias(f, g) == gamma(f, g)` | random compositions | 1e-12, scale of A[fg], f A[g], g A[f] and Γ[f, g] | `tests/test_g04_gamma_via_bias.py` |
|
|
21
|
+
| G5 | Transport of the bias operator: θ_{v∘u}(L) = θ_v(θ_u(L)) and θ_{u⁻¹}(θ_u(L)) = L; for a linear u(x) = Mx, drift′ = M·drift and diffusion′ = M D Mᵀ | closed form (linear u); polar coordinates on the plane minus a cut (θ in ]−3, 3[); polar then coordinatewise exponential | 1e-10 | `tests/test_g05_transport.py` |
|
|
22
|
+
| G6 | "The identity that amplifies errors": with V₁, V₂ independent of unit error, U₁ = V₁, U₂ = V₁ + V₂, the quantity U₂ − U₁ has error exactly 1 (a rule σ_F = Σ\|∂ᵢF\|σᵢ applied along the chain would give 3), and the bias operator transported there and back is unchanged | exact values | exact; 1e-15 | `tests/test_g06_identity_does_not_amplify.py` |
|
|
23
|
+
| G7 | Order 1 and order 2 give the same value and the same sharp, bit for bit (scalars, arrays, linear algebra, `wrap`) | the two orders on the same compositions | bit for bit | `tests/test_g07_orders_bitwise.py` |
|
|
24
|
+
| G8 | At order 1, `bias`, `contributions(kind="bias")`, `input(bias=...)`, `gamma_via_bias`, `BiasOperator.from_inputs`, and the model options `require_bias` and `bias_breakdown` raise `FirstOrderError` | direct tests | — | `tests/test_g08_first_order_refusals.py` |
|
|
25
|
+
| G9 | Correlated inputs: `covariance_matrix(inputs)` returns the declared covariance; singular covariances are accepted (spectral factorisation of the correlation matrix), their rank determined by the eigenvalues, whatever the Cholesky pivots (the same on every BLAS library); the split of Γ by group equals ∇Fᵀ C_g ∇F, hence does not depend on the factorisation; inputs of very different scales keep their errors | random covariances of full and deficient rank, mixed scales | 1e-14 · n · max\|C\|; 1e-12 | `tests/test_g09_correlated.py`, `tests/test_regressions.py` |
|
|
26
|
+
| G10 | Contributions: their sum is Γ[q]; with `bias_breakdown=True`, the bias contributions sum to A[q]; by group, the variance part is ∇Fᵀ C_g ∇F and the curvature part ½ tr(∇²F C_g) | random compositions; symbolic oracle by group | 1e-14; 1e-12 | `tests/test_g10_contributions.py` |
|
|
27
|
+
| G11 | `assumed_zero_bias` lists exactly the groups without a declared bias on which the quantity depends (a structural dependency; an input with `std=0` and no bias is an exact constant, without a group); `require_bias=True` raises `MissingBiasError` | constructed cases (inputs, propagation, arrays, linear algebra) | exact | `tests/test_g11_assumed_zero_bias.py` |
|
|
28
|
+
| G12 | Sigma points: \| − A\| and \|Γ̂ − Γ\| decrease as O(s) (fitted slope in [0.9, 1.1] over s = 1e-2 … 1e-5); for a quadratic F,  − A = ½ s bᵀHb and Γ̂ − Γ = 2s ∇FᵀCHb + s² bᵀHCHb, so both are exact when b = 0 | five reference cases (random compositions); quadratic polynomials with b = 0 and b ≠ 0 against these closed forms | slope; 1e-12, relative to \|F\|/s for  and F²/s for Γ̂ (the scale of the differences of F) | `tests/test_g12_sigma_points.py` |
|
|
29
|
+
| G13 | Monte Carlo: Γ̂ and  lie within 4 standard errors of Γ and A at s = 1e-4, with a fixed seed; the standard errors are calibrated from `n_samples = 400`; an asymmetric user-supplied law is sampled as given (not symmetrised) | five reference cases, 10⁶ samples; standard deviation of z-scores over 400 seeds; an exponential law | 4 standard errors | `tests/test_g13_monte_carlo.py` |
|
|
30
|
+
| G14 | `taylor2_variance` returns the exact mean and variance of the quadratic Taylor polynomial of F under normal inputs | moments of the polynomial computed symbolically (sympy, exact rationals, E[zᵐ] = (m − 1)!!); Monte Carlo on the polynomial itself | 1e-10 | `tests/test_g14_taylor2.py` |
|
|
31
|
+
| G15 | Parity with other libraries: `uncertainties` (value, standard deviation, covariance matrix, error components), GTC (value, standard uncertainty, signed components, correlated inputs; `mul2(estimated=False)` = `taylor2_variance` of x·y), soerp (mean and second-order variance), folx (Γ and A from the Jacobian and the Laplacian); and the second-order mean correction ½ Σ f_ij u(xᵢ, xⱼ) in closed form | the libraries themselves (folx in float64) and sympy | 1e-12 (soerp variance: 1e-10; closed form: 1e-14) | `tests/parity/test_g15_parity.py` (marker `parity`) |
|
|
32
|
+
| G16 | `QuantityArray` (dense storage) agrees with `Quantity` element by element (sparse storage) | random arrays, ufuncs, broadcasting, `matmul`, shape operations | 1e-14, scale of the component | `tests/test_g16_array_vs_scalar.py` |
|
|
33
|
+
| G17 | Domain: outside the domain → `DomainError`; at a point where the function is not C² or has an infinite derivative, with a non-empty sharp → `NonDifferentiableError`; overflow → `NonFiniteError`, in propagation and in the readings (Γ, `covariance_matrix`, `QuantityArray.cov()`, `contributions`, `summary`); never a nan or an inf returned in silence, except the nan that `correlation_matrix` returns, by definition, for a quantity without error; the same domain refusals (`DomainError`, `NonDifferentiableError`) at both orders, and at order 2 a bias alone cannot be carried through a singular point (`NonFiniteError`) | the functions at the edges of their domains, both orders; extreme arguments | — | `tests/test_g17_domain.py`, `tests/test_regressions.py` |
|
|
34
|
+
| G18 | Linear algebra: `solve`, `inv`, `det` follow the global rule; a matrix with a zero row or column, or with a scaled condition number κ_s = ρ(\|a⁻¹\|\|a\|) above 1/(100 ε), is refused with `DomainError`; results and refusals do not depend on the units of rows and columns; exactly invertible but badly scaled matrices are accepted and exact | 2×2 and 3×3 against sympy; 4×4 and 5×5 against a Gaussian elimination written with scalar quantities; mpmath at 50 digits; diag(1e9, 1e-9); [[1, 1e20], [1, 1]]; random diagonal scalings of dense and sparse matrices; a column of subnormal entries next to a zero | 1e-10 (1e-12 against mpmath) | `tests/test_g18_linalg.py` |
|
|
35
|
+
| G19 | `wrap` without derivatives, homogeneous scales: gradient within 1e-7 and Hessian within 1e-4 of the exact values (largest entry), off-diagonal terms included; the step-halving check warns on heterogeneous scales (√(x² + y² + z²) at (1, 2, 200)) and does not raise false alarms at stationary points | test functions; the heterogeneous case | 1e-7; 1e-4 | `tests/test_g19_wrap.py`, `tests/test_regressions.py` |
|
|
36
|
+
| G20 | `sensitivities` returns the gradient and the Hessian exactly, term by term (each entry up to the rounding of its own terms, with no subtraction between diagonal terms): a coupling of 1e-3 between variables of curvature 5e10 is returned to 1e-12 | sympy, on random compositions and constructed cases; through arrays, `matmul`, `linalg.solve`, `linalg.inv`, `linalg.det` and `wrap` | 1e-12 of each entry, with a floor of 1e-13 of the largest entry (through those operations: 1e-12 of the largest entry) | `tests/test_g20_sensitivities.py` |
|
|
37
|
+
| G21 | Any operation between quantities of two models raises `ModelMismatchError`; `==` returns `False` | direct tests | — | `tests/test_g21_g22_models.py`, `tests/test_regressions.py` |
|
|
38
|
+
| G22 | A model and its quantities, pickled together, reload with the same values, sharps and biases (bit for bit) and remain combinable | pickle round trip | bit for bit | `tests/test_g21_g22_models.py` |
|
|
39
|
+
| G23 | `BiasOperator.from_inputs(xs).apply(φ, at=values) == φ(*xs).bias`, and `.gamma(φ, ψ, at=values) == gamma(φ(*xs), ψ(*xs))` | random compositions | 1e-12 | `tests/test_g23_g24_operator_scale.py` |
|
|
40
|
+
| G24 | Scale: `summary(scale=s)` has variance s·Γ, bias s·A and standard deviation √(s·Γ) | random s | 1e-15 | `tests/test_g23_g24_operator_scale.py` |
|
|
41
|
+
|
|
42
|
+
The API itself (the public names, the exception hierarchy) is checked by `tests/test_api_names.py`, and the contract
|
|
43
|
+
of `compare_methods` (arguments, refusals, first order, inputs without error, results) by `tests/test_compare_api.py`.
|
|
44
|
+
|
|
45
|
+
## What is not guaranteed
|
|
46
|
+
|
|
47
|
+
- **Rounded intermediates.** Like any automatic differentiation, the engine is exact with respect to the rounded
|
|
48
|
+
intermediate results: an ill-conditioned intermediate (log(1 + u²) for a small u) passes its relative error to the
|
|
49
|
+
sharp and the bias downstream. Use `log1p`, `expm1` and `hypot` where they apply.
|
|
50
|
+
- **Near the singularity threshold** of `linalg`, κ_s is computed in floating point, and the decision may differ from
|
|
51
|
+
one BLAS library to another. Below the threshold, each component of a result loses accuracy as any linear solve
|
|
52
|
+
does: typically of order n ε (\|a⁻¹\|\|a\|\|x\|)ᵢ; the componentwise bound of an LU factorisation with partial
|
|
53
|
+
pivoting holds with \|L\|\|U\| in place of \|a\|, which can be larger (growth factor).
|
|
54
|
+
- **Numerical derivatives** of `wrap` are checked by step halving, not proved: the check catches badly chosen steps
|
|
55
|
+
and kinks, and can miss other errors.
|
|
56
|
+
- **Performance** is measured, not guaranteed: the cost of an elementary operation grows linearly with the number of
|
|
57
|
+
error sources it carries.
|
|
58
|
+
- R `propagate` is not part of the parity tests (G15).
|
|
59
|
+
- Some oracles take a derivative from the library itself: the reduction of `taylor2_variance` to the formula of soerp
|
|
60
|
+
(G14) and the ∇F·b term of the comparison with folx (G15) use `sensitivities`, itself checked independently (G20).
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# API reference
|
|
2
|
+
|
|
3
|
+
All names below are exported at the root of the package (`import errorcalculus as ec`), except those of
|
|
4
|
+
`errorcalculus.linalg` and the functions `sigma_points`, `monte_carlo` and `taylor2_variance` of
|
|
5
|
+
`errorcalculus.compare`.
|
|
6
|
+
|
|
7
|
+
## Models and quantities
|
|
8
|
+
|
|
9
|
+
```{eval-rst}
|
|
10
|
+
.. autoclass:: errorcalculus.Model
|
|
11
|
+
|
|
12
|
+
.. autoclass:: errorcalculus.Quantity
|
|
13
|
+
|
|
14
|
+
.. autoclass:: errorcalculus.QuantityArray
|
|
15
|
+
|
|
16
|
+
.. autoclass:: errorcalculus.ErrorSummary
|
|
17
|
+
:no-members:
|
|
18
|
+
|
|
19
|
+
.. autofunction:: errorcalculus.array
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Readings
|
|
23
|
+
|
|
24
|
+
```{eval-rst}
|
|
25
|
+
.. autofunction:: errorcalculus.gamma
|
|
26
|
+
.. autofunction:: errorcalculus.gamma_via_bias
|
|
27
|
+
.. autofunction:: errorcalculus.covariance_matrix
|
|
28
|
+
.. autofunction:: errorcalculus.correlation_matrix
|
|
29
|
+
.. autofunction:: errorcalculus.contributions
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Elementary functions
|
|
33
|
+
|
|
34
|
+
`exp`, `expm1`, `log`, `log1p`, `log2`, `log10`, `sqrt`, `sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `atan2`,
|
|
35
|
+
`sinh`, `cosh`, `tanh`, `asinh`, `acosh`, `atanh`, `hypot`, `erf`, `erfc`. Each accepts a number, a NumPy array, a
|
|
36
|
+
`Quantity` or a `QuantityArray`; on numbers and arrays it returns the ordinary NumPy result. The corresponding NumPy
|
|
37
|
+
ufuncs (`np.exp`, …, `np.arctan2`, `np.hypot`, and the arithmetic ufuncs) are routed to the same rules.
|
|
38
|
+
|
|
39
|
+
```{eval-rst}
|
|
40
|
+
.. autofunction:: errorcalculus.exp
|
|
41
|
+
.. autofunction:: errorcalculus.atan2
|
|
42
|
+
.. autofunction:: errorcalculus.hypot
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## User functions
|
|
46
|
+
|
|
47
|
+
```{eval-rst}
|
|
48
|
+
.. autofunction:: errorcalculus.wrap
|
|
49
|
+
.. autofunction:: errorcalculus.sensitivities
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Linear algebra
|
|
53
|
+
|
|
54
|
+
```{eval-rst}
|
|
55
|
+
.. automodule:: errorcalculus.linalg
|
|
56
|
+
:members: solve, inv, det
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## The bias operator
|
|
60
|
+
|
|
61
|
+
```{eval-rst}
|
|
62
|
+
.. autoclass:: errorcalculus.BiasOperator
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Comparing methods
|
|
66
|
+
|
|
67
|
+
```{eval-rst}
|
|
68
|
+
.. autofunction:: errorcalculus.compare_methods
|
|
69
|
+
|
|
70
|
+
.. autoclass:: errorcalculus.Comparison
|
|
71
|
+
|
|
72
|
+
.. autoclass:: errorcalculus.MethodResult
|
|
73
|
+
:no-members:
|
|
74
|
+
|
|
75
|
+
.. autofunction:: errorcalculus.compare.sigma_points
|
|
76
|
+
.. autofunction:: errorcalculus.compare.monte_carlo
|
|
77
|
+
.. autofunction:: errorcalculus.compare.taylor2_variance
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Exceptions and warnings
|
|
81
|
+
|
|
82
|
+
```{eval-rst}
|
|
83
|
+
.. automodule:: errorcalculus.errors
|
|
84
|
+
:members:
|
|
85
|
+
```
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Comparing methods
|
|
2
|
+
|
|
3
|
+
{func}`~errorcalculus.compare_methods` computes the same function of the same inputs with several methods, so that the
|
|
4
|
+
error calculus can be set against the methods it is usually compared with. The finite-scale methods perturb the inputs
|
|
5
|
+
as x̃ = x + s·b + √s·L z, where x are the nominal values, b the input biases, L the sharps of the inputs, s = ε² the
|
|
6
|
+
scale and z a vector of independent, centred, reduced components.
|
|
7
|
+
|
|
8
|
+
| Method | What it returns | Cost |
|
|
9
|
+
|---|---|---|
|
|
10
|
+
| `"calculus"` | Γ and A of the model (A at order 2) | one pass |
|
|
11
|
+
| `"gauss"` | Γ, in a first-order clone of the model | one pass |
|
|
12
|
+
| `"sensitivity"` | the gradient (`sensitivities`) | one pass |
|
|
13
|
+
| `"sigma_points"` | estimates of Γ and A at scale s, error O(s) | 2k + 1 evaluations |
|
|
14
|
+
| `"monte_carlo"` | mean and centred variance at scale s, with standard errors | 2⌊n_samples/2⌋ + 1 evaluations (the nominal point included) |
|
|
15
|
+
| `"taylor2"` | exact mean and variance of the quadratic Taylor polynomial under normal inputs | 1 + p(p+1)/2 passes |
|
|
16
|
+
|
|
17
|
+
Here k is the number of error sources and p the number of directions (k, or k + 1 when b ≠ 0).
|
|
18
|
+
|
|
19
|
+
## Sigma points
|
|
20
|
+
|
|
21
|
+
x_j^± = x + s·b ± √(ks)·L e_j, j = 1…k, and
|
|
22
|
+
|
|
23
|
+
 = mean_j[(F(x_j⁺) + F(x_j⁻))/2 − F(x)] / s, Γ̂ = mean_j[((F(x_j⁺) − F(x_j⁻))/2)²] / s.
|
|
24
|
+
|
|
25
|
+
For a quadratic F of Hessian H, Â − A = ½ s bᵀHb and Γ̂ − Γ = 2s ∇FᵀCHb + s² bᵀHCHb: the estimates are exact for a
|
|
26
|
+
quadratic F only when b = 0, and O(s) in general (guarantee G12). The method is a relative of the unscented transform
|
|
27
|
+
([Julier and Uhlmann 2004](references.md)), without a weight on the central point.
|
|
28
|
+
|
|
29
|
+
## Monte Carlo
|
|
30
|
+
|
|
31
|
+
The variance returned is the centred variance Var F(x̃), as in [JCGM 101](references.md) (7.6); it differs from
|
|
32
|
+
s·Γ by terms of order s² for the symmetric laws `"normal"` and `"uniform"`, and of order s^{3/2} for a law
|
|
33
|
+
with a non-zero third moment. For the laws `"normal"` and `"uniform"` (on [−√3, √3]) the samples are drawn in antithetic
|
|
34
|
+
pairs (z, −z); for a law supplied as a callable `(rng, shape) -> z`, they are drawn independently, so that an
|
|
35
|
+
asymmetric law keeps its odd moments. Standard errors are computed by batches; `n_samples` is at least 400.
|
|
36
|
+
|
|
37
|
+
## Second-order Taylor moments
|
|
38
|
+
|
|
39
|
+
`"taylor2"` returns the mean and variance of the quadratic Taylor polynomial of F under normal inputs,
|
|
40
|
+
|
|
41
|
+
variance = s Γ + s² [½ tr((HC)²) + 2 ∇FᵀCHb] + s³ bᵀHCHb, bias = s A + ½ s² bᵀHb.
|
|
42
|
+
|
|
43
|
+
With b = 0 this is the "second-order variance" s Γ + ½ s² tr((HC)²) computed by soerp and by R `propagate`. It is not
|
|
44
|
+
the s² term of the true variance, which also needs third derivatives ([GUM](references.md), 5.1.2, note). Laws other
|
|
45
|
+
than normal raise {class}`~errorcalculus.UnsupportedDistributionError` in 0.1.0.
|
|
46
|
+
|
|
47
|
+
## Readings
|
|
48
|
+
|
|
49
|
+
{class}`~errorcalculus.Comparison` holds one {class}`~errorcalculus.MethodResult` per method; `table()` prints them
|
|
50
|
+
and `discrepancy(reference="calculus")` gives the relative gaps on Γ and A.
|
|
51
|
+
|
|
52
|
+
## What the library encompasses
|
|
53
|
+
|
|
54
|
+
| Library | Compared (guarantee G15) |
|
|
55
|
+
|---|---|
|
|
56
|
+
| `uncertainties` | value, standard deviation, covariance matrix, error components |
|
|
57
|
+
| GTC | value, standard uncertainty, signed components, correlated inputs, `mul2(estimated=False)` |
|
|
58
|
+
| soerp | mean, second-order variance |
|
|
59
|
+
| folx | Γ and A, from the Jacobian and the Laplacian |
|
|
60
|
+
|
|
61
|
+
What these libraries do and errorcalculus 0.1.0 does not: formatting and parsing of strings (`uncertainties`);
|
|
62
|
+
degrees of freedom and complex quantities (GTC); skewness, kurtosis and non-normal inputs for the second-order
|
|
63
|
+
variance (soerp); coverage intervals and copulas (R `propagate`); the adaptive Monte Carlo procedure of JCGM 101.
|