Polynomial chaos exploitationΒΆ

In this example we are going to create a global approximation of a model response using functional chaos and expose the associated results:

  • the composed model: h: \underline{Z}^{\strut} \longrightarrow \underline{Y} = g \circ T^{-1}(\underline{Z}), which is the model of the reduced variables \underline{Z}. We have \displaystyle h =  \sum_{k \in \mathbb N} \underline{\alpha}_k \Psi_k,

  • the coefficients of the polynomial approximation : (\underline{\alpha}_k)_{k \in K},

  • the composed meta model: \hat{h}, which is the model of the reduced variables reduced to the truncated multivariate basis (\Psi_k)_{k \in K}. We have \displaystyle  \hat{h} = \sum_{k \in K} \underline{\alpha}_k \Psi_k,

  • the meta model: \displaystyle \hat{g} : \underline{X} \longrightarrow Y = \hat{h} \circ T(\underline{X}) which is the polynomial chaos approximation as a Function. We have \displaystyle \hat{g} = \sum_{k \in K} \underline{\alpha}_k \Psi_k \circ T,

  • the truncated multivariate basis : (\Psi_k)_{k \in K},

  • the indices K,

  • the composition of each polynomial of the truncated multivariate basis \Psi_k,

  • the distribution \mu of the transformed variables \underline{Z}.

import openturns as ot

ot.Log.Show(ot.Log.NONE)

Prepare some X/Y data.

ot.RandomGenerator.SetSeed(0)
dimension = 2
input_names = ["x1", "x2"]
formulas = ["cos(x1 + x2)", "(x2 + 1) * exp(x1 - 2 * x2)"]
model = ot.SymbolicFunction(input_names, formulas)
distribution = ot.Normal(dimension)
x = distribution.getSample(30)
y = model(x)

create a functional chaos algorithm

algo = ot.FunctionalChaosAlgorithm(x, y)
algo.run()

Stream out the result

result = algo.getResult()

Get the polynomial chaos coefficients

result.getCoefficients()
v0v1
00.3308045-0.6106302
1-0.09725067-0.6674937
2-0.13500431.924297
3-0.2023175-0.3430515
4-0.1688722-2.403922
50.07066199-0.232698
6-0.00090691091.962535
7-0.27247051.152768
80.1111448-0.06542314
90.01580866-0.9641006
10-0.020569390.66078
110.017547770.3063366
120.19728720.9048693
130.1185361-1.947015
140.03388530.7107189
15-0.034735838.027624e-05
160.013399380.8760112
170.01815919-0.09791576
180.17147780.2717687
190.22764271.475364
200.3167942-0.2963439
21-0.023410040.4344956
22-0.024808610.08778979
230.038529540.4438532
24-0.0601454-0.6648294
250.0059336970.3440138
260.004230113-0.05374558
270.1163968-0.2128577
28-0.051180920.3456002
29-0.027955410.03345297
30-0.0076067550.01674685
31-0.061102150.2832294
320.031868410.3052


The coefficients of marginal i

i = 1
result.getCoefficients()[i]

[-0.0972507,-0.667494]



Get the indices of the selected polynomials : K

subsetK = result.getIndices()
subsetK

[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32]#33



Get the composition of the polynomials of the truncated multivariate basis

for i in range(subsetK.getSize()):
    print(
        "Polynomial number ",
        i,
        " in truncated basis <-> polynomial number ",
        subsetK[i],
        " = ",
        ot.LinearEnumerateFunction(dimension)(subsetK[i]),
        " in complete basis",
    )
