Skip to main content

errorcalculus

Bouleau's error calculus for Python. errorcalculus propagates the error variance Γ (the quadratic error) and, at second order, the bias A of quantities through a computation, exactly in the sense of the chain rule, at the nominal values. It follows the error calculus of N. Bouleau (Error Calculus for Finance and Physics: The Language of Dirichlet Forms, de Gruyter, 2003), in which Γ and A are two operators with their own calculus: a C² function F of quantities x₁, …, xₙ satisfies

F♯   = Σᵢ ∂ᵢF · xᵢ♯                                    (the "sharp": a linear error)
Γ[F] = Σᵢⱼ ∂ᵢF ∂ⱼF Γ[xᵢ, xⱼ]
A[F] = Σᵢ ∂ᵢF A[xᵢ] + ½ Σᵢⱼ ∂ᵢⱼF Γ[xᵢ, xⱼ]

Status: 0.1.0, alpha. This is the first layer of the library (finite dimension). The API of the 0.x series is not stable: names and signatures may still change, and every change is listed in the changelog.

Install

python -m pip install errorcalculus

Python 3.10 or later; NumPy is the only dependency (SciPy is used when present, for vectorised erf/erfc).

A first computation

The order of the calculus is explicit: order=1 propagates error variances only (Gauss); order=2 propagates error variances and biases.

import errorcalculus as ec

m = ec.Model(order=2)
x = m.input(2.0, std=0.1, bias=0.01, name="x")
y = m.input(3.0, std=0.2, name="y")       # no bias declared: assumed zero, and reported

f = x * ec.exp(y / 10)
print(f)              # 2.6997176151520064 ± 0.1453842429031768 [bias 0.014038531598790434]
print(f.gamma)        # Γ[f], the error variance of f (not the variance of f)
print(dict(f.sharp))  # {'x': 0.13498588075760032, 'y': 0.05399435230304014}
print(ec.contributions(f))          # Γ[f] split by input
print(f.summary(scale=1.0))         # ... (bias assumed zero for: y)

In a first-order model, asking for a bias raises FirstOrderError instead of returning 0 or None: Gauss's calculus excludes biases by construction, and the library says so.

What is in 0.1.0

  • Model, Quantity, QuantityArray: independent and correlated inputs (Cholesky, or a spectral factorisation for singular covariances), NumPy arrays of quantities, 23 elementary functions with their domain rules, linear algebra (errorcalculus.linalg.solve, inv, det);
  • user functions: wrap (with given or numerical derivatives, checked by step halving) and sensitivities (exact gradient and Hessian);
  • readings: gamma, covariance_matrix, correlation_matrix, contributions (of the error variance, and of the bias by source), summary(scale=s) with s = ε² (Bouleau's gauge);
  • BiasOperator: the bias operator L as an operator on functions, the identity Γ(φ, ψ) = L(φψ) − φL(ψ) − ψL(φ), and its transport by a diffeomorphism;
  • compare_methods: the same model computed by several methods (error calculus, first order, sensitivities, sigma points, Monte Carlo, second-order Taylor moments), side by side.

Every guarantee is tested; the register of the 24 guarantees, each with its test file, is docs/GUARANTEES.md.

Relation to other libraries

The propagation engine is the forward recursion of value, gradient and Laplacian known as the Forward Laplacian (R. Li et al., 2023, arXiv:2307.08214), here applied to error variances and biases; it is cited, not claimed. The first-order part covers what uncertainties and GTC compute, and the second-order moments are those of soerp and of R propagate. The test suite checks parity with uncertainties, GTC, soerp and folx (guarantee G15).

Documentation

https://errorcalculus.readthedocs.io

Contributing, support

See CONTRIBUTING.md. Questions and reports: https://github.com/HubHubHubHubHub/errorcalculus/issues.

License

BSD-3-Clause (LICENSE).

Metadata

Release files for errorcalculus 0.1.0

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

Source distribution (sdist)

Source distribution for errorcalculus 0.1.0
File Size Uploaded Provenance Actions
errorcalculus-0.1.0.tar.gz 108.1 kB Without provenance Details for errorcalculus-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 166.4 kB

Release files / errorcalculus-0.1.0.tar.gz

Download URL errorcalculus-0.1.0.tar.gz
Size 108.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2c0b5acb6e2fce9d71d6cc51fdea7b8cca5043eb56f331b35fb023d777cde6ae
BLAKE2b-256 checksum
How to use checksums
d6300b21d141c2bcdff05d90aaf16acfcce3a4be56a6848d1f509ad5ac1a7840
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.2

Release files / errorcalculus-0.1.0-py3-none-any.whl

Download URL errorcalculus-0.1.0-py3-none-any.whl
Size 58.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
78a702600d142347d749cd6055ec4fc800755e10eb3962e7839f1c089a4d48fb
BLAKE2b-256 checksum
How to use checksums
b71c4569db5d53ceb4988746edd7d9df25374c404aada33d30c3a3d1673a76dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.2

Security for errorcalculus 0.1.0

Provenance

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

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

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

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

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