File: t_MaximumDistribution_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 (99 lines) | stat: -rwxr-xr-x 3,535 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#! /usr/bin/env python

import openturns as ot
import openturns.testing as ott

ot.TESTPREAMBLE()

# First constructor: distribution of the maximum of the components
# of a random vector given its joint distribution
# Second constructor: distribution of the maximum of independent
# random variables given their distributions
# Third constructor: distribution of the maximum of independent
# identically distributed random variables
R = ot.CorrelationMatrix(3)
R[0, 1] = 0.5
coll = [
    ot.MaximumDistribution(ot.Normal(5)),
    ot.MaximumDistribution([ot.Normal()] * 5),
    ot.MaximumDistribution(ot.Normal(), 5),
    ot.MaximumDistribution(ot.Normal([0.0] * 3, [1.0] * 3, R)),
]
for index, distribution in enumerate(coll):
    print("Distribution ", distribution)

    # Is this distribution elliptical ?
    print("Elliptical = ", distribution.isElliptical())

    # Is this distribution continuous ?
    print("Continuous = ", distribution.isContinuous())

    # Confidence regions
    (
        interval,
        threshold,
    ) = distribution.computeMinimumVolumeIntervalWithMarginalProbability(0.95)
    if index < 3:
        ott.assert_almost_equal(interval.getLowerBound(), [-0.11278], 1e-4, 0.0)
        ott.assert_almost_equal(interval.getUpperBound(), [2.50221], 1e-4, 0.0)
    else:
        ott.assert_almost_equal(interval.getLowerBound(), [-0.770165], 1e-4, 0.0)
        ott.assert_almost_equal(interval.getUpperBound(), [2.33536], 1e-4, 0.0)
    print("threshold=", threshold)

    levelSet, beta = distribution.computeMinimumVolumeLevelSetWithThreshold(0.95)
    print("Minimum volume level set=", levelSet)
    print("beta=%.5g" % beta)

    (
        interval,
        beta,
    ) = distribution.computeBilateralConfidenceIntervalWithMarginalProbability(0.95)
    print("Bilateral confidence interval=", interval)
    print("beta=%.5g" % beta)

    (
        interval,
        beta,
    ) = distribution.computeUnilateralConfidenceIntervalWithMarginalProbability(
        0.95, False
    )
    if index < 3:
        ott.assert_almost_equal(interval.getLowerBound(), [-7.65063], 1e-4, 0.0)
        ott.assert_almost_equal(interval.getUpperBound(), [2.31868], 1e-4, 0.0)
    else:
        ott.assert_almost_equal(interval.getLowerBound(), [-7.65063], 1e-4, 0.0)
        ott.assert_almost_equal(interval.getUpperBound(), [2.10094], 1e-4, 0.0)
    print("beta=%.5g" % beta)

    (
        interval,
        beta,
    ) = distribution.computeUnilateralConfidenceIntervalWithMarginalProbability(
        0.95, True
    )
    if index < 3:
        ott.assert_almost_equal(interval.getLowerBound(), [0.123843], 1e-4, 0.0)
        ott.assert_almost_equal(interval.getUpperBound(), [7.65063], 1e-4, 0.0)
    else:
        ott.assert_almost_equal(interval.getLowerBound(), [-0.502767], 1e-4, 0.0)
        ott.assert_almost_equal(interval.getUpperBound(), [7.65063], 1e-4, 0.0)
    print("beta=%.5g" % beta)

    spearman = distribution.getSpearmanCorrelation()
    print("spearman=", spearman)
    kendall = distribution.getKendallTau()
    print("kendall=", kendall)
    print("Standard representative=", distribution.getStandardRepresentative())

    ot.Log.Show(ot.Log.TRACE)
    ot.RandomGenerator.SetSeed(1234)
    validation = ott.DistributionValidation(distribution)
    validation.skipEntropy()  # slow
    validation.skipMinimumVolumeLevelSet()  # slow
    validation.run()

# Issue #1643
coll = [ot.Uniform(), ot.Normal()]
distribution = ot.MaximumDistribution(coll)
print("%.5g" % distribution.computePDF([1.1]))