File: t_Distribution_draw.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 (124 lines) | stat: -rwxr-xr-x 3,547 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#! /usr/bin/env python

import openturns as ot
import os

ot.TESTPREAMBLE()
pointNumber = 251


dist1D = ot.Normal(2.0, 4.0)
dist2D = ot.Normal(ot.Point(2, 2.0), ot.Point(2, 4.0), ot.CorrelationMatrix(2))
distND = ot.Normal(ot.Point(5, 2.0), ot.Point(5, 4.0), ot.CorrelationMatrix(5))
# Check drawing methods for 1D distributions
# PDF
graphPDF = dist1D.drawPDF()
graphPDF = dist1D.drawPDF(-4.0, 4.0, 101)
graphPDF = dist1D.drawPDF(-4.0, 4.0)
graphPDF = dist1D.drawPDF(101)
# log-PDF
graphLogPDF = dist1D.drawLogPDF()
graphLogPDF = dist1D.drawLogPDF(-4.0, 4.0, 101)
graphLogPDF = dist1D.drawLogPDF(-4.0, 4.0)
graphLogPDF = dist1D.drawLogPDF(101)
# CDF
graphCDF = dist1D.drawCDF()
graphCDF = dist1D.drawCDF(-4.0, 4.0, 101)
graphCDF = dist1D.drawCDF(-4.0, 4.0)
graphCDF = dist1D.drawCDF(101)
# Check drawing methods for 2D distributions
# PDF
graphPDF = dist2D.drawPDF()
graphPDF = dist2D.drawPDF([-4.0, -4.0], [4.0, 4.0], [101, 101])
graphPDF = dist2D.drawPDF([-4.0, -4.0], [4.0, 4.0])
graphPDF = dist2D.drawPDF([101, 101])
# log-PDF
graphLogPDF = dist2D.drawLogPDF()
graphLogPDF = dist2D.drawLogPDF([-4.0, -4.0], [4.0, 4.0], [101, 101])
graphLogPDF = dist2D.drawLogPDF([-4.0, -4.0], [4.0, 4.0])
graphLogPDF = dist2D.drawLogPDF([101, 101])
# CDF
graphCDF = dist2D.drawCDF()
graphCDF = dist2D.drawCDF([-4.0, -4.0], [4.0, 4.0], [101, 101])
graphCDF = dist2D.drawCDF([-4.0, -4.0], [4.0, 4.0])
graphCDF = dist2D.drawCDF([101, 101])

# Save and load objects
if ot.PlatformInfo.HasFeature("libxml2"):
    study = ot.Study()
    file = "study_distribution_draw.xml"
    study.setStorageManager(ot.XMLStorageManager(file))
    study.add("pdf", distND.getPDF())
    study.add("logpdf", distND.getLogPDF())
    study.add("cdf", distND.getCDF())
    study.save()

    study = ot.Study()
    study.setStorageManager(ot.XMLStorageManager(file))
    study.load()
    pdf = ot.Function()
    logpdf = ot.Function()
    cdf = ot.Function()
    study.fillObject("pdf", pdf)
    study.fillObject("logpdf", logpdf)
    study.fillObject("cdf", cdf)
    os.remove(file)
else:
    pdf = distND.getPDF()
    logpdf = distND.getLogPDF()
    cdf = distND.getCDF()

# Check drawing methods for ND distributions
# PDF
graphPDF = distND.drawMarginal1DPDF(2, -4.0, 4.0, 101)
graphPDF = distND.drawMarginal2DPDF(2, 3, [-4.0, -4.0], [4.0, 4.0], [101, 101])
pdf.drawCrossCuts(
    ot.Point(5, 0.0),
    ot.Point(5, -4.0),
    ot.Point(5, 4.0),
    ot.Indices(5, 10),
    True,
    False,
    0.0,
    1e-5,
)
# log-PDF
graphLogPDF = distND.drawMarginal1DLogPDF(2, -4.0, 4.0, 101)
graphLogPDF = distND.drawMarginal2DLogPDF(2, 3, [-4.0, -4.0], [4.0, 4.0], [101, 101])
logpdf.drawCrossCuts(
    ot.Point(5, 0.0),
    ot.Point(5, -4.0),
    ot.Point(5, 4.0),
    ot.Indices(5, 10),
    True,
    False,
    -14.0,
    -11.0,
)
# CDF
graphCDF = distND.drawMarginal1DCDF(2, -4.0, 4.0, 101)
graphCDF = distND.drawMarginal2DCDF(2, 3, [-4.0, -4.0], [4.0, 4.0], [101, 101])
cdf.drawCrossCuts(
    ot.Point(5, 0.0),
    ot.Point(5, -4.0),
    ot.Point(5, 4.0),
    ot.Indices(5, 10),
    False,
    True,
    0.0,
    1e-2,
)
# Quantile
graphQuantile = dist1D.drawQuantile()
graphQuantile = dist2D.drawQuantile()

# dependence functions
copula = ot.FrankCopula()
graph1 = copula.drawUpperTailDependenceFunction()
graph2 = copula.drawUpperExtremalDependenceFunction()
graph3 = copula.drawLowerTailDependenceFunction()
graph4 = copula.drawLowerExtremalDependenceFunction()

# 2d / discrete
dist_2d_discrete = ot.JointDistribution([ot.Geometric(0.5)] * 2)
graphPDF = dist_2d_discrete.drawPDF()