.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_surrogate_modeling/polynomial_chaos/plot_functional_chaos_getmarginal.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_surrogate_modeling_polynomial_chaos_plot_functional_chaos_getmarginal.py: Get the (output) marginal of a PCE ================================== .. GENERATED FROM PYTHON SOURCE LINES 7-10 .. code-block:: Python from openturns.usecases import flood_model import openturns as ot .. GENERATED FROM PYTHON SOURCE LINES 11-13 .. code-block:: Python ot.RandomGenerator.SetSeed(0) .. GENERATED FROM PYTHON SOURCE LINES 14-15 Create a PCE of a multivariate output function .. GENERATED FROM PYTHON SOURCE LINES 15-35 .. code-block:: Python fm = flood_model.FloodModel() sampleSize = 100 inputTrain = fm.distribution.getSample(sampleSize) print(f"Output dimension = {fm.model.getOutputDimension()}") outputTrain = fm.model(inputTrain) marginalList = [fm.distribution.getMarginal(i) for i in range(fm.distribution.getDimension())] multivariateBasis = ot.OrthogonalProductPolynomialFactory(marginalList) selectionAlgorithm = ot.LeastSquaresMetaModelSelectionFactory() projectionStrategy = ot.LeastSquaresStrategy(selectionAlgorithm) totalDegree = 4 enumerateFunction = multivariateBasis.getEnumerateFunction() basisSize = enumerateFunction.getBasisSizeFromTotalDegree(totalDegree) adaptiveStrategy = ot.FixedStrategy(multivariateBasis, basisSize) chaosAlgo = ot.FunctionalChaosAlgorithm( inputTrain, outputTrain, fm.distribution, adaptiveStrategy, projectionStrategy ) chaosAlgo.run() chaosResult = chaosAlgo.getResult() chaosResult .. rst-class:: sphx-glr-script-out .. code-block:: none Output dimension = 3 .. raw:: html
FunctionalChaosResult
Index Multi-index Coeff.#0 Coeff.#1 Coeff.#2
0 [0,0,0,0,0,0,0,0] 2.548371 -5.896414 1.051877
1 [1,0,0,0,0,0,0,0] 0.773257 0.8357752 0.1253737
2 [0,1,0,0,0,0,0,0] -0.4389366 -0.3860588 -0.05421815
3 [0,0,1,0,0,0,0,0] 0.08976339 0.647519 0.09112254
4 [0,0,0,1,0,0,0,0] -0.08137927 0 0
5 [0,0,0,0,0,0,1,0] 0 -0.1905812 -0.02479445
6 [0,0,0,0,0,0,0,1] 0 -0.5785103 -0.08005601
7 [2,0,0,0,0,0,0,0] -0.1214097 0 -0.01510397
8 [1,1,0,0,0,0,0,0] -0.1210497 0 -0.01609437
9 [1,0,1,0,0,0,0,0] 0.0249925 0 0
10 [1,0,0,1,0,0,0,0] -0.03204353 -0.06062191 -0.00616599
11 [0,2,0,0,0,0,0,0] 0.1650799 0.2157529 0
12 [0,0,1,0,0,0,0,1] 0 0.03178252 0
13 [2,1,0,0,0,0,0,0] 0 0 0.01875842
14 [2,0,1,0,0,0,0,0] 0 0 -0.02694046
15 [2,0,0,1,0,0,0,0] 0.02169697 0 0
16 [1,2,0,0,0,0,0,0] 0.03479956 0.08026756 0
17 [1,1,0,0,0,1,0,0] 0.002127432 0 0
18 [1,0,1,1,0,0,0,0] -0.01386595 0 0
19 [0,3,0,0,0,0,0,0] -0.05261044 0 0
20 [0,2,1,0,0,0,0,0] 0.007146761 0 -0.01108846
21 [0,2,0,1,0,0,0,0] 0.003041979 0 0
22 [0,2,0,0,0,1,0,0] 0.001910707 0.04568372 0
23 [0,1,1,0,0,0,0,1] -0.0118976 0 0
24 [0,0,1,2,0,0,0,0] 0.008048237 0 0
25 [0,0,0,2,1,0,0,0] 0 0 0.00304079
26 [3,0,0,0,0,1,0,0] -0.005522131 0 0
27 [2,0,0,2,0,0,0,0] 0 0 0.0005163499
28 [1,2,0,0,0,1,0,0] 0.006881887 0.02602445 0
29 [1,1,0,2,0,0,0,0] -0.002116046 0.01629044 0
30 [1,1,0,0,0,2,0,0] 0.0005137444 0 0
31 [1,1,0,0,0,1,0,1] 0.004035853 0.0310958 0
32 [1,0,1,0,0,2,0,0] 0.00530171 0 0
33 [1,0,1,0,0,0,0,2] 0 0 0.009452343
34 [1,0,0,2,1,0,0,0] -0.0003194063 0 0
35 [1,0,0,0,0,2,1,0] 0 0 -0.0003454352
36 [1,0,0,0,0,1,0,2] 0.01226029 0 0
37 [0,4,0,0,0,0,0,0] 0.05244523 0 0
38 [0,3,1,0,0,0,0,0] 0.01209063 0.05043918 0.002357003
39 [0,2,2,0,0,0,0,0] 0 0 0.00226228
40 [0,2,1,1,0,0,0,0] 0.005735646 0 0
41 [0,2,1,0,1,0,0,0] 0.006009616 0 0
42 [0,2,0,2,0,0,0,0] -0.02147063 0 0
43 [0,1,2,1,0,0,0,0] 0 0 -0.005858556
44 [0,1,2,0,0,0,0,1] 0.00340243 0 0
45 [0,1,1,1,1,0,0,0] 0.008101327 0 0
46 [0,1,0,2,1,0,0,0] -0.01241504 0 -0.003665261
47 [0,1,0,0,3,0,0,0] 0.001777337 0 0
48 [0,0,4,0,0,0,0,0] 0.003530577 0 0
49 [0,0,0,3,1,0,0,0] -0.004709976 0 0
50 [0,0,0,1,0,3,0,0] 0 0 0.003566791
51 [0,0,0,1,0,2,0,1] 0.008706613 0 0
52 [0,0,0,0,3,0,0,1] 0 0 0.005100202
53 [0,0,0,0,1,0,0,3] 0 0 0.003412873


