Skip to main content

A python & numpy data type for floating point numbers with quantified uncertainity.

Project description

Code CI Docs CI Test Coverage Latest PyPI version Apache License

This package provides a python and numpy data type (uncertain) which implements a floating point value with quantified uncertainity, allowing for forward uncertainity propagation of uncorrelated values.

PyPI

pip install numcertain

Source code

https://github.com/DiamondLightSource/numcertain

Documentation

https://DiamondLightSource.github.io/numcertain

Releases

https://github.com/DiamondLightSource/numcertain/releases

Aritmatic Examples

A brief example of arithmatic with the provided uncertain data type is presented below:

a = uncertain(42.0, 5.0)
b = uncertain(36, 12)

print(a + b)
print(a - b)
print(a * b)
print(a / b)
>> 78.0±13.0
>> 6.0±13.0
>> 1512.0±535.1784749034662
>> 1.1666666666666667±0.41294635409218067

A brief example of arithmatic with numpy arrays with the uncertain dtype is presented below:

a = array([uncertain(5.0, 3.0), uncertain(7.0, 6.0)])
b = array([uncertain(12.0, 4.0), uncertain(24.0, 8.0)])

print(a + b)
print(a - b)
print(a * b)
print(a / b)
>> [uncertain(17.0, 5.0) uncertain(31.0, 10.0)]
>> [uncertain(-7.0, 5.0) uncertain(-17.0, 10.0)]
>> [uncertain(60.0, 41.182520563948) uncertain(168.0, 154.50566332662373)]
>> [uncertain(0.4166666666666667, 0.2859897261385278) uncertain(0.2916666666666667, 0.268238998830944)]

Alternative Methods

In order to accurately propagate uncertainties of related values the derivative of the computed expectation must be known with respect to expectations it is comprised of. Automatic differentiation (autodiff) provides a mechanism for computing the derivative of arbitrary functions with respect to their components by exploiting the fact that all codes, regardless of complexity, are reduced to a sequence of primative arithmetic operations during execution for which the derivatives are known, by applying the chain rule the overall derivative can be determined automatically.

The python package Uncertainties provides a python data type which performs autodiff to propagate the corresponding uncertainity, unforunately due to Implementation as a python object the library is non-performant when used for array math.

Whilst Propagation of Uncertainty with autodiff, describes the use of autodiff provided by the python package JAX in propagating uncertainities for array math.

See https://DiamondLightSource.github.io/numcertain for more detailed documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

numcertain-0.3.0.tar.gz (48.2 kB view hashes)

Uploaded Source

Built Distributions

numcertain-0.3.0-cp311-cp311-win_amd64.whl (21.9 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

numcertain-0.3.0-cp311-cp311-win32.whl (21.0 kB view hashes)

Uploaded CPython 3.11 Windows x86

numcertain-0.3.0-cp311-cp311-musllinux_1_1_x86_64.whl (63.2 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

numcertain-0.3.0-cp311-cp311-musllinux_1_1_i686.whl (60.4 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

numcertain-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (55.6 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

numcertain-0.3.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (51.5 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

numcertain-0.3.0-cp311-cp311-macosx_10_9_x86_64.whl (20.3 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

numcertain-0.3.0-cp310-cp310-win_amd64.whl (21.9 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

numcertain-0.3.0-cp310-cp310-win32.whl (21.0 kB view hashes)

Uploaded CPython 3.10 Windows x86

numcertain-0.3.0-cp310-cp310-musllinux_1_1_x86_64.whl (62.5 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

numcertain-0.3.0-cp310-cp310-musllinux_1_1_i686.whl (59.6 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

numcertain-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (55.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

numcertain-0.3.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (50.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

numcertain-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl (20.3 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

numcertain-0.3.0-cp39-cp39-win_amd64.whl (21.9 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

numcertain-0.3.0-cp39-cp39-win32.whl (21.0 kB view hashes)

Uploaded CPython 3.9 Windows x86

numcertain-0.3.0-cp39-cp39-musllinux_1_1_x86_64.whl (62.0 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

numcertain-0.3.0-cp39-cp39-musllinux_1_1_i686.whl (58.9 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

numcertain-0.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (54.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

numcertain-0.3.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (50.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

numcertain-0.3.0-cp39-cp39-macosx_10_9_x86_64.whl (20.3 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page