File: t_SimulationSensitivityAnalysis_std.py

package info (click to toggle)
openturns 1.24-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 66,204 kB
  • sloc: cpp: 256,662; python: 63,381; ansic: 4,414; javascript: 406; sh: 180; xml: 164; yacc: 123; makefile: 98; lex: 55
file content (55 lines) | stat: -rwxr-xr-x 1,850 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /usr/bin/env python

import openturns as ot

ot.TESTPREAMBLE()


# Uncertain parameters
distribution = ot.Normal([1.0] * 3, [2.0] * 3, ot.CorrelationMatrix(3))
distribution.setName("Unnamed")
# Model
f = ot.SymbolicFunction(["x", "y", "z"], ["x-1.5*y+2*z"])
# Sampling
size = 100
inputSample = distribution.getSample(size)
outputSample = f(inputSample)
comparisonOperators = [ot.Less(), ot.LessOrEqual(), ot.Greater(), ot.GreaterOrEqual()]
threshold = 3.0
ot.ResourceMap.SetAsUnsignedInteger(
    "SimulationSensitivityAnalysis-DefaultSampleMargin", 10
)
for i in range(4):
    # Analysis based on an event
    X = ot.RandomVector(distribution)
    Y = ot.CompositeRandomVector(f, X)
    event = ot.ThresholdEvent(Y, comparisonOperators[i], threshold)
    algo = ot.SimulationSensitivityAnalysis(event, inputSample, outputSample)
    print("algo=", algo)
    # Perform the analysis
    print("Mean point in event domain=", algo.computeMeanPointInEventDomain())
    print(
        "Importance factors at threshold ",
        threshold,
        " =",
        algo.computeImportanceFactors(),
    )
    print(
        "Importance factors at threshold/2 ",
        threshold / 2,
        " =",
        algo.computeImportanceFactors(threshold / 2),
    )
    importanceFactorsGraph = algo.drawImportanceFactors()
    print("importanceFactorsGraph=", importanceFactorsGraph)

    # Importance factors evolution on probability scale
    importanceFactorsRangeGraphProbability = algo.drawImportanceFactorsRange()
    print(
        "importanceFactorsRangeGraphProbability=",
        importanceFactorsRangeGraphProbability,
    )

    # Importance factors evolution on threshold scale
    importanceFactorsRangeGraphThreshold = algo.drawImportanceFactorsRange(False)
    print("importanceFactorsRangeGraphThreshold=", importanceFactorsRangeGraphThreshold)