File: t_ExperimentIntegration_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 (54 lines) | stat: -rw-r--r-- 2,017 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
#! /usr/bin/env python

import openturns as ot
import openturns.testing as ott
import math
from openturns.usecases import ishigami_function
import openturns.experimental as otexp

ot.TESTPREAMBLE()

# Test integrate
im = ishigami_function.IshigamiModel()
sampleSize = 100000
experiment = ot.MonteCarloExperiment(im.inputDistribution, sampleSize)
integration = otexp.ExperimentIntegration(experiment)
approximatedOutputMean = integration.integrate(im.model)
rtol = 0.0
atol = 1.0 / math.sqrt(sampleSize)
assert approximatedOutputMean.getDimension() == 1
ott.assert_almost_equal(approximatedOutputMean[0], im.expectation, rtol, atol)

# Test computeL2Norm
im = ishigami_function.IshigamiModel()
centeredIshigamiFunction = ot.SymbolicFunction(
    ["x1", "x2", "x3"], ["sin(x1) + 7 * (sin(x2)) ^ 2 + 0.1 * x3^4 * sin(x1) - 3.5"]
)
functionNorm = integration.computeL2Norm(centeredIshigamiFunction)
exactFunctionNorm = math.sqrt(im.variance)
rtol = 0.0
atol = 10.0 / math.sqrt(sampleSize)
ott.assert_almost_equal(functionNorm[0], exactFunctionNorm, rtol, atol)

# Test compute error
im = ishigami_function.IshigamiModel()
partOfIshigamiFunction = ot.SymbolicFunction(
    ["x1", "x2", "x3"], ["7 * (sin(x2)) ^ 2 + 0.1 * x3^4 * sin(x1)"]
)
functionError = integration.computeL2Norm(im.model - partOfIshigamiFunction)
exactError = math.sqrt(0.5)
rtol = 0.0
atol = 10.0 / math.sqrt(sampleSize)
ott.assert_almost_equal(functionError[0], exactError, rtol, atol)

# Test integrate with multi-variate output
functionCollection = [im.model, im.model, im.model]
multivariateIshigami = ot.AggregatedFunction(functionCollection)
experiment = ot.MonteCarloExperiment(im.inputDistribution, sampleSize)
integration = otexp.ExperimentIntegration(experiment)
approximatedOutputMean = integration.integrate(multivariateIshigami)
rtol = 0.0
atol = 10.0 / math.sqrt(sampleSize)
assert approximatedOutputMean.getDimension() == 3
exactIntegral = [im.expectation] * 3
ott.assert_almost_equal(approximatedOutputMean, exactIntegral, rtol, atol)