Polynomial number  0  in truncated basis <-> polynomial number  0  =  [0,0]  in complete basis
Polynomial number  1  in truncated basis <-> polynomial number  1  =  [1,0]  in complete basis
Polynomial number  2  in truncated basis <-> polynomial number  2  =  [0,1]  in complete basis
Polynomial number  3  in truncated basis <-> polynomial number  3  =  [2,0]  in complete basis
Polynomial number  4  in truncated basis <-> polynomial number  4  =  [1,1]  in complete basis
Polynomial number  5  in truncated basis <-> polynomial number  5  =  [0,2]  in complete basis
Polynomial number  6  in truncated basis <-> polynomial number  6  =  [3,0]  in complete basis
Polynomial number  7  in truncated basis <-> polynomial number  7  =  [2,1]  in complete basis
Polynomial number  8  in truncated basis <-> polynomial number  8  =  [1,2]  in complete basis
Polynomial number  9  in truncated basis <-> polynomial number  9  =  [0,3]  in complete basis
Polynomial number  10  in truncated basis <-> polynomial number  10  =  [4,0]  in complete basis
Polynomial number  11  in truncated basis <-> polynomial number  11  =  [3,1]  in complete basis
Polynomial number  12  in truncated basis <-> polynomial number  12  =  [2,2]  in complete basis
Polynomial number  13  in truncated basis <-> polynomial number  13  =  [1,3]  in complete basis
Polynomial number  14  in truncated basis <-> polynomial number  14  =  [0,4]  in complete basis
Polynomial number  15  in truncated basis <-> polynomial number  15  =  [5,0]  in complete basis
Polynomial number  16  in truncated basis <-> polynomial number  16  =  [4,1]  in complete basis
Polynomial number  17  in truncated basis <-> polynomial number  17  =  [3,2]  in complete basis
Polynomial number  18  in truncated basis <-> polynomial number  18  =  [2,3]  in complete basis
Polynomial number  19  in truncated basis <-> polynomial number  19  =  [1,4]  in complete basis
Polynomial number  20  in truncated basis <-> polynomial number  20  =  [0,5]  in complete basis
Polynomial number  21  in truncated basis <-> polynomial number  21  =  [6,0]  in complete basis
Polynomial number  22  in truncated basis <-> polynomial number  22  =  [5,1]  in complete basis
Polynomial number  23  in truncated basis <-> polynomial number  23  =  [4,2]  in complete basis
Polynomial number  24  in truncated basis <-> polynomial number  24  =  [3,3]  in complete basis
Polynomial number  25  in truncated basis <-> polynomial number  25  =  [2,4]  in complete basis
Polynomial number  26  in truncated basis <-> polynomial number  26  =  [1,5]  in complete basis
Polynomial number  27  in truncated basis <-> polynomial number  27  =  [0,6]  in complete basis
Polynomial number  28  in truncated basis <-> polynomial number  28  =  [7,0]  in complete basis
Polynomial number  29  in truncated basis <-> polynomial number  29  =  [6,1]  in complete basis
Polynomial number  30  in truncated basis <-> polynomial number  30  =  [5,2]  in complete basis
Polynomial number  31  in truncated basis <-> polynomial number  31  =  [4,3]  in complete basis
Polynomial number  32  in truncated basis <-> polynomial number  32  =  [3,4]  in complete basis

Get the multivariate basis as a collection of Function

reduced = result.getReducedBasis()

Get the orthogonal basis

orthgBasis = result.getOrthogonalBasis()

Get the distribution of variables Z

orthgBasis.getMeasure()

ComposedDistribution(VonMises(mu = 0.0630857, kappa=1.61753), Uniform(a = -1, b = 1), IndependentCopula(dimension = 2))



Get the composed meta model which is the model of the reduced variables Z within the reduced polynomials basis

result.getComposedMetaModel()

