# FunctionalChaosAlgorithm¶

class FunctionalChaosAlgorithm(*args)

Functional chaos algorithm.

Available constructors:

FunctionalChaosAlgorithm(inputSample, outputSample)

FunctionalChaosAlgorithm(inputSample, weights, outputSample, distribution, adaptiveStrategy, projectionStrategy)

Parameters
inputSample, outputSample2-d sequence of float

Sample of the input - output random vectors

modelFunction

Model such as .

distributionDistribution

Distribution of the random vector adaptiveStrategyAdaptiveStrategy

Strategy of selection of the different terms of the multivariate basis.

projectionStrategyProjectionStrategy

Strategy of evaluation of the coefficients weightssequence of float

Weights associated to the data base

Default values are where N=inputSample.getSize()

Notes

Consider with , and with finite variance: .

When , the functional chaos algorithm is used on each marginal of , using the same multivariate orthonormal basis for all the marginals. Thus, the algorithm is detailed here for a scalar output and .

Let be an isoprobabilistic transformation such that . We note , then .

Let be an orthonormal multivariate basis of .

Then the functional chaos decomposition of f writes: which can be truncated to the finite set : The approximation can be used to build an efficient random generator of based on the random vector . It writes: For more details, see FunctionalChaosRandomVector.

The functional chaos decomposition can be used to build a meta model of g, which writes: If the basis has been obtained by tensorisation of univariate orthonormal basis, then the distribution writes . In that case only, the Sobol indices can easily be deduced from the coefficients .

We detail here all the steps required in order to create a functional chaos algorithm.

Step 1 - Construction of the multivariate orthonormal basis: the multivariate orthonornal basis is built as the tensor product of orthonormal univariate families.

The univariate bases may be:

• polynomials: the associated distribution is continuous or discrete. Note that it is possible to build the polynomial family orthonormal to any univariate distribution under some conditions. For more details, see StandardDistributionPolynomialFactory;

• Haar wavelets: they enable to approximate functions with discontinuities. For more details, see HaarWaveletFactory,;

• Fourier series: for more details, see FourierSeriesFactory.

Furthermore, the numerotation of the multivariate orthonormal basis is given by an enumerate function which defines a regular way to generate the collection of degres used for the univariate polynomials : an enumerate function represents a bijection . See LinearEnumerateFunction or HyperbolicAnisotropicEnumerateFunction for more details.

Step 2 - Truncation strategy of the multivariate orthonormal basis: a strategy must be chosen for the selection of the different terms of the multivariate basis. The selected terms are gathered in the subset K.

For more details on the possible strategies, see FixedStrategy, SequentialStrategy and CleaningStrategy.

Step 3 - Evaluation strategy of the coefficients: a strategy must be chosen for the estimation of te coefficients . The vector is equivalently defined by:

(1) or

(2) where the mean is evaluated with respect to the measure .

Relation (1) means that the coefficients minimize the quadratic error between the model and the polynomial approximation. For more details, see LeastSquaresStrategy.

Relation (2) means that is the scalar product of the model with the k-th element of the orthonormal basis . For more details, see IntegrationStrategy.

Examples

Create the model:

>>> import openturns as ot
>>> ot.RandomGenerator.SetSeed(0)
>>> inputDim = 1
>>> model = ot.SymbolicFunction(['x'], ['x*sin(x)'])
>>> distribution = ot.ComposedDistribution([ot.Uniform()]*inputDim)


Build the multivariate orthonormal basis:

>>> polyColl = [0.0]*inputDim
>>> for i in range(distribution.getDimension()):
...     polyColl[i] = ot.StandardDistributionPolynomialFactory(distribution.getMarginal(i))
>>> enumerateFunction = ot.LinearEnumerateFunction(inputDim)
>>> productBasis = ot.OrthogonalProductPolynomialFactory(polyColl, enumerateFunction)


Define the strategy to truncate the multivariate orthonormal basis: We choose all the polynomials of degree <= 4

>>> degree = 4
>>> indexMax = enumerateFunction.getStrataCumulatedCardinal(degree)
>>> print(indexMax)
5


We keep all the polynomials of degree <= 4 (which corresponds to the 5 first ones):

>>> adaptiveStrategy = ot.FixedStrategy(productBasis, indexMax)


Define the evaluation strategy of the coefficients:

>>> samplingSize = 50
>>> experiment = ot.MonteCarloExperiment(samplingSize)
>>> projectionStrategy = ot.LeastSquaresStrategy(experiment)


Create the Functional Chaos Algorithm:

