|
18 | 18 | .. |binder| image:: https://mybinder.org/badge_logo.svg |
19 | 19 | :target: https://mybinder.org/v2/gh/jonathf/chaospy/master?filepath=docs%2Ftutorials |
20 | 20 |
|
21 | | -Chaospy is a numerical tool for performing uncertainty quantification using |
22 | | -polynomial chaos expansions and advanced Monte Carlo methods implemented in |
23 | | -Python. |
24 | | - |
25 | 21 | * `Documentation <https://chaospy.readthedocs.io/en/master>`_ |
26 | 22 | * `Interactive tutorials with Binder <https://mybinder.org/v2/gh/jonathf/chaospy/master?filepath=docs%2Ftutorials>`_ |
27 | | -* `Source code <https://github.com/jonathf/chaospy>`_ |
28 | | -* `Issue tracker <https://github.com/jonathf/chaospy/issues>`_ |
29 | | -* `Code of Conduct <https://github.com/jonathf/chaospy/blob/master/CODE_OF_CONDUCT.md>`_ |
30 | | -* `Contribution Guideline <https://github.com/jonathf/chaospy/blob/master/CONTRIBUTING.md>`_ |
31 | | -* `Changelog <https://github.com/jonathf/chaospy/blob/master/CHANGELOg.md>`_ |
| 23 | +* `Code of conduct <https://github.com/jonathf/chaospy/blob/master/CODE_OF_CONDUCT.md>`_ |
| 24 | +* `Contribution guideline <https://github.com/jonathf/chaospy/blob/master/CONTRIBUTING.md>`_ |
| 25 | +* `Changelog <https://github.com/jonathf/chaospy/blob/master/CHANGELOG.md>`_ |
| 26 | +* `License <https://github.com/jonathf/chaospy/blob/master/LICENCE.txt>`_ |
| 27 | + |
| 28 | +Chaospy is a numerical toolbox for performing uncertainty quantification using |
| 29 | +polynomial chaos expansions, advanced Monte Carlo methods implemented in |
| 30 | +Python. It also include a full suite of tools for doing low-discrepancy |
| 31 | +sampling, quadrature creation, polynomial manipulations, and a lot more. |
| 32 | + |
| 33 | +The philosophy behind ``chaospy`` is not to be a single tool that solves every |
| 34 | +uncertainty quantification problem, but instead be a specific tools to aid to |
| 35 | +let the user solve problems themselves. This includes both well established |
| 36 | +problems, but also to be a foundry for experimenting with new problems, that |
| 37 | +are not so well established. To do this, emphasis is put on the following: |
| 38 | + |
| 39 | +* Focus on an easy to use interface that embraces the `pythonic code style |
| 40 | + <https://docs.python-guide.org/writing/style/>`_. |
| 41 | +* Make sure the code is "composable", such a way that changing one part of the |
| 42 | + code with something user defined should be easy and encouraged. |
| 43 | +* Try to support a broad width of the various methods for doing uncertainty |
| 44 | + quantification where that makes sense to involve ``chaospy``. |
| 45 | +* Make sure that ``chaospy`` plays nice with a large set of of other other |
| 46 | + similar projects. This includes `numpy <https://numpy.org/>`_, `scipy |
| 47 | + <https://scipy.org/>`_, `scikit-learn <https://scikit-learn.org>`_, |
| 48 | + `statsmodels <https://statsmodels.org/>`_, `openturns |
| 49 | + <https://openturns.org/>`_, and `gstools <https://geostat-framework.org/>`_ |
| 50 | + to mention a few. |
| 51 | +* Contribute all code to the community open source. |
32 | 52 |
|
33 | 53 | Installation |
34 | | ------------- |
| 54 | +============ |
35 | 55 |
|
36 | | -Installation should be straight forward using `pip <https://pypi.org/>`_: |
| 56 | +Installation should be straight forward from `pip <https://pypi.org/>`_: |
37 | 57 |
|
38 | 58 | .. code-block:: bash |
39 | 59 |
|
40 | | - $ pip install chaospy |
41 | | -
|
42 | | -For more installation details, see the `installation guide |
43 | | -<https://chaospy.readthedocs.io/en/master/installation.html>`_. |
44 | | - |
45 | | -Example Usage |
46 | | -------------- |
47 | | - |
48 | | -``chaospy`` is created to work well inside numerical Python ecosystem. You |
49 | | -therefore typically need to import `Numpy <https://numpy.org/>`_ along side |
50 | | -``chaospy``: |
51 | | - |
52 | | -.. code-block:: python |
53 | | -
|
54 | | - >>> import numpy |
55 | | - >>> import chaospy |
56 | | -
|
57 | | -``chaospy`` is problem agnostic, so you can use your own code using any means |
58 | | -you find fit. The only requirement is that the output is compatible with |
59 | | -`numpy.ndarray` format: |
60 | | - |
61 | | -.. code-block:: python |
62 | | -
|
63 | | - >>> coordinates = numpy.linspace(0, 10, 100) |
64 | | -
|
65 | | - >>> def forward_solver(coordinates, parameters): |
66 | | - ... """Function to do uncertainty quantification on.""" |
67 | | - ... param_init, param_rate = parameters |
68 | | - ... return param_init*numpy.e**(-param_rate*coordinates) |
| 60 | + pip install chaospy |
69 | 61 |
|
70 | | -We here assume that ``parameters`` contains aleatory variability with known |
71 | | -probability. We formalize this probability in ``chaospy`` as a joint |
72 | | -probability distribution. For example: |
| 62 | +Or if `Conda <https://conda.io/>`_ is more to your liking: |
73 | 63 |
|
74 | | -.. code-block:: python |
75 | | -
|
76 | | - >>> distribution = chaospy.J(chaospy.Uniform(1, 2), chaospy.Normal(0, 2)) |
77 | | -
|
78 | | - >>> print(distribution) |
79 | | - J(Uniform(lower=1, upper=2), Normal(mu=0, sigma=2)) |
80 | | -
|
81 | | -Most probability distributions have an associated expansion of orthogonal |
82 | | -polynomials. These can be automatically constructed: |
83 | | - |
84 | | -.. code-block:: python |
85 | | -
|
86 | | - >>> expansion = chaospy.generate_expansion(8, distribution) |
87 | | -
|
88 | | - >>> print(expansion[:5].round(8)) |
89 | | - [1.0 q1 q0-1.5 q0*q1-1.5*q1 q0**2-3.0*q0+2.16666667] |
90 | | -
|
91 | | -Here the polynomial is defined positional, such that ``q0`` and ``q1`` refers |
92 | | -to the uniform and normal distribution respectively. |
| 64 | +.. code-block:: bash |
93 | 65 |
|
94 | | -The distribution can also be used to create (pseudo-)random samples and |
95 | | -low-discrepancy sequences. For example to create Sobol sequence samples: |
| 66 | + conda install -c conda-forge chaospy |
96 | 67 |
|
97 | | -.. code-block:: python |
| 68 | +Then go over to the |
| 69 | +`tutorial collection <https://chaospy.readthedocs.io/en/master/tutorials>`_ |
| 70 | +to see how to use the toolbox. |
98 | 71 |
|
99 | | - >>> samples = distribution.sample(1000, rule="sobol") |
| 72 | +Development |
| 73 | +=========== |
100 | 74 |
|
101 | | - >>> print(samples[:, :4].round(8)) |
102 | | - [[ 1.5 1.75 1.25 1.375 ] |
103 | | - [ 0. -1.3489795 1.3489795 -0.63727873]] |
| 75 | +Chaospy uses `poetry`_ to manage its development installation. Assuming |
| 76 | +`poetry`_ installed on your system, installing ``chaospy`` for development can |
| 77 | +be done from the repository root with the command:: |
104 | 78 |
|
105 | | -We can evaluating the forward solver using these samples: |
| 79 | + poetry install |
106 | 80 |
|
107 | | -.. code-block:: python |
| 81 | +This will install all required dependencies and chaospy into a virtual |
| 82 | +environment. If you are not already managing your own virtual environment, you |
| 83 | +can use poetry to activate and deactivate with:: |
108 | 84 |
|
109 | | - >>> evaluations = numpy.array([forward_solver(coordinates, sample) |
110 | | - ... for sample in samples.T]) |
| 85 | + poetry shell |
| 86 | + exit |
111 | 87 |
|
112 | | - >>> print(evaluations[:3, :5].round(8)) |
113 | | - [[1.5 1.5 1.5 1.5 1.5 ] |
114 | | - [1.75 2.00546578 2.29822457 2.63372042 3.0181921 ] |
115 | | - [1.25 1.09076905 0.95182169 0.83057411 0.72477163]] |
| 88 | +.. _poetry: https://poetry.eustace.io/ |
116 | 89 |
|
117 | | -Having all these components in place, we have enough components to perform |
118 | | -point collocation. Or in other words, we can create a polynomial approximation |
119 | | -of ``forward_solver``: |
| 90 | +Testing |
| 91 | +------- |
120 | 92 |
|
121 | | -.. code-block:: python |
| 93 | +To ensure that the code run on your local system, run the following: |
122 | 94 |
|
123 | | - >>> approx_solver = chaospy.fit_regression(expansion, samples, evaluations) |
| 95 | +.. code-block:: bash |
124 | 96 |
|
125 | | - >>> print(approx_solver[:2].round(4)) |
126 | | - [q0 -0.0002*q0*q1**3+0.0051*q0*q1**2-0.101*q0*q1+q0] |
| 97 | + poetry run pytest --nbval-lax --doctest-modules \ |
| 98 | + chaospy/ tests/ docs/*/*.{rst,ipynb} |
127 | 99 |
|
128 | | -Since the model approximations are polynomials, we can do inference on them |
129 | | -directly. For example: |
| 100 | +Documentation |
| 101 | +------------- |
130 | 102 |
|
131 | | -.. code-block:: python |
| 103 | +The documentation build assumes that ``pandoc`` is installed on your |
| 104 | +system and available in your path. |
132 | 105 |
|
133 | | - >>> expected = chaospy.E(approx_solver, distribution) |
134 | | - >>> deviation = chaospy.Std(approx_solver, distribution) |
| 106 | +To build documentation locally on your system, use ``make`` from the ``docs/`` |
| 107 | +folder: |
135 | 108 |
|
136 | | - >>> print(expected[:5].round(8)) |
137 | | - [1.5 1.53092356 1.62757217 1.80240142 2.07915608] |
138 | | - >>> print(deviation[:5].round(8)) |
139 | | - [0.28867513 0.43364958 0.76501802 1.27106355 2.07110879] |
| 109 | +.. code-block:: bash |
140 | 110 |
|
141 | | -For more extensive guides on this approach an others, see the `tutorial |
142 | | -collection`_. |
| 111 | + cd docs/ |
| 112 | + make html |
143 | 113 |
|
144 | | -.. _tutorial collection: https://chaospy.readthedocs.io/en/master/tutorials |
| 114 | +Run ``make`` without argument to get a list of build targets. |
| 115 | +The HTML target stores output to the folder ``doc/.build/html``. |
0 commit comments