Note
Go to the end to download the full example code.
Benchmark the Morris test function¶
import openturns as ot
import otbenchmark as otb
import openturns.viewer as otv
problem = otb.MorrisSensitivity()
print(problem)
name = Morris
distribution = JointDistribution(Uniform(a = 0, b = 1), Uniform(a = 0, b = 1), Uniform(a = 0, b = 1), Uniform(a = 0, b = 1), Uniform(a = 0, b = 1), Uniform(a = 0, b = 1), Uniform(a = 0, b = 1), Uniform(a = 0, b = 1), Uniform(a = 0, b = 1), Uniform(a = 0, b = 1), Uniform(a = 0, b = 1), Uniform(a = 0, b = 1), Uniform(a = 0, b = 1), Uniform(a = 0, b = 1), Uniform(a = 0, b = 1), Uniform(a = 0, b = 1), Uniform(a = 0, b = 1), Uniform(a = 0, b = 1), Uniform(a = 0, b = 1), Uniform(a = 0, b = 1), IndependentCopula(dimension = 20))
function = class=PythonEvaluation name=MorrisFunction
firstOrderIndices = [0.0061257,0.0068268,0.0148127,0.0097981,0.0125528,1.41e-05,0.0559007,0.141909,0.117441,0.123611,4.7e-06,3.06e-05,0.0014462,0.0044277,0.0001056,0.0002988,0.0018635,1.2e-06,9.32e-05,0.0006815]#20
totalOrderIndices = [0.245404,0.245113,0.105865,0.249405,0.103829,0.091275,0.0575356,0.144465,0.119821,0.126461,0.0016405,0.0014999,0.0028601,0.0068092,0.0018924,0.0029526,0.0032192,0.0018433,0.0015019,0.0019601]#20
distribution = problem.getInputDistribution()
model = problem.getFunction()
Exact first and total order
exact_first_order = problem.getFirstOrderIndices()
exact_first_order
exact_total_order = problem.getTotalOrderIndices()
exact_total_order
Plot the function¶
Create X/Y data
ot.RandomGenerator.SetSeed(0)
size = 200
inputDesign = ot.MonteCarloExperiment(distribution, size).generate()
outputDesign = model(inputDesign)
dimension = distribution.getDimension()
nbcolumns = 4
nbrows = int(dimension / nbcolumns)
grid = ot.GridLayout(nbrows, nbcolumns)
inputDescription = distribution.getDescription()
outputDescription = model.getOutputDescription()[0]
index = 0
for i in range(nbrows):
for j in range(nbcolumns):
graph = ot.Graph(
"n=%d" % (size), inputDescription[index], outputDescription, True, ""
)
sample = ot.Sample(size, 2)
sample[:, 0] = inputDesign[:, index]
sample[:, 1] = outputDesign[:, 0]
cloud = ot.Cloud(sample)
graph.add(cloud)
grid.setGraph(i, j, graph)
index += 1
_ = otv.View(grid, figure_kw={"figsize": (10.0, 10.0)})
# %
output_distribution = ot.KernelSmoothing().build(outputDesign)
_ = otv.View(output_distribution.drawPDF())
Perform sensitivity analysis¶
Create X/Y data
ot.RandomGenerator.SetSeed(0)
size = 30
inputDesign = ot.SobolIndicesExperiment(distribution, size).generate()
outputDesign = model(inputDesign)
Compute first order indices using the Saltelli estimator
sensitivityAnalysis = ot.SaltelliSensitivityAlgorithm(inputDesign, outputDesign, size)
computed_first_order = sensitivityAnalysis.getFirstOrderIndices()
computed_total_order = sensitivityAnalysis.getTotalOrderIndices()
Compare with exact results
print("Sample size : ", size)
# First order
# Compute absolute error (the LRE cannot be computed,
# because S can be zero)
print("Computed first order = ", computed_first_order)
print("Exact first order = ", exact_first_order)
# Total order
print("Computed total order = ", computed_total_order)
print("Exact total order = ", exact_total_order)
Sample size : 30
Computed first order = [0.0413107,0.341659,0.223284,0.226236,0.237565,0.0933184,0.254577,0.440998,0.230921,0.24593,0.199562,0.186567,0.212842,0.219807,0.217282,0.213096,0.207136,0.214633,0.212578,0.212067]#20
Exact first order = [0.0061257,0.0068268,0.0148127,0.0097981,0.0125528,1.41e-05,0.0559007,0.141909,0.117441,0.123611,4.7e-06,3.06e-05,0.0014462,0.0044277,0.0001056,0.0002988,0.0018635,1.2e-06,9.32e-05,0.0006815]#20
Computed total order = [0.332513,0.44494,0.32691,0.180088,-0.0418676,0.0326762,0.0128154,0.0742036,0.0663578,0.0987545,0.0137192,0.0174896,-0.0188307,0.000667087,0.0222983,-0.00491485,0.0154232,0.0015813,0.00707231,0.00853714]#20
Exact total order = [0.245404,0.245113,0.105865,0.249405,0.103829,0.091275,0.0575356,0.144465,0.119821,0.126461,0.0016405,0.0014999,0.0028601,0.0068092,0.0018924,0.0029526,0.0032192,0.0018433,0.0015019,0.0019601]#20
_ = otv.View(sensitivityAnalysis.draw())

otv.View.ShowAll()
Total running time of the script: (0 minutes 0.485 seconds)
otbenchmark

