File: t_RankSobolSensitivityAlgorithm_std.py

package info (click to toggle)
openturns 1.26-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 67,708 kB
  • sloc: cpp: 261,605; python: 67,030; ansic: 4,378; javascript: 406; sh: 185; xml: 164; makefile: 101
file content (45 lines) | stat: -rwxr-xr-x 1,645 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
#!/usr/bin/env python

import openturns as ot
from openturns.testing import assert_almost_equal
from openturns.usecases import ishigami_function

ot.RandomGenerator.SetSeed(0)
im = ishigami_function.IshigamiModel()
input_names = im.distribution.getDescription()
n = 250
sampleX = im.distribution.getSample(n)
sampleY = im.model(sampleX)

ot.ResourceMap.SetAsUnsignedInteger("SobolIndicesAlgorithm-DefaultBootstrapSize", 100)

ot.RandomGenerator.SetSeed(42)  # Set seed for bootstrap interval computation algorithm
mySobol = ot.RankSobolSensitivityAlgorithm(sampleX, sampleY)
indices = mySobol.getFirstOrderIndices()
assert_almost_equal(indices, [0.208654, 0.493591, -0.0669488], 1.0e-4, 1.0e-2)

interval = mySobol.getFirstOrderIndicesInterval()
assert_almost_equal(
    interval.getLowerBound(), [0.107531, 0.406036, -0.195595], 1.0e-4, 1.0e-2
)
assert_almost_equal(
    interval.getUpperBound(), [0.328238, 0.569699, 0.0936075], 1.0e-4, 1.0e-2
)

# Testing that we still get the same results when using setDesign
normal = ot.Normal()
mySobol2 = ot.RankSobolSensitivityAlgorithm(normal.getSample(10),
                                            normal.getSample(10))
ot.RandomGenerator.SetSeed(42)
mySobol2.setDesign(sampleX, sampleY, sampleX.getSize())

indices2 = mySobol2.getFirstOrderIndices()
interval2 = mySobol2.getFirstOrderIndicesInterval()

assert_almost_equal(indices2, indices, 0, ot.SpecFunc.ScalarEpsilon)
assert_almost_equal(
    interval2.getLowerBound(), interval.getLowerBound(), 0,
    ot.SpecFunc.ScalarEpsilon)
assert_almost_equal(
    interval2.getUpperBound(), interval.getUpperBound(), 0,
    ot.SpecFunc.ScalarEpsilon)