File: t_ComposedDistribution_large.py

package info (click to toggle)
openturns 1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 38,588 kB
  • ctags: 26,495
  • sloc: cpp: 144,032; python: 26,855; ansic: 7,868; sh: 419; makefile: 263; yacc: 123; lex: 44
file content (79 lines) | stat: -rwxr-xr-x 2,543 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
#! /usr/bin/env python

from __future__ import print_function
from openturns import *

TESTPREAMBLE()
RandomGenerator.SetSeed(0)

try:

    meanPoint = NumericalPoint(1)
    meanPoint[0] = 1.0
    sigma = NumericalPoint(1)
    sigma[0] = 3.0
    R = CorrelationMatrix(1)
    R[0, 0] = 1.0

# Create a collection of distribution
    dimension = 2000
    print("Creating a composed distribution of dimension ", dimension)
    aCollection = DistributionCollection(
        dimension, Normal(meanPoint, sigma, R))
    for i in range(dimension):
        aCollection[i] = Normal(meanPoint, sigma, R)

# Create a a copula
    aCopula = IndependentCopula(dimension)

# Instanciate one distribution object
    distribution = ComposedDistribution(aCollection, aCopula)
    print("Distribution created.")

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

    # Has this distribution an elliptical copula?
    print("Elliptical copula = ", distribution.hasEllipticalCopula())

    # Has this distribution an independent copula?
    print("Independent copula = ",  distribution.hasIndependentCopula())

    # Test for sampling
    size = 10
    anotherSample = distribution.getSample(size)

    # Define a point
    zero = NumericalPoint(dimension, 0.0)

    # Show PDF and CDF of zero point
    zeroPDF = distribution.computePDF(zero)
    zeroCDF = distribution.computeCDF(zero)
    print(" pdf=%.6f" % zeroPDF, " cdf=%.6f" % zeroCDF)

    # Get 95% quantile
    quantile = distribution.computeQuantile(0.95)
    print("Quantile=", repr(quantile))
    print("CDF(quantile)=%.6f" % distribution.computeCDF(quantile))

    # Extract a 2-D marginal
    indices = Indices(2, 0)
    indices[0] = 1
    indices[1] = 0
    print("indices=", repr(indices))
    margins = distribution.getMarginal(indices)
    print("margins=", repr(margins))
    print("margins PDF=%.6f" % margins.computePDF(NumericalPoint(2)))
    print("margins CDF=%.6f" % margins.computeCDF(NumericalPoint(2)))
    quantile = NumericalPoint(margins.computeQuantile(0.5))
    print("margins quantile=", repr(quantile))
    print("margins CDF(qantile)=%.6f" % margins.computeCDF(quantile))
    print("margins realization=", repr(margins.getRealization()))
    sample = margins.getSample(1000)
    print("margins sample mean=", repr(sample.computeMean()))
    print("margins sample covariance=", repr(sample.computeCovariance()))

except:
    import sys
    print("t_ComposedDistribution_large.py",
          sys.exc_info()[0], sys.exc_info()[1])