Skip to main content

Linear and stochastic sensitivity analysis and uncertainty propagation

Project description

Tests

sensitivities

(L. Riegger, 2025)

Methods for linear and stochastic sensitivities analysis and uncertainty propagation, following the BIPM GUM (JCGM 102:2011).

Install

You can install the sensitivities module using pip:

pip install sensitivities

Usage

sensitivities.stochastic

The sensitivities.stochastic module provides functionality for stochastic sensitivity analysis. It allows you to stochastically sample input parameters from various, potentially correlated distributions and evaluate the sensitivities of a function to those inputs. Available distributions are

  • Gaussian (given mean and standard deviation)
  • Uniform (between lower and upper bound)
  • Discrete (multiple discrete options)

Example for stochastic sampling:

from sensitivities.stochastic import sample, Gaussian, Uniform, Discrete
import matplotlib.pyplot as plt

def my_function(a, b, c=0, d=0):
    return a + b + c + d


samples = sample(
    my_function,
    [
        Gaussian(10, 0.05),
        Discrete([1, 2]),
    ],
    {"c": Uniform(-0.4, 0.4), "d": -100},
    corr=[("a", "c", 0.5)],
    n=100000,
)

plt.hist(np.array(samples), 100)
plt.show()

sensitivities.linear

This module contains the propagate_uncertainties function for propagation of uncertainties for a given function based on the principle of linear differentials. It makes use of the scipy function approx_fprime to calculate the partial derivatives of the given function.

Here is a simple usage example:

from sensitivities.linear import propagate_uncertainties

def my_function(x, y):
    return [x ** 2, x, y]

print(propagate_uncertainties(my_function, uncertainties=[0.1, 0.2], x0=[1, 1]))

This will output the propagated standard uncertainties and correlation matrix between the function outputs:

(
    np.array([0.2, 0.1, 0.2]),
    np.array([[1.0, 1.0, 0.0], [1.0, 1.0, 0.0], [0.0, 0.0, 1.0]])
)

Development

Setup development environment

uv sync --extra dev

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

sensitivities-1.2.0.tar.gz (587.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sensitivities-1.2.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file sensitivities-1.2.0.tar.gz.

File metadata

  • Download URL: sensitivities-1.2.0.tar.gz
  • Upload date:
  • Size: 587.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.14

File hashes

Hashes for sensitivities-1.2.0.tar.gz
Algorithm Hash digest
SHA256 0145404b2fdd40cacb386fea0a327a4086d01f1f843b090c54c7745222442e56
MD5 8f57f19a61ffd68d0f8752b73b2b9f5f
BLAKE2b-256 7864d6f27e349e195c72981fa9ec6648e337775591b34567792e856701844f44

See more details on using hashes here.

File details

Details for the file sensitivities-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sensitivities-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d4a4ad3e9d4ad8679d8eebb50d23a5de222c44fb8a03ea2958aba5a718b45df
MD5 475d8242fb248e239c7b3da21daa83e0
BLAKE2b-256 fbfb7444b2735282ea00dfd61abd129605760e79aa08e11b25b26d27e743835d

See more details on using hashes here.

Supported by

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