SparseExpansion

class SparseExpansion(*args)

L2 approximation on an orthonormal basis using least-squares and sparse model selection.

Warning

This class is experimental and likely to be modified in future releases. To use it, import the openturns.experimental submodule.

This class builds a sparse polynomial chaos expansion by iteratively selecting basis functions using either Orthogonal Matching Pursuit (OMP) or Least Angle Regression (LARS), controlled by the selectionMethod parameter (default: "OMP").

The sample weights define the weighted inner product \langle u, v \rangle_w = \sum_{s=1}^n w_s u_s v_s and the associated weighted least-squares norm. Correlations, the initial constant term and the Gram matrix below are all weighted: the initial coefficient is the weighted mean of the output and the correlations read c_k = \langle \varphi_k, r \rangle_w.

OMP algorithm:

At each iteration, the basis function having the largest absolute correlation with the current residual is added to the active set. The coefficients are then updated by solving the least-squares problem restricted to the active set.

For each output marginal j, the algorithm starts with a constant approximation equal to the weighted mean of the output:

\widehat{y}_j = \beta_0

and the initial residual:

r = y_j - \beta_0

At each iteration i:

  1. Find k_i = \arg\max_k |\langle \varphi_k, r \rangle_w|

  2. Add \varphi_{k_i} to the active set

  3. Solve \beta = \arg\min \| y_j - \Phi_{\mathcal{A}} \beta \|_w^2

  4. Update the residual: r = y_j - \Phi_{\mathcal{A}} \beta

  5. Compute the cross-validation error using the FittingAlgorithm

LARS algorithm:

At each iteration, the algorithm computes an equiangular direction in the span of the active basis functions and steps along it until another inactive function’s correlation catches up. The coefficients of active functions change continuously along the path, unlike OMP which recomputes them from scratch at each step.

  1. Find k_i = \arg\max_k |\langle \varphi_k, r \rangle_w|

  2. Compute the equiangular direction u in \operatorname{span}(\Phi_{\mathcal{A}}) with respect to the weighted inner product (weighted Gram matrix)

  3. Determine the step size \gamma from the catch-up condition

  4. Update the prediction: \mu \mathrel{+}= \gamma u

  5. Compute the cross-validation error using the FittingAlgorithm

Stopping criteria:

Both algorithms stop when one of the following conditions is met:

  • The cross-validation error has increased for k consecutive iterations, where k is given by the SparseExpansion-ConsecutiveIncreases key in ResourceMap (default: 2)

  • The cross-validation error degrades by more than a factor \alpha compared to the best error so far

  • The cross-validation error exceeds an absolute maximum

  • The best cross-validation error falls below a threshold

Available constructors:

SparseExpansion(inputSample, outputSample, distribution)

SparseExpansion(inputSample, weights, outputSample, distribution)

SparseExpansion(inputSample, outputSample, distribution, basis, basisSize, methodName, fittingAlgorithm)

SparseExpansion(inputSample, weights, outputSample, distribution, basis, basisSize, methodName, fittingAlgorithm)

SparseExpansion(inputSample, outputSample, distribution, basis, basisSize, activeFunctions, methodName, fittingAlgorithm)

SparseExpansion(inputSample, weights, outputSample, distribution, basis, basisSize, activeFunctions, methodName, fittingAlgorithm)

Parameters:
inputSample2-d sequence of float of size n>0

Input sample.

weightsequence of float of size n>0, optional

Input weights. By default, a uniform weight equals to 1/n is used.

outputSample2-d sequence of floats of size n>0

Output sample.

distributionDistribution

The distribution associated to the weighted sample (inputSample, weights)

basisOrthogonalBasis, optional

The orthonormal basis of the vector space on which the approximation is built. By default, a basis is built using an hyperbolic enumerate function HyperbolicAnisotropicEnumerateFunction associated to the q- norm specified by the FunctionalChaosAlgorithm-QNorm key in ResourceMap. The basis is obtained through a tensorization of the univariate orthonormal polynomial bases associated to each marginal distributions of distribution.

