File: t_IterativeThreshold_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 (50 lines) | stat: -rwxr-xr-x 1,736 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
#! /usr/bin/env python

import openturns as ot
import openturns.testing as ott

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

ot.RandomGenerator.SetSeed(0)

# We create a Sample
point1 = [10.0, 20.0]
point2 = [11.0, 21.0]
point3 = [12.0, 22.0]
sample1 = [point1, point2, point3]
referencethreshold = [0, 3]

# Iterative threshold, one point at a time
dimension = 2
algo = ot.IterativeThresholdExceedance(dimension, ot.Greater(), 15.0)
algo.increment(point1)
algo.increment(point2)
algo.increment(point3)
computedthreshold = algo.getThresholdExceedance()
ott.assert_almost_equal(referencethreshold, computedthreshold)
iteration = algo.getIterationNumber()
ott.assert_almost_equal(iteration, 3)
algo.increment([20.0, 10.0])
ratio = algo.getRatio()
ott.assert_almost_equal(ratio, [0.25, 0.75])

# Iterative threshold, one single sample
iterthresholdSample = ot.IterativeThresholdExceedance(dimension, ot.Greater(), 15.0)
iterthresholdSample.increment(sample1)
computedthreshold = iterthresholdSample.getThresholdExceedance()
ott.assert_almost_equal(referencethreshold, computedthreshold)
iteration = iterthresholdSample.getIterationNumber()
ott.assert_almost_equal(iteration, 3)

# Iterative threshold, one single sample, then one point at a time
iterthresholdMixed = ot.IterativeThresholdExceedance(dimension, ot.Greater(), 15.0)
iterthresholdMixed.increment(sample1)
iterthresholdMixed.increment(point1)
iterthresholdMixed.increment(point2)
iterthresholdMixed.increment(point3)
computedthreshold = iterthresholdMixed.getThresholdExceedance()
referencethreshold = [0, 6]
ott.assert_almost_equal(referencethreshold, computedthreshold)
iteration = iterthresholdMixed.getIterationNumber()
ott.assert_almost_equal(iteration, 6)