[0.330804,-0.61063] + [-0.0972507,-0.667494] * (-0.0630992 + 1.00021 * x0) + [-0.135004,1.9243] * (1.73205 * x1) + [-0.202318,-0.343052] * (-0.621424 - 0.0787529 * x0 + 0.624174 * x0^2) + [-0.168872,-2.40392] * (-1.11803 + 3.3541 * x1^2) + [0.070662,-0.232698] * (0.0819413 - 1.29599 * x0 - 0.0689844 * x0^2 + 0.364501 * x0^3) + [-0.000906911,1.96254] * (-3.96863 * x1 + 6.61438 * x1^3) + [-0.27247,1.15277] * ((-0.0630992 + 1.00021 * x0) * (1.73205 * x1)) + [0.111145,-0.0654231] * (0.664284 + 0.187284 * x0 - 1.48072 * x0^2 - 0.0576984 * x0^3 + 0.228651 * x0^4) + [0.0158087,-0.964101] * (1.125 - 11.25 * x1^2 + 13.125 * x1^4) + [-0.0205694,0.66078] * (-0.10992 + 1.73191 * x0 + 0.248892 * x0^2 - 1.31123 * x0^3 - 0.0459492 * x0^4 + 0.145672 * x0^5) + [0.0175478,0.306337] * (6.21867 * x1 - 29.0205 * x1^3 + 26.1184 * x1^5) + [0.197287,0.904869] * ((-0.621424 - 0.0787529 * x0 + 0.624174 * x0^2) * (1.73205 * x1)) + [0.118536,-1.94701] * ((-0.0630992 + 1.00021 * x0) * (-1.11803 + 3.3541 * x1^2)) + [0.0338853,0.710719] * (-0.656697 - 0.325351 * x0 + 2.56175 * x0^2 + 0.267675 * x0^3 - 1.05708 * x0^4 - 0.0349601 * x0^5 + 0.0923614 * x0^6) + [-0.0347358,8.02762e-05] * (-1.12673 + 23.6614 * x1^2 - 70.9843 * x1^4 + 52.0551 * x1^6) + [0.0133994,0.876011] * (0.136249 - 2.13624 * x0 - 0.557896 * x0^2 + 2.9261 * x0^3 + 0.258064 * x0^4 - 0.814873 * x0^5 - 0.025872 * x0^6 + 0.058587 * x0^7) + [0.0181592,-0.0979158] * (-8.47215 * x1 + 76.2494 * x1^3 - 167.749 * x1^5 + 103.844 * x1^7) + [0.171478,0.271769] * ((0.0819413 - 1.29599 * x0 - 0.0689844 * x0^2 + 0.364501 * x0^3) * (1.73205 * x1)) + [0.227643,1.47536] * ((-0.0630992 + 1.00021 * x0) * (-3.96863 * x1 + 6.61438 * x1^3)) + [0.316794,-0.296344] * ((-0.621424 - 0.0787529 * x0 + 0.624174 * x0^2) * (-1.11803 + 3.3541 * x1^2)) + [-0.02341,0.434496] * (0.652084 + 0.497903 * x0 - 3.89951 * x0^2 - 0.739607 * x0^3 + 2.90659 * x0^4 + 0.231563 * x0^5 - 0.609003 * x0^6 - 0.0187799 * x0^7 + 0.037211 * x0^8) + [-0.0248086,0.0877898] * (1.12741 - 40.5868 * x1^2 + 223.228 * x1^4 - 386.928 * x1^6 + 207.283 * x1^8) + [0.0385295,0.443853] * ((0.664284 + 0.187284 * x0 - 1.48072 * x0^2 - 0.0576984 * x0^3 + 0.228651 * x0^4) * (1.73205 * x1)) + [-0.0601454,-0.664829] * ((-0.0630992 + 1.00021 * x0) * (1.125 - 11.25 * x1^2 + 13.125 * x1^4)) + [0.0059337,0.344014] * (-0.162465 + 2.53183 * x0 + 1.03094 * x0^2 - 5.37612 * x0^3 - 0.84474 * x0^4 + 2.65313 * x0^5 + 0.197456 * x0^6 - 0.444879 * x0^7 - 0.0134262 * x0^8 + 0.0236471 * x0^9) + [0.00423011,-0.0537456] * (10.727 * x1 - 157.329 * x1^3 + 613.583 * x1^5 - 876.547 * x1^7 + 413.925 * x1^9) + [0.116397,-0.212858] * ((0.0819413 - 1.29599 * x0 - 0.0689844 * x0^2 + 0.364501 * x0^3) * (-1.11803 + 3.3541 * x1^2)) + [-0.0511809,0.3456] * ((-0.621424 - 0.0787529 * x0 + 0.624174 * x0^2) * (-3.96863 * x1 + 6.61438 * x1^3)) + [-0.0279554,0.033453] * (-0.645788 - 0.702885 * x0 + 5.46896 * x0^2 + 1.61083 * x0^3 - 6.29129 * x0^4 - 0.875042 * x0^5 + 2.28788 * x0^6 + 0.16215 * x0^7 - 0.319495 * x0^8 - 0.00948333 * x0^9 + 0.0150325 * x0^10) + [-0.00760675,0.0167469] * (-1.12774 + 62.0259 * x1^2 - 537.558 * x1^4 + 1612.67 * x1^6 - 1958.25 * x1^8 + 826.815 * x1^10) + [-0.0611021,0.283229] * ((-0.10992 + 1.73191 * x0 + 0.248892 * x0^2 - 1.31123 * x0^3 - 0.0459492 * x0^4 + 0.145672 * x0^5) * (1.73205 * x1)) + [0.0318684,0.3052] * ((-0.0630992 + 1.00021 * x0) * (6.21867 * x1 - 29.0205 * x1^3 + 26.1184 * x1^5))



