File: t_IterativeExtrema_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 (52 lines) | stat: -rwxr-xr-x 1,616 bytes parent folder | download | duplicates (3)
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
#! /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 = ot.Sample([point1, point2, point3])
referencemin = point1
referencemax = point3

# Iterative extrema, one point at a time
dimension = 2
iterPoint = ot.IterativeExtrema(dimension)
iterPoint.increment(point1)
iterPoint.increment(point2)
iterPoint.increment(point3)
computedmin = iterPoint.getMin()
computedmax = iterPoint.getMax()
ott.assert_almost_equal(referencemin, computedmin)
ott.assert_almost_equal(referencemax, computedmax)
iteration = iterPoint.getIterationNumber()
ott.assert_almost_equal(iteration, 3)

# Iterative extrema, one single sample
iterSample = ot.IterativeExtrema(dimension)
iterSample.increment(sample1)
computedmin = iterSample.getMin()
computedmax = iterSample.getMax()
ott.assert_almost_equal(referencemin, computedmin)
ott.assert_almost_equal(referencemax, computedmax)
iteration = iterSample.getIterationNumber()
ott.assert_almost_equal(iteration, 3)

# Iterative extrema, one single sample, then one point at a time
iterMixed = ot.IterativeExtrema(dimension)
iterMixed.increment(sample1)
iterMixed.increment(point1)
iterMixed.increment(point2)
iterMixed.increment(point3)
computedmin = iterMixed.getMin()
computedmax = iterMixed.getMax()
ott.assert_almost_equal(referencemin, computedmin)
ott.assert_almost_equal(referencemax, computedmax)
iteration = iterMixed.getIterationNumber()
ott.assert_almost_equal(iteration, 6)