basisSizeint, optional

The size of the basis on which the approximation is built. If not given, it is given by the FunctionalChaosAlgorithm-BasisSize key in ResourceMap if this value is positive, or as the cardinal of the set of basis functions up to a degree given by the FunctionalChaosAlgorithm-MaximumTotalDegree key in ResourceMap.

methodNamestr, optional

The decomposition method used to solve the least-squares problem, of type LeastSquaresMethod. If not given, it is given by the SparseExpansion-DecompositionMethod key in ResourceMap.

activeFunctionssequence of int, optional

The indices of the basis functions to use for the approximation. If not given, all functions from 0 to basisSize-1 are used. Must be non-empty and all indices must be less than basisSize.

fittingAlgorithmFittingAlgorithm, optional

The fitting algorithm used to compute the cross-validation error driving the basis selection. By default, it is a CorrectedLeaveOneOut.

Methods

BuildDistribution(inputSample)

Recover the distribution, with metamodel performance in mind.

getActiveFunctions()

Accessor to the active functions in the basis.

getAdaptiveStrategy()

Get the adaptive strategy.

getClassName()

Accessor to the object's name.

getDistribution()

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

getFittingAlgorithm()

Accessor to the fitting algorithm.

getInputSample()

Accessor to the input sample.

getMaximumResidual()

Get the maximum residual.

getName()

Accessor to the object's name.

getOutputSample()

Accessor to the output sample.

getProjectionStrategy()

Get the projection strategy.

getResult()

Get the results of the metamodel computation.

getSelectionMethod()

Accessor to the selection method.

getUseTransformation()

Transformation method flag accessor.

getWeights()

Return the weights of the input sample.

hasName()

Test if the object is named.

run()

Compute the metamodel.

setActiveFunctions(activeFunctions)

Accessor to the active functions in the basis.

setDistribution(distribution)

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

setFittingAlgorithm(fitting)

Accessor to the fitting algorithm.

setMaximumResidual(residual)

Set the maximum residual.

setName(name)

Accessor to the object's name.

setProjectionStrategy(projectionStrategy)

Set the projection strategy.

setSelectionMethod(method)

Accessor to the selection method.

setUseTransformation(useTransformation)

Transformation method flag accessor.

Notes

The following ResourceMap keys are used by this class:

  • SparseExpansion-DecompositionMethod (String, default: SVD): the default decomposition method used to solve the least-squares problem.

  • SparseExpansion-ConsecutiveIncreases (UnsignedInteger, default: 2): the number of consecutive increases in cross-validation error required before stopping the basis selection. Must be at least 1.

Examples

Solves a functional linear least squares approximation using residual minimization with QR method:

>>> import openturns as ot
>>> import openturns.experimental as otexp
>>> g = ot.SymbolicFunction('x', 'sin(x)')
>>> distribution = ot.Uniform(-2.0, 2.0)
>>> inSample = distribution.getSample(10)
>>> outSample = g(inSample)
>>> basis = ot.OrthogonalProductPolynomialFactory([ot.LegendreFactory()])
>>> basisSize = 5
>>> algo = otexp.SparseExpansion(inSample, outSample, distribution, basis, basisSize, 'QR')
>>> algo.run()
__init__(*args)
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 a nonparametric one.

The selection is done as follow:

  • We start with a list of all parametric models (all factories)

  • For each model, we estimate its parameters if feasible.

  • We check then if model is valid, ie if its Kolmogorov score exceeds a threshold fixed in the MetaModelAlgorithm-PValueThreshold ResourceMap key. Default value is 5%

  • We sort all valid models and return the one with the optimal criterion.