Get the meta model which is the composed meta model combined with the iso probabilistic transformation

result.getMetaModel()

([0.330804,-0.61063] + [-0.0972507,-0.667494] * (-0.0630992 + 1.00021 * x0) + [-0.135004,1.9243] * (1.73205 * x1) + [-0.202318,-0.343052] * (-0.621424 - 0.0787529 * x0 + 0.624174 * x0^2) + [-0.168872,-2.40392] * (-1.11803 + 3.3541 * x1^2) + [0.070662,-0.232698] * (0.0819413 - 1.29599 * x0 - 0.0689844 * x0^2 + 0.364501 * x0^3) + [-0.000906911,1.96254] * (-3.96863 * x1 + 6.61438 * x1^3) + [-0.27247,1.15277] * ((-0.0630992 + 1.00021 * x0) * (1.73205 * x1)) + [0.111145,-0.0654231] * (0.664284 + 0.187284 * x0 - 1.48072 * x0^2 - 0.0576984 * x0^3 + 0.228651 * x0^4) + [0.0158087,-0.964101] * (1.125 - 11.25 * x1^2 + 13.125 * x1^4) + [-0.0205694,0.66078] * (-0.10992 + 1.73191 * x0 + 0.248892 * x0^2 - 1.31123 * x0^3 - 0.0459492 * x0^4 + 0.145672 * x0^5) + [0.0175478,0.306337] * (6.21867 * x1 - 29.0205 * x1^3 + 26.1184 * x1^5) + [0.197287,0.904869] * ((-0.621424 - 0.0787529 * x0 + 0.624174 * x0^2) * (1.73205 * x1)) + [0.118536,-1.94701] * ((-0.0630992 + 1.00021 * x0) * (-1.11803 + 3.3541 * x1^2)) + [0.0338853,0.710719] * (-0.656697 - 0.325351 * x0 + 2.56175 * x0^2 + 0.267675 * x0^3 - 1.05708 * x0^4 - 0.0349601 * x0^5 + 0.0923614 * x0^6) + [-0.0347358,8.02762e-05] * (-1.12673 + 23.6614 * x1^2 - 70.9843 * x1^4 + 52.0551 * x1^6) + [0.0133994,0.876011] * (0.136249 - 2.13624 * x0 - 0.557896 * x0^2 + 2.9261 * x0^3 + 0.258064 * x0^4 - 0.814873 * x0^5 - 0.025872 * x0^6 + 0.058587 * x0^7) + [0.0181592,-0.0979158] * (-8.47215 * x1 + 76.2494 * x1^3 - 167.749 * x1^5 + 103.844 * x1^7) + [0.171478,0.271769] * ((0.0819413 - 1.29599 * x0 - 0.0689844 * x0^2 + 0.364501 * x0^3) * (1.73205 * x1)) + [0.227643,1.47536] * ((-0.0630992 + 1.00021 * x0) * (-3.96863 * x1 + 6.61438 * x1^3)) + [0.316794,-0.296344] * ((-0.621424 - 0.0787529 * x0 + 0.624174 * x0^2) * (-1.11803 + 3.3541 * x1^2)) + [-0.02341,0.434496] * (0.652084 + 0.497903 * x0 - 3.89951 * x0^2 - 0.739607 * x0^3 + 2.90659 * x0^4 + 0.231563 * x0^5 - 0.609003 * x0^6 - 0.0187799 * x0^7 + 0.037211 * x0^8) + [-0.0248086,0.0877898] * (1.12741 - 40.5868 * x1^2 + 223.228 * x1^4 - 386.928 * x1^6 + 207.283 * x1^8) + [0.0385295,0.443853] * ((0.664284 + 0.187284 * x0 - 1.48072 * x0^2 - 0.0576984 * x0^3 + 0.228651 * x0^4) * (1.73205 * x1)) + [-0.0601454,-0.664829] * ((-0.0630992 + 1.00021 * x0) * (1.125 - 11.25 * x1^2 + 13.125 * x1^4)) + [0.0059337,0.344014] * (-0.162465 + 2.53183 * x0 + 1.03094 * x0^2 - 5.37612 * x0^3 - 0.84474 * x0^4 + 2.65313 * x0^5 + 0.197456 * x0^6 - 0.444879 * x0^7 - 0.0134262 * x0^8 + 0.0236471 * x0^9) + [0.00423011,-0.0537456] * (10.727 * x1 - 157.329 * x1^3 + 613.583 * x1^5 - 876.547 * x1^7 + 413.925 * x1^9) + [0.116397,-0.212858] * ((0.0819413 - 1.29599 * x0 - 0.0689844 * x0^2 + 0.364501 * x0^3) * (-1.11803 + 3.3541 * x1^2)) + [-0.0511809,0.3456] * ((-0.621424 - 0.0787529 * x0 + 0.624174 * x0^2) * (-3.96863 * x1 + 6.61438 * x1^3)) + [-0.0279554,0.033453] * (-0.645788 - 0.702885 * x0 + 5.46896 * x0^2 + 1.61083 * x0^3 - 6.29129 * x0^4 - 0.875042 * x0^5 + 2.28788 * x0^6 + 0.16215 * x0^7 - 0.319495 * x0^8 - 0.00948333 * x0^9 + 0.0150325 * x0^10) + [-0.00760675,0.0167469] * (-1.12774 + 62.0259 * x1^2 - 537.558 * x1^4 + 1612.67 * x1^6 - 1958.25 * x1^8 + 826.815 * x1^10) + [-0.0611021,0.283229] * ((-0.10992 + 1.73191 * x0 + 0.248892 * x0^2 - 1.31123 * x0^3 - 0.0459492 * x0^4 + 0.145672 * x0^5) * (1.73205 * x1)) + [0.0318684,0.3052] * ((-0.0630992 + 1.00021 * x0) * (6.21867 * x1 - 29.0205 * x1^3 + 26.1184 * x1^5)))o(| y0 = [x0]->[x0]
| y1 = [x1]->[0.537892876741792203*(x1-0.2190125596644127981)]
)