.. GENERATED FROM PYTHON SOURCE LINES 36-37 Get the marginal PCE corresponding to the third output. .. GENERATED FROM PYTHON SOURCE LINES 37-41 .. code-block:: Python marginal_pce = chaosResult.getMarginal(2) marginal_pce .. raw:: html
FunctionalChaosResult
Index Multi-index Coeff.
0 [0,0,0,0,0,0,0,0] 1.051877
1 [1,0,0,0,0,0,0,0] 0.1253737
2 [0,1,0,0,0,0,0,0] -0.05421815
3 [0,0,1,0,0,0,0,0] 0.09112254
4 [0,0,0,0,0,0,1,0] -0.02479445
5 [0,0,0,0,0,0,0,1] -0.08005601
6 [2,0,0,0,0,0,0,0] -0.01510397
7 [1,1,0,0,0,0,0,0] -0.01609437
8 [1,0,0,1,0,0,0,0] -0.00616599
9 [2,1,0,0,0,0,0,0] 0.01875842
10 [2,0,1,0,0,0,0,0] -0.02694046
11 [0,2,1,0,0,0,0,0] -0.01108846
12 [0,0,0,2,1,0,0,0] 0.00304079
13 [2,0,0,2,0,0,0,0] 0.0005163499
14 [1,0,1,0,0,0,0,2] 0.009452343
15 [1,0,0,0,0,2,1,0] -0.0003454352
16 [0,3,1,0,0,0,0,0] 0.002357003
17 [0,2,2,0,0,0,0,0] 0.00226228
18 [0,1,2,1,0,0,0,0] -0.005858556
19 [0,1,0,2,1,0,0,0] -0.003665261
20 [0,0,0,1,0,3,0,0] 0.003566791
21 [0,0,0,0,3,0,0,1] 0.005100202
22 [0,0,0,0,1,0,0,3] 0.003412873


.. GENERATED FROM PYTHON SOURCE LINES 42-43 Get the marginal PCE corresponding to the second and third outputs. .. GENERATED FROM PYTHON SOURCE LINES 43-46 .. code-block:: Python marginal_pce = chaosResult.getMarginal([1, 2]) marginal_pce .. raw:: html
FunctionalChaosResult
Index Multi-index Coeff.#0 Coeff.#1
0 [0,0,0,0,0,0,0,0] -5.896414 1.051877
1 [1,0,0,0,0,0,0,0] 0.8357752 0.1253737
2 [0,1,0,0,0,0,0,0] -0.3860588 -0.05421815
3 [0,0,1,0,0,0,0,0] 0.647519 0.09112254
4 [0,0,0,0,0,0,1,0] -0.1905812 -0.02479445
5 [0,0,0,0,0,0,0,1] -0.5785103 -0.08005601
6 [2,0,0,0,0,0,0,0] 0 -0.01510397
7 [1,1,0,0,0,0,0,0] 0 -0.01609437
8 [1,0,0,1,0,0,0,0] -0.06062191 -0.00616599
9 [0,2,0,0,0,0,0,0] 0.2157529 0
10 [0,0,1,0,0,0,0,1] 0.03178252 0
11 [2,1,0,0,0,0,0,0] 0 0.01875842
12 [2,0,1,0,0,0,0,0] 0 -0.02694046
13 [1,2,0,0,0,0,0,0] 0.08026756 0
14 [0,2,1,0,0,0,0,0] 0 -0.01108846
15 [0,2,0,0,0,1,0,0] 0.04568372 0
16 [0,0,0,2,1,0,0,0] 0 0.00304079
17 [2,0,0,2,0,0,0,0] 0 0.0005163499
18 [1,2,0,0,0,1,0,0] 0.02602445 0
19 [1,1,0,2,0,0,0,0] 0.01629044 0
20 [1,1,0,0,0,1,0,1] 0.0310958 0
21 [1,0,1,0,0,0,0,2] 0 0.009452343
22 [1,0,0,0,0,2,1,0] 0 -0.0003454352
23 [0,3,1,0,0,0,0,0] 0.05043918 0.002357003
24 [0,2,2,0,0,0,0,0] 0 0.00226228
25 [0,1,2,1,0,0,0,0] 0 -0.005858556
26 [0,1,0,2,1,0,0,0] 0 -0.003665261
27 [0,0,0,1,0,3,0,0] 0 0.003566791
28 [0,0,0,0,3,0,0,1] 0 0.005100202
29 [0,0,0,0,1,0,0,3] 0 0.003412873


.. _sphx_glr_download_auto_surrogate_modeling_polynomial_chaos_plot_functional_chaos_getmarginal.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_functional_chaos_getmarginal.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_functional_chaos_getmarginal.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_functional_chaos_getmarginal.zip `