For the last step, the criterion might be BIC, AIC or AICC. The specification of the criterion is done through the MetaModelAlgorithm-ModelSelectionCriterion ResourceMap key. Default value is fixed to BIC. Note that if there is no valid candidate, we estimate a non-parametric model (KernelSmoothing or Histogram). The MetaModelAlgorithm-NonParametricModel ResourceMap key allows selecting the preferred one. Default value is Histogram

One each marginal is estimated, we use the Spearman independence test on each component pair to decide whether an independent copula. In case of non independence, we rely on a NormalCopula.

Parameters:
sampleSample

Input sample.

Returns:
distributionDistribution

Input distribution.

getActiveFunctions()

Accessor to the active functions in the basis.

Returns:
activeFunctionssequence of int

The indices of the functions used for the approximation in the basis.

getAdaptiveStrategy()

Get the adaptive strategy.

Returns:
adaptiveStrategyAdaptiveStrategy

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

getClassName()

Accessor to the object’s name.

Returns:
class_namestr

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

getDistribution()

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

Returns:
distributionDistribution

Joint probability density function of the physical input vector.

getFittingAlgorithm()

Accessor to the fitting algorithm.

Returns:
fittingAlgorithmFittingAlgorithm

Fitting algorithm used to estimate the cross-validation error.

getInputSample()

Accessor to the input sample.

Returns:
inputSampleSample

Input sample of a model evaluated apart.

getMaximumResidual()

Get the maximum residual.

Returns:
residualfloat

Residual value needed in the projection strategy.

Default value is 1e-06.

getName()

Accessor to the object’s name.

Returns:
namestr

The name of the object.

getOutputSample()

Accessor to the output sample.

Returns:
outputSampleSample

Output sample of a model evaluated apart.

getProjectionStrategy()

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()

Get the results of the metamodel computation.

Returns:
resultFunctionalChaosResult

Result structure, created by the method run().

getSelectionMethod()

Accessor to the selection method.

Returns:
methodstr

The selection method used for basis function selection. Either "OMP" for orthogonal matching pursuit or "LARS" for least angle regression.

getUseTransformation()

Transformation method flag accessor.

Returns:
useTransformationbool

Whether the transformation method is used.

Notes

The transformation method consists in using an isoprobabilistic transformation that maps the input distribution to the measure of the orthogonal basis. The basis is orthonormal with respect to the measure, and Sobol’ indices can be computed.

getWeights()

Return the weights of the input sample.

Returns:
weightssequence of float

The weights of the points in the input sample.

hasName()

Test if the object is named.

Returns:
hasNamebool

True if the name is not empty.

run()

Compute the metamodel.

Notes

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

setActiveFunctions(activeFunctions)

Accessor to the active functions in the basis.

Parameters:
activeFunctionssequence of int

The indices of the functions used for the approximation in the basis.

setDistribution(distribution)

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

Parameters:
distributionDistribution

Joint probability density function of the physical input vector.

setFittingAlgorithm(fitting)

Accessor to the fitting algorithm.

Parameters:
fittingAlgorithmFittingAlgorithm

Fitting algorithm used to estimate the cross-validation error.

setMaximumResidual(residual)

Set the maximum residual.

Parameters:
residualfloat

Residual value needed in the projection strategy.

Default value is 1e-06.

setName(name)

Accessor to the object’s name.

Parameters:
namestr

The name of the object.

setProjectionStrategy(projectionStrategy)

Set the projection strategy.

Parameters:
projectionStrategyProjectionStrategy

Strategy to estimate the coefficients a_k.

setSelectionMethod(method)

Accessor to the selection method.

Parameters:
methodstr

The selection method used for basis function selection. Either "OMP" for orthogonal matching pursuit or "LARS" for least angle regression.

setUseTransformation(useTransformation)

Transformation method flag accessor.

Parameters:
useTransformationbool

Whether to use the transformation method.

Notes

The transformation method consists in using an isoprobabilistic transformation that maps the input distribution to the measure of the orthogonal basis. The basis is orthonormal with respect to the measure, and Sobol’ indices can be computed.