>>> algo = ot.FunctionalChaosAlgorithm(model, distribution, adaptiveStrategy,
...                                    projectionStrategy)
>>> algo.run()


Get the result:

>>> functionalChaosResult = algo.getResult()
>>> metamodel = functionalChaosResult.getMetaModel()


Test it:

>>> X = [0.5]
>>> print(model(X))
[0.239713]
>>> print(metamodel(X))
[0.239514]


Methods

 BuildDistribution(inputSample) Recover the distribution, with metamodel performance in mind. Get the adaptive strategy. getClassName(self) Accessor to the object’s name. Accessor to the joint probability density function of the physical input vector. getId(self) Accessor to the object’s id. getInputSample(self) Accessor to the input sample. Get the maximum residual. getName(self) Accessor to the object’s name. Accessor to the output sample. Get the projection strategy. getResult(self) Get the results of the metamodel computation. getShadowedId(self) Accessor to the object’s shadowed id. getVisibility(self) Accessor to the object’s visibility state. hasName(self) Test if the object is named. hasVisibleName(self) Test if the object has a distinguishable name. run(self) Compute the metamodel. setDistribution(self, distribution) Accessor to the joint probability density function of the physical input vector. setMaximumResidual(self, residual) Set the maximum residual. setName(self, name) Accessor to the object’s name. setProjectionStrategy(self, projectionStrategy) Set the projection strategy. setShadowedId(self, id) Accessor to the object’s shadowed id. setVisibility(self, visible) Accessor to the object’s visibility state.
__init__(self, \*args)

Initialize self. See help(type(self)) for accurate signature.

static BuildDistribution(inputSample)

Recover the distribution, with metamodel performance in mind.

For each marginal, find the best 1-d continuous parametric model, else fallback to the use of KernelSmoothing. For the copula, the Spearman independance test is used on each component pair to decide whether an independent copula can be used, else use a NormalCopula.

Parameters
sampleSample

Input sample.

Returns
distributionDistribution

Input distribution.

getAdaptiveStrategy(self)

Returns
adaptiveStrategyAdaptiveStrategy

Strategy of selection of the different terms of the multivariate basis.

getClassName(self)

Accessor to the object’s name.

Returns
class_namestr

The object class name (object.__class__.__name__).

getDistribution(self)

Accessor to the joint probability density function of the physical input vector.

Returns
distributionDistribution

Joint probability density function of the physical input vector.

getId(self)

Accessor to the object’s id.

Returns
idint

Internal unique identifier.

getInputSample(self)

Accessor to the input sample.

Returns
inputSampleSample

Input sample of a model evaluated apart.

getMaximumResidual(self)

Get the maximum residual.

Returns
residualfloat

Residual value needed in the projection strategy.

Default value is .

getName(self)

Accessor to the object’s name.

Returns
namestr

The name of the object.

getOutputSample(self)

Accessor to the output sample.

Returns
outputSampleSample

Output sample of a model evaluated apart.

getProjectionStrategy(self)

Get the projection strategy.

Returns
strategyProjectionStrategy

Projection strategy.

Notes

The projection strategy selects the different terms of the multivariate basis to define the subset K.

getResult(self)

Get the results of the metamodel computation.

Returns
resultFunctionalChaosResult

Result structure, created by the method run().

getShadowedId(self)

Accessor to the object’s shadowed id.

Returns
idint

Internal unique identifier.

getVisibility(self)

Accessor to the object’s visibility state.

Returns
visiblebool

Visibility flag.

hasName(self)

Test if the object is named.

Returns
hasNamebool

True if the name is not empty.

hasVisibleName(self)

Test if the object has a distinguishable name.

Returns
hasVisibleNamebool

True if the name is not empty and not the default one.

run(self)

Compute the metamodel.

Notes

Evaluates the metamodel and stores all the results in a result structure.

setDistribution(self, distribution)

Accessor to the joint probability density function of the physical input vector.

Parameters
distributionDistribution

Joint probability density function of the physical input vector.

setMaximumResidual(self, residual)

Set the maximum residual.

Parameters
residualfloat

Residual value needed in the projection strategy.

Default value is .

setName(self, name)

Accessor to the object’s name.

Parameters
namestr

The name of the object.

setProjectionStrategy(self, projectionStrategy)

Set the projection strategy.

Parameters
strategyProjectionStrategy

Strategy to estimate the coefficients .

setShadowedId(self, id)

Accessor to the object’s shadowed id.

Parameters
idint

Internal unique identifier.

setVisibility(self, visible)

Accessor to the object’s visibility state.

Parameters
visiblebool

Visibility flag.