Skip to main content

Numerical tool for perfroming uncertainty quantification

Project description

https://github.com/jonathf/chaospy/raw/master/docs/.static/chaospy_logo.svg

circleci codecov readthedocs downloads pypi

Chaospy is a numerical tool for performing uncertainty quantification using polynomial chaos expansions and advanced Monte Carlo methods implemented in Python.

Installation

Installation should be straight forward from PyPI:

$ pip install chaospy

Example Usage

chaospy is created to work well inside numerical Python ecosystem. You therefore typically need to import Numpy along side chaospy:

>>> import numpy
>>> import chaospy

chaospy is problem agnostic, so you can use your own code using any means you find fit. The only requirement is that the output is compatible with numpy.ndarray format:

>>> coordinates = numpy.linspace(0, 10, 100)
>>> def forward_solver(coordinates, parameters):
...     """Function to do uncertainty quantification on."""
...     param_init, param_rate = parameters
...     return param_init*numpy.e**(-param_rate*coordinates)

We here assume that parameters contains aleatory variability with known probability. We formalize this probability in chaospy as a joint probability distribution. For example:

>>> distribution = chaospy.J(
...     chaospy.Uniform(1, 2), chaospy.Normal(0, 2))
>>> print(distribution)
J(Uniform(lower=1, upper=2), Normal(mu=0, sigma=2))

Most probability distributions have an associated expansion of orthogonal polynomials. These can be automatically constructed:

>>> expansion = chaospy.generate_expansion(8, distribution)
>>> print(expansion[:5].round(8))
[1.0 q1 q0-1.5 q0*q1-1.5*q1 q0**2-3.0*q0+2.16666667]

Here the polynomial is defined positional, such that q0 and q1 refers to the uniform and normal distribution respectively.

The distribution can also be used to create (pseudo-)random samples and low-discrepancy sequences. For example to create Sobol sequence samples:

>>> samples = distribution.sample(1000, rule="sobol")
>>> print(samples[:, :4].round(8))
[[ 1.5         1.75        1.25        1.375     ]
 [ 0.         -1.3489795   1.3489795  -0.63727873]]

We can evaluating the forward solver using these samples:

>>> evaluations = numpy.array([
...     forward_solver(coordinates, sample) for sample in samples.T])
>>> print(evaluations[:3, :5].round(8))
[[1.5        1.5        1.5        1.5        1.5       ]
 [1.75       2.00546578 2.29822457 2.63372042 3.0181921 ]
 [1.25       1.09076905 0.95182169 0.83057411 0.72477163]]

Having all these components in place, we have enough components to perform point collocation. Or in other words, we can create a polynomial approximation of forward_solver:

>>> approx_solver = chaospy.fit_regression(
...     expansion, samples, evaluations)
>>> print(approx_solver[:2].round(4))
[q0 -0.0002*q0*q1**3+0.0051*q0*q1**2-0.101*q0*q1+q0]

Since the model approximations are polynomials, we can do inference on them directly. For example:

>>> expected = chaospy.E(approx_solver, distribution)
>>> print(expected[:5].round(8))
[1.5        1.53092356 1.62757217 1.80240142 2.07915608]
>>> deviation = chaospy.Std(approx_solver, distribution)
>>> print(deviation[:5].round(8))
[0.28867513 0.43364958 0.76501802 1.27106355 2.07110879]

For more extensive guides on this approach an others, see the tutorial collection.

Questions and Contributions

Please feel free to file an issue for:

  • bug reporting

  • asking questions related to usage

  • requesting new features

  • wanting to contribute with code

If you are using this software in work that will be published, please cite the journal article: Chaospy: An open source tool for designing methods of uncertainty quantification.

And if you use code to deal with stochastic dependencies, please also cite Multivariate Polynomial Chaos Expansions with Dependent Variables.

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

chaospy-4.1.1.tar.gz (146.5 kB view details)

Uploaded Source

Built Distribution

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

chaospy-4.1.1-py2.py3-none-any.whl (233.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file chaospy-4.1.1.tar.gz.

File metadata

  • Download URL: chaospy-4.1.1.tar.gz
  • Upload date:
  • Size: 146.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.9 CPython/3.8.3 Linux/4.15.0-1077-aws

File hashes

Hashes for chaospy-4.1.1.tar.gz
Algorithm Hash digest
SHA256 10749e4696d137bbf479d529f6612ea2b660fa6ddfa9e52954a54e77c26148ed
MD5 28da3919d17905db988b382d3971063a
BLAKE2b-256 03a2f5110dfb8e5517bd0357e643061ef1896b0d94d9a080fef84e1adf8adc65

See more details on using hashes here.

File details

Details for the file chaospy-4.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: chaospy-4.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 233.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.9 CPython/3.8.3 Linux/4.15.0-1077-aws

File hashes

Hashes for chaospy-4.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 712f4a6abe0656bf4f03ac20d045f9aa16cb5f0e88bee9e2c4bc79b1436a083a
MD5 f591535b36000677ca61aae590852d01
BLAKE2b-256 e82b40c05be4c4c0e381b12f8cb44cc5776aacc916e48c6a825786a79c5ae927

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