Linear and stochastic sensitivity analysis and error propagation
Project description
sensitivities
Methods for linear and stochastic sensitivities analysis and error propagation.
Install
You can install the sensitivities
module using pip:
pip install sensitivities
Usage
sensitivities.stochastic
The sensitivities.stochastic
module provides functionality for stochastic sensitivities analysis. It allows you to stochastically sample input parameters from various 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, seed
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": -10},
n=100000,
)
plt.hist(samples, 100)
plt.show()
sensitivities.linear
This module contains the propagate_errors
function for linear propagation of errors for a given function based on the principle of differentials. It makes use of the scipy function approx_fprime
to calculate the partial derivatives of the given function. The propagated error is calculated by taking the square root of the sum of squares of the product of the partial derivatives and the uncertainties.
Here is a simple usage example:
from sensitivities.linear import propagate_errors
def my_function(x, y):
return [x ** 2, y]
print(propagate_errors(my_function, errors=[0.1, 0.2], x0=[1, 1]))
This will output:
np.array([0.2, 0.2])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sensitivities-1.0.1.tar.gz
.
File metadata
- Download URL: sensitivities-1.0.1.tar.gz
- Upload date:
- Size: 27.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac3c1b039f7a94cd93641548800ba51e610fe6505a68b04d70db0abce9fd5a57 |
|
MD5 | 8df9003918e88c8959927be4a0f050a0 |
|
BLAKE2b-256 | b45548cf424c0787b500778b8a824a9f5678b5536719e11c5a066e5bdc2f9986 |
File details
Details for the file sensitivities-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: sensitivities-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc6676a8be37b74f3863182d7da359865bef3a339fa8529d3cdc838065579f40 |
|
MD5 | a3868e0ec18c86e3a80916f4b888ad40 |
|
BLAKE2b-256 | 6140d2af05cbe608da002360268e29289e71b6fd83229e35cef9ad1d40d81dca |