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.
from uqpylab import sessions
import numpy as np
Start a remote UQCloud session¶
# 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¶
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:
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:
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:
myInput = uq.createInput(InputOpts)
PCEOpts = {
'Type': 'Metamodel',
'MetaType': 'PCE'
}
Specify the computational model to create an experimental design:
PCEOpts['FullModel'] = myModel['Name']
Specify degree-adaptive PCE (default: sparse PCE):
PCEOpts['Degree'] = np.arange(1,5).tolist()
Specify the parameters for the PCE truncation scheme:
PCEOpts['TruncOptions'] = {
'qNorm': 0.7,
'MaxInteraction': 2
}
Specify an experimental design of size $1'200$ based on the latin hypercube sampling (LHS):
PCEOpts['ExpDesign'] = {
'NSamples': 1200,
'Sampling': 'LHS'
}
Create the PCE metamodel:
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:
SobolOpts = {
'Type': 'Sensitivity',
'Method': 'Sobol'
}
Set the maximum Sobol' indices order:
SobolOpts['Sobol'] = {
'Order': 2
}
Run the sensitivity analysis:
mySobolAnalysisPCE = uq.createAnalysis(SobolOpts)
5 - RESULTS VISUALIZATION¶
Display a graphical representation of the results:
uq.display(mySobolAnalysisPCE);
Terminate the remote UQCloud session¶
mySession.quit()
uqpylab.sessions :: INFO :: Session e264d87c69bc4e31a41ecabbf14299a6 terminated.
True