Skip to main content

Package that computes error propagation

Project description

Error Propagation

Every number should have an error, even if it's 0.

To do so, we have created a python package that makes it easy to propagate errors when performing calculations.

(10 ± 3) + (11 ± 4) != (21 ± 7) 

To calculate the error when adding 2 numbers, the L2 norm must be calculated

(10 ± 3) + (11 ± 4) != (21 ± (3 ** 2 + 4 ** 2) ** 0.5) == (21 ± 5)

Calculating the error when multiplying, dividing, exponentiation is significantly harder, but still important! Please checkout this notebook for derivations of error propagation formulas.

How to use

Create a Complex class instance:

Basic Functionality

from error_propagation import Complex
a = Complex(10, 3)
b = Complex(11, 4)

# Compute basic operations
a + b # 21.0 ± 5.0
a - b # -1.0 ± 5.0
a * b # 110.0 ± 51.85556864985669
a / b # 0.9090909090909091 ± 0.42855841859385696
a ** b # 100000000000.0 ± 978367874409.4901

# Compute basic equalities
a == b # False
a != b # True
a < b # True
a <= b # True
a > b # False
a >= b # False

Numpy and Pandas integration

from error_propagation import Complex, arrays_to_complex
import numpy as np 
import pandas as pd

a = np.array([Complex(3, 4), Complex(8, 3)])
b = np.array([Complex(2, 3), Complex(10, 4)])
a + b # array([5.0 ± 5.0, 18.0 ± 5.0], dtype=object)
a * b # array([6.0 ± 12.041594578792296, 80.0 ± 43.86342439892262], dtype=object)

df = pd.DataFrame({"values": [1, 2], "errors": [3, 4]})
df["complex_numbers"] = arrays_to_complex(values=df["values"], errors=df["errors"])

Financial functions

from error_propagation import Complex
from error_propagation.finance import npv
result = npv(
            cash=[Complex(10, 2), Complex(11, 3), Complex(12, 1)],
            discount_rate=Complex(0.05, 0.001),
        )

result # 29.867184969225782 ± 3.432196994041631

Leverage functions

from error_propagation import Complex
a = Complex(10, 3)
b = Complex(11, 4)

Complex.add(a, b) # 21.0 ± 5.0
Complex.sub(a, b) # -1.0 ± 5.0
Complex.mul(a, b) # 110.0 ± 51.85556864985669
Complex.truediv(a, b) # 0.9090909090909091 ± 0.42855841859385696
Complex.pow(a, b) # 100000000000.0 ± 978367874409.4901

To see more examples, go to docs/functionality.md and the testsfolder.

How to install

error-propagation is hosted on PyP

pip install error-propagation

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

error_propagation-0.0.4.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

error_propagation-0.0.4-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file error_propagation-0.0.4.tar.gz.

File metadata

  • Download URL: error_propagation-0.0.4.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.11

File hashes

Hashes for error_propagation-0.0.4.tar.gz
Algorithm Hash digest
SHA256 56f5cec287e0b35ba83b153049a23fa566106fa067c74a191d15cf19d51612a9
MD5 2df2f1d5b53fbe0752d6e35e193d2c42
BLAKE2b-256 77f205dd94f5c66a51713553fe954771c4e0fbc375911210610acf3c18cee512

See more details on using hashes here.

File details

Details for the file error_propagation-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: error_propagation-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.11

File hashes

Hashes for error_propagation-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3bfcd34fa813925bd632b8ef40810b5c02cdf59a59eded34ece18e6c757c180e
MD5 7ba10863c56b6c02910136421717b878
BLAKE2b-256 54259e333a3bf8ada04bee0a875b6bc106b9064c95159f69f30306765ea84330

See more details on using hashes here.

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