File: t_SimulationSensitivityAnalysis_std.py

package info (click to toggle)
openturns 1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 38,588 kB
  • ctags: 26,495
  • sloc: cpp: 144,032; python: 26,855; ansic: 7,868; sh: 419; makefile: 263; yacc: 123; lex: 44
file content (94 lines) | stat: -rwxr-xr-x 3,827 bytes parent folder | download
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#! /usr/bin/env python

from __future__ import print_function
from openturns import *

TESTPREAMBLE()
RandomGenerator.SetSeed(0)

try:
    # Uncertain parameters
    distribution = Normal(
        NumericalPoint(3, 1.0), NumericalPoint(3, 2.0), CorrelationMatrix(3))
    distribution.setName("Unnamed")
    # Model
    inputVar = Description(["x", "y", "z"])
    formulas = Description(["x-1.5*y+2*z"])
    outputVar = Description(["out"])
    f = NumericalMathFunction(inputVar, formulas)
    # Must activate the history mechanism if one want to perform sensitivity
    # analysis
    f.enableHistory()
    # Sampling
    size = 100
    inputSample = distribution.getSample(size)
    outputSample = f(inputSample)
    comparisonOperators = [Less(), LessOrEqual(), Greater(), GreaterOrEqual()]
    threshold = 3.0
    ResourceMap.SetAsUnsignedInteger(
        "SimulationSensitivityAnalysis-DefaultSampleMargin", 10)
    for i in range(4):
        algo = SimulationSensitivityAnalysis(
            inputSample, outputSample, distribution.getIsoProbabilisticTransformation(), comparisonOperators[i], threshold)
        print("algo=", algo)
        # Perform the analysis
        print("Mean point in event domain=",
              algo.computeMeanPointInEventDomain())
        print("Importance factors at ", threshold,
              " =", algo.computeImportanceFactors())
        print("Importance factors at ", 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)

        # Reset the history of the model
        f.clearHistory()

        # Analysis based on an event
        X = RandomVector(distribution)
        Y = RandomVector(f, X)
        event = Event(Y, comparisonOperators[i], threshold)
        # Get a sample of the event to simulate a Monte Carlo analysis. We
        # don't care of the result as the interesting values are stored in the
        # model history
        event.getSample(size)
        algo = SimulationSensitivityAnalysis(event)
        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)

except:
    import sys
    print("t_SimulationSensitivityAnalysis_std.py",
          sys.exc_info()[0], sys.exc_info()[1])