File: t_ishigami_function.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 (67 lines) | stat: -rwxr-xr-x 1,602 bytes parent folder | download | duplicates (2)
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
#! /usr/bin/env python

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


ot.TESTPREAMBLE()
ot.PlatformInfo.SetNumericalPrecision(5)

"""
Test the import of the IshigamiModel data class.
"""
im = ishigami_function.IshigamiModel()
a = 7.0
b = 0.1

# parameters
assert_almost_equal(im.dim, 3, 1e-12)
assert_almost_equal(im.a, a, 1e-12)
assert_almost_equal(im.b, b, 1e-12)

# marginals means
assert_almost_equal(im.X1.getMean()[0], 0.0, 1e-12)
assert_almost_equal(im.X2.getMean()[0], 0.0, 1e-12)
assert_almost_equal(im.X3.getMean()[0], 0.0, 1e-12)

# special value
X = ot.Point([pi / 2, pi / 2, 1.0])
assert_almost_equal(im.model(X), [1.0 + a + b], 1e-12)

# First moments
expectation = a / 2.0
assert_almost_equal(im.expectation, expectation, 1e-12)

variance = 1.0 / 2 + a**2 / 8.0 + b * pi**4 / 5.0 + b**2 * pi**8 / 18.0
assert_almost_equal(im.variance, variance, 1e-12)


# Sobol indices
S1 = (1.0 / 2.0 + b * pi**4 / 5.0 + b**2 * pi**8 / 50.0) / variance
assert_almost_equal(im.S1, S1, 1e-12)

S2 = (a**2 / 8.0) / variance
assert_almost_equal(im.S2, S2, 1e-12)

assert_almost_equal(im.S3, 0.0, 1e-12)
assert_almost_equal(im.S12, 0.0, 1e-12)

S13 = b**2 * pi**8 / 2.0 * (1.0 / 9.0 - 1.0 / 25.0) / variance
assert_almost_equal(im.S13, S13, 1e-12)

S23 = 0.0
assert_almost_equal(im.S23, 0.0, 1e-12)

S123 = 0.0
assert_almost_equal(im.S123, 0.0, 1e-12)

ST1 = S1 + S13
assert_almost_equal(im.ST1, ST1, 1e-12)

ST2 = S2
assert_almost_equal(im.ST2, ST2, 1e-12)

ST3 = S13
assert_almost_equal(im.ST3, ST3, 1e-12)