CleaningStrategy¶
- class CleaningStrategy(*args)¶
Cleaning truncation strategy.
- Available constructors:
CleaningStrategy(orthogonalBasis, maximumDimension)
CleaningStrategy(orthogonalBasis, maximumDimension, maximumSize, significanceFactor)
- Parameters:
- orthogonalBasis
OrthogonalBasis
An OrthogonalBasis.
- maximumDimensionpositive int
Maximum index that can be used by the
EnumerateFunction
to determine the last term of the basis.- maximumSizepositive int
Parameter that characterizes the cleaning strategy. It represents the number of efficient coefficients of the basis. Its default value is the CleaningStrategy-DefaultMaximumSize key of the
ResourceMap
.- significanceFactorfloat
Parameter used as a threshold factor for selecting the efficient coefficients of the basis. The actual threshold is the product of the significanceFactor with the maximum magnitude of the current coefficients. Its default value is the CleaningStrategy-DefaultSignificanceFactor key of the
ResourceMap
.- verbosebool
Used for the online monitoring of the current basis updates (removed or added coefficients).
- orthogonalBasis
See also
Notes
The cleaning strategy aims at building a PC expansion containing only a subset of the coefficients of the full expansion. Hence, this strategy can lead to a sparse expansion which can limit the chances of potential surrogate model overfitting.
Let maximumDimension be the number of coefficients in the full expansion and let maximumSize be the maximum number of coefficients defined by the user. On output, at most the minimum of maximumDimension and maximumSize coefficients are selected. Let be the value of the significanceFactor. The method proceeds as follows:
Generate an initial PC basis made of the maximumDimension first polynomials (according to the adopted
EnumerateFunction
), or equivalently an initial set of indices .Discard from the basis any polynomial associated with an insignificant coefficient, i.e. such that:
Add the next basis term to the current basis .
Reiterate the procedure until the minimum of maximumDimension and maximumSize has been reached.
Examples
In the next example, we select, among the maximumDimension = 100 first polynomials of the multivariate basis, those which have the maximumSize = 20 most significant contribution (greatest absolute value of the coefficients), with respect to the significance factor .
>>> import openturns as ot >>> ot.RandomGenerator.SetSeed(0) >>> # Define the model >>> inputDim = 1 >>> model = ot.SymbolicFunction(['x'], ['x*sin(x)']) >>> # Create the input distribution >>> distribution = ot.JointDistribution([ot.Uniform()]*inputDim) >>> # Construction of 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) >>> maximumDimension = 100 >>> maximumSize = 20 >>> significanceFactor = 1e-4 >>> adaptiveStrategy = ot.CleaningStrategy( ... productBasis, maximumDimension, maximumSize, significanceFactor ... )
Methods
Compute initial basis for the approximation.
getBasis
()Accessor to the underlying orthogonal basis.
Accessor to the object's name.
Accessor to the current vector index.
Accessor to the maximum dimension of the orthogonal basis.
Accessor to the maximum size of the orthogonal basis.
getName
()Accessor to the object's name.
getPsi
()Accessor to the selected orthogonal polynomials in the basis.
Accessor to the significance factor.
hasName
()Test if the object is named.
Get the model selection flag.
setMaximumDimension
(maximumDimension)Accessor to the maximum dimension of the orthogonal basis.
setMaximumSize
(maximumSize)Accessor to the maximum size of the orthogonal basis.
setName
(name)Accessor to the object's name.
setSignificanceFactor
(significanceFactor)Accessor to the significance factor.
updateBasis
(alpha_k, residual, relativeError)Update the basis for the next iteration of approximation.
- __init__(*args)¶
- getBasis()¶
Accessor to the underlying orthogonal basis.
- Returns:
- basis
OrthogonalBasis
Orthogonal basis of which the adaptive strategy is based.
- basis
- getClassName()¶
Accessor to the object’s name.
- Returns:
- class_namestr
The object class name (object.__class__.__name__).
- getCurrentVectorIndex()¶
Accessor to the current vector index.
- Returns:
- indexint
Current index of the basis term.
- getMaximumDimension()¶
Accessor to the maximum dimension of the orthogonal basis.
- Returns:
- maximumDimensionint
Maximum dimension of the truncated basis.
- getMaximumSize()¶
Accessor to the maximum size of the orthogonal basis.
- Returns:
- maximumSizeint
Maximum number of significant terms of the basis.
See also
- getName()¶
Accessor to the object’s name.
- Returns:
- namestr
The name of the object.
- getPsi()¶
Accessor to the selected orthogonal polynomials in the basis.
The value returned by this method depends on the specific choice of adaptive strategy and the previous calls to the
updateBasis()
method.- Returns:
- polynomialslist of polynomials
Sequence of polynomials.
Notes
The method
computeInitialBasis()
must be applied first.Examples
>>> import openturns as ot >>> productBasis = ot.OrthogonalProductPolynomialFactory([ot.HermiteFactory()]) >>> adaptiveStrategy = ot.FixedStrategy(productBasis, 3) >>> adaptiveStrategy.computeInitialBasis() >>> print(adaptiveStrategy.getPsi()) [1,x0,-0.707107 + 0.707107 * x0^2]
- getSignificanceFactor()¶
Accessor to the significance factor.
- Returns:
- significanceFactorfloat
Value of the significance factor.
See also
- hasName()¶
Test if the object is named.
- Returns:
- hasNamebool
True if the name is not empty.
- involvesModelSelection()¶
Get the model selection flag.
A model selection method can be used to select the coefficients of the decomposition which enable to best predict the output. Model selection can lead to a sparse functional chaos expansion.
- Returns:
- involvesModelSelection: bool
True if the method involves a model selection method.
- setMaximumDimension(maximumDimension)¶
Accessor to the maximum dimension of the orthogonal basis.
- Parameters:
- maximumDimensionint
Maximum dimension of the truncated basis.
- setMaximumSize(maximumSize)¶
Accessor to the maximum size of the orthogonal basis.
- Parameters:
- maximumSizeint
Maximum number of significant terms of the basis.
See also
- setName(name)¶
Accessor to the object’s name.
- Parameters:
- namestr
The name of the object.
- setSignificanceFactor(significanceFactor)¶
Accessor to the significance factor.
- Parameters:
- significanceFactorfloat
Value of the significance factor.
See also
- updateBasis(alpha_k, residual, relativeError)¶
Update the basis for the next iteration of approximation.
In this strategy, the residual and the relativeError input arguments are ignored.
- Parameters:
- alpha_ksequence of floats
The coefficients of the expansion at this step.
- residualfloat
The current value of the residual. Ignored.
- relativeErrorfloat
The relative error. Ignored.
Examples
>>> import openturns as ot >>> dimension = 3 >>> enumerateFunction = ot.LinearEnumerateFunction(dimension) >>> productBasis = ot.OrthogonalProductPolynomialFactory( ... [ot.LegendreFactory()] * dimension, enumerateFunction ... ) >>> degree = 6 >>> basisSize = enumerateFunction.getBasisSizeFromTotalDegree(degree) >>> maximumDimension = 100 >>> maximumSize = 20 >>> significanceFactor = 1e-4 >>> adaptiveStrategy = ot.CleaningStrategy( ... productBasis, maximumDimension, maximumSize, significanceFactor ... ) >>> adaptiveStrategy.computeInitialBasis() >>> print(adaptiveStrategy.getCurrentVectorIndex()) 20 >>> psi = adaptiveStrategy.getPsi() >>> print(len(psi)) 20 >>> alpha_k = [3.5, 0.1, 0.0, -0.2, 0.0, 0.3, 0.0, -0.4, 0.0, -0.5] >>> residual = 0.0 # Ignored >>> relativeError = 0.0 # Ignored >>> adaptiveStrategy.updateBasis(alpha_k, residual, relativeError) >>> psi = adaptiveStrategy.getPsi() >>> print(len(psi)) 7
Examples using the class¶
Advanced polynomial chaos construction
Create a sparse chaos by integration