SENSITIVITY: SOBOL' INDICES OF A HIGH-DIMENSIONAL FUNCTION¶

In this example, the first- and second-order Sobol' sensitivity indices for a high-dimensional ($M = 100$) non-linear analytical function are calculated by means of polynomial chaos expansion (PCE).

Note: This example runs a very high-dimensional analysis, it may take up between 2 to 3 minutes to complete.

1 - INITIALIZATION¶

Import python packages¶

In [1]:
from uqpylab import sessions
import numpy as np

Start a remote UQCloud session¶

In [2]:
# Start the session
mySession = sessions.cloud()
# (Optional) Get a convenient handle to the command line interface
uq = mySession.cli
# Reset the session
mySession.reset()
Processing .
.
 done!

 uqpylab.sessions :: INFO     :: This is UQ[py]Lab, version 1.00, running on https://uqcloud.ethz.ch. 
                                 UQ[py]Lab is free software, published under the open source BSD 3-clause license.
                                 To request special permissions, please contact:
                                  - Stefano Marelli (marelli@ibk.baug.ethz.ch).
                                 A new session (e264d87c69bc4e31a41ecabbf14299a6) started.
 uqpylab.sessions :: INFO     :: Reset successful.

Set the random seed for reproducibility¶

In [3]:
uq.rng(100, 'twister');

2 - Computational model¶

The high-dimensional function presented in this example is a non-linear arbitrary dimensional function (with input dimension $M >= 55$) defined as:

$$Y = 3 - \frac{5}{M} \sum_{k = 1}^{M} k x_k + \frac{1}{M}\sum_{k = 1}^{M} k x_k^3 + \ln\left(\frac{1}{3M}\sum_{k = 1}^{M} k (x_k^2 + x_k^4)\right) + x_1 x_2^2 + x_2 x_4 - x_3 x_5 + x_{50} + x_{50}x_{54}^2$$

If all the input variables are identically distributed, the sensitivity pattern of this function has an overall non-linearly increasing trend with the variable number. It also presents distinct peaks for variables $x_1$, $x_5$, $x_{50}$, and $x_{54}$. Furthermore, four 2-term interaction peaks are expected: $x_1 x_2$, $x_2 x_4$, $x_3 x_5$, and $x_{50} x_{54}$. Finally, by construction, each pair of interaction terms $x_1 x_2$, $x_{50} x_{54}$ and $x_2 x_4$, $x_{3} x_{5}$ are expected to have identical sensitivity indices, respectively.

This computation is carried out by the function uq_many_inputs_model(X) supplied with UQLab. The input parameters of this function are gathered into the vector X.

Create a MODEL object from the function file:

In [4]:
ModelOpts = {
    'Type': 'Model',
    'ModelFun': 'many_inputs.model'
}

myModel = uq.createModel(ModelOpts)

3 - PROBABILISTIC INPUT MODEL¶

The probabilistic input model consists of $100$ uniformly distributed random variables:

$$X_i \sim \mathcal{U}(1,2) \quad i = 1,\ldots,100, \; i \neq 20,$$

$$X_{20} \sim \mathcal{U}(1,3)$$

Specify the marginals of the input model:

In [5]:
M = 100

InputOpts = {'Marginals': []}

for ii in range(M):
    if ii == 19:
        InputOpts['Marginals'].append(
            {
                'Type': 'Uniform',
                'Parameters': [1, 3]
            }
        )
    else:
        InputOpts['Marginals'].append(
            {
                'Type': 'Uniform',
                'Parameters': [1, 2]
            }        
        )

Create an INPUT object based on the marginals:

In [6]:
myInput = uq.createInput(InputOpts)

4 - SENSITIVITY ANALYSIS¶

Due to the high dimensionality of the model, the Sobol' indices are directly calculated with polynomial chaos expansion (PCE).

4.1 Create a PCE of the full model¶

Select PCE as the metamodeling tool in UQpyLab:

In [7]:
PCEOpts = {
    'Type': 'Metamodel',
    'MetaType': 'PCE'
}

Specify the computational model to create an experimental design:

In [8]:
PCEOpts['FullModel'] = myModel['Name']

Specify degree-adaptive PCE (default: sparse PCE):

In [9]:
PCEOpts['Degree'] = np.arange(1,5).tolist()

Specify the parameters for the PCE truncation scheme:

In [10]:
PCEOpts['TruncOptions'] = {
    'qNorm': 0.7,
    'MaxInteraction': 2
}

Specify an experimental design of size $1'200$ based on the latin hypercube sampling (LHS):

In [11]:
PCEOpts['ExpDesign'] = {
    'NSamples': 1200,
    'Sampling': 'LHS'
}

Create the PCE metamodel:

In [12]:
myPCE = uq.createModel(PCEOpts)
 uqpylab.sessions :: INFO     :: Received intermediate compute request, function: many_inputs.model.
 uqpylab.sessions :: INFO     :: Carrying out local computation...
 uqpylab.sessions :: INFO     :: Local computation complete.
 uqpylab.sessions :: INFO     :: Starting transmission of intermediate compute results ((1200, 1))...
 uqpylab.sessions :: INFO     :: Intermediate compute results sent.
Processing .
.
.
.
.
.
 done!

4.2 Sensitivity analysis of the PCE metamodel¶

The sensitivity module automatically calculates the sensitivity indices from the PCE coefficients if the current model is a PCE metamodel.

Specify the sensitivity module and Sobol' indices:

In [13]:
SobolOpts = {
    'Type': 'Sensitivity',
    'Method': 'Sobol'
}

Set the maximum Sobol' indices order:

In [14]:
SobolOpts['Sobol'] = {
    'Order': 2
}

Run the sensitivity analysis:

In [15]:
mySobolAnalysisPCE = uq.createAnalysis(SobolOpts)

5 - RESULTS VISUALIZATION¶

Display a graphical representation of the results:

In [16]:
uq.display(mySobolAnalysisPCE);

Terminate the remote UQCloud session¶

In [17]:
mySession.quit()
 uqpylab.sessions :: INFO     :: Session e264d87c69bc4e31a41ecabbf14299a6 terminated.
Out[17]:
True