Use advanced features for PCE

In this example we are going to expose advanced elements in the construction of a polynomial chaos algorithm:

  • construction of the multivariate orthonormal basis,

  • truncature strategy of the multivariate orthonormal basis,

  • evaluation strategy of the approximation coefficients.

In this example, we consider the following function \mathbb{R}^4 \rightarrow \mathbb{R}:

g(\mathbf{x}) = 1+x_1 x_2 + 2 x_3^2+x_4^4

for any x_1,x_2,x_3,x_4\in\mathbb{R}.

We assume that the inputs have Normal, uniform, gamma and beta distributions :

X_1 \sim \mathcal{N}(0,1), \qquad X_2 \sim \mathcal{U}(-1,1), \qquad X_3 \sim \mathcal{G}(2.75,1), \qquad X_4 \sim \mathcal{B}(2.5,1,-1,2),

and X_1, X_2, X_3 and X_4 are independent.

Define the model and the input distribution

import openturns as ot
model = ot.SymbolicFunction(["x1", "x2", "x3", "x4"], ["1+x1*x2 + 2*x3^2+x4^4"])

Create a distribution of dimension 4.

distribution = ot.JointDistribution(
    [ot.Normal(), ot.Uniform(), ot.Gamma(2.75, 1.0), ot.Beta(2.5, 1.0, -1.0, 2.0)]
)
inputDimension = distribution.getDimension()
inputDimension
4

STEP 1: Construction of the multivariate orthonormal basis

Create the univariate polynomial family collection which regroups the polynomial families for each direction.

polyColl = ot.PolynomialFamilyCollection(inputDimension)

We could use the Krawtchouk and Charlier families (for discrete distributions).

polyColl[0] = ot.KrawtchoukFactory()
polyColl[1] = ot.CharlierFactory()

In our specific case, we use specific polynomial factories.

polyColl[0] = ot.HermiteFactory()
polyColl[1] = ot.LegendreFactory()
polyColl[2] = ot.LaguerreFactory(2.75)
polyColl[3] = ot.JacobiFactory(2.5, 1.0, -1.0, 2.0)

Create the enumeration function.

The first possibility is to use the LinearEnumerateFunction.

  • dimension: 4
  • enumerate function: class=LinearEnumerateFunction dimension=4
Index Name Distribution Univariate polynomial
0 X0 Normal Normal
1 X1 Uniform Uniform
2 X2 Gamma Gamma
3 X3 Beta Beta


Another possibility is to use the HyperbolicAnisotropicEnumerateFunction, which gives less weight to interactions.

Create the multivariate orthonormal basis which is the Cartesian product of the univariate basis.

  • dimension: 4
  • enumerate function: class=HyperbolicAnisotropicEnumerateFunction derived from class=HyperbolicAnisotropicEnumerateFunction dimension=4 q=0.4 weights=class=Point name=Unnamed dimension=4 values=[1,1,1,1]
Index Name Distribution Univariate polynomial
0 X0 Normal Normal
1 X1 Uniform Uniform
2 X2 Gamma Gamma
3 X3 Beta Beta


Ask how many basis terms there are in the 6-th strata. In the special case of the linear enumerate function this is also the strata with all the multi-indices of total degree 5.

4

Ask how many basis multi-indices have total degrees lower or equal to k=5.

27

Give the k-th term of the multivariate basis. To calculate its degree, add the integers.

[0,0,0,2]


Build a term of the basis as a Function. Generally, we do not need to construct manually any term, all terms are constructed automatically by a strategy of construction of the basis.

0.806226 - 4.03113 × x3 + 2.21712 × x32


Get the measure mu associated to the multivariate basis.

JointDistribution
  • name=JointDistribution
  • dimension: 4
  • description=[X0,X1,X2,X3]
  • copula: IndependentCopula(dimension = 4)
Index Variable Distribution
0 X0 Normal(mu = 0, sigma = 1)
1 X1 Uniform(a = -1, b = 1)
2 X2 Gamma(k = 2.75, lambda = 1, gamma = 0)
3 X3 Beta(alpha = 2.5, beta = 1, a = -1, b = 2)


STEP 2: Truncature strategy of the multivariate orthonormal basis

FixedStrategy : all the polynomials of degree lower or equal to 2 which corresponds to the 15 first ones.

CleaningStrategy : among the maximumConsideredTerms = 500 first polynomials, those which have the mostSignificant = 50 most significant contributions with significance criterion significanceFactor equal to 10^{-4} The True boolean indicates if we are interested in the online monitoring of the current basis update (removed or added coefficients).

maximumConsideredTerms = 500
mostSignificant = 50
significanceFactor = 1.0e-4
truncatureBasisStrategy_2 = ot.CleaningStrategy(
    multivariateBasis, maximumConsideredTerms, mostSignificant, significanceFactor
)

STEP 3: Evaluation strategy of the approximation coefficients

The technique illustrated is the Least Squares technique where the points come from a design of experiments. Here : the Monte-Carlo sampling technique.

You can specify the approximation algorithm. This is the algorithm that generates a sequence of basis using Least Angle Regression.

This algorithm estimates the empirical error on each sub-basis using Leave One Out strategy.

Try integration.

marginalSizes = [2] * inputDimension
evaluationCoeffStrategy_3 = ot.IntegrationStrategy()
experiment_3 = ot.GaussProductExperiment(distribution, marginalSizes)

Evaluate design of experiments. For the Gauss product we need to specify the non-uniform weights.

STEP 4: Creation of the Functional Chaos Algorithm

The FunctionalChaosAlgorithm class combines

  • the model : model,

  • the distribution of the input random vector : distribution,

  • the truncature strategy of the multivariate basis,

  • and the evaluation strategy of the coefficients.