Get the projection strategy

algo.getProjectionStrategy()

class=ProjectionStrategy implementation=class=LeastSquaresStrategy experiment=class=FixedExperiment name=Unnamed sample=class=Sample name=Normal implementation=class=SampleImplementation name=Normal size=30 dimension=2 description=[X0,X1] data=[[0.608202,-1.26617],[-0.438266,1.20548],[-2.18139,0.350042],[-0.355007,1.43725],[0.810668,0.793156],[-0.470526,0.261018],[-2.29006,-1.28289],[-1.31178,-0.0907838],[0.995793,-0.139453],[-0.560206,0.44549],[0.322925,0.445785],[-1.03808,-0.856712],[0.473617,-0.125498],[0.351418,1.78236],[0.0702074,-0.781366],[-0.721533,-0.241223],[-1.78796,0.40136],[1.36783,1.00434],[0.741548,-0.0436123],[0.539345,0.29995],[0.407717,-0.485112],[-0.382992,-0.752817],[0.257926,1.96876],[-0.671291,1.85579],[0.0521593,0.790446],[0.716353,-0.743622],[0.184356,-1.53073],[0.655027,0.538071],[1.73821,-0.958722],[0.377922,-0.181004]] weights=class=Point name=Unnamed dimension=30 values=[0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333,0.0333333]



Total running time of the script: ( 0 minutes 0.029 seconds)