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
|
{{ objname }} distribution
{{ underline }}{{ underline }}
.. plot::
:include-source: False
import openturns as ot
from matplotlib import pyplot as plt
import openturns.viewer as otv
ot.RandomGenerator.SetSeed(0)
if "{{ objname }}" == "BlockIndependentCopula":
distribution = ot.BlockIndependentCopula([ot.ClaytonCopula(2.0), ot.GumbelCopula(3.0)])
elif "{{ objname }}" == "JointDistribution":
R = ot.CorrelationMatrix(3)
R[0,1]=0.5
R[0,2]=0.3
R[1,2]=-0.2
copula = ot.NormalCopula(R)
marginals = [ot.Uniform(1.0, 2.0), ot.Normal(2.0, 3.0), ot.Gamma(5.5, 2.0)]
distribution = ot.JointDistribution(marginals, copula)
elif "{{ objname }}" == "BlockIndependentDistribution":
R = ot.CorrelationMatrix(2)
R[0,1]=0.5
atom1 = ot.JointDistribution([ot.Exponential(2.0), ot.WeibullMax(2.0, 2.0)], ot.NormalCopula(R))
atom2 = ot.JointDistribution([ot.Normal(2.0, 1.0), ot.Triangular(2.0, 3.0, 4.0)], ot.ClaytonCopula(3.0))
distribution = ot.BlockIndependentDistribution([atom1, atom2])
else:
distribution = ot.{{ objname }}()
dimension = distribution.getDimension()
mean = distribution.getMean()
std = distribution.getStandardDeviation()
xMin = distribution.getRange().getLowerBound()
xMax = distribution.getRange().getUpperBound()
xMin = [max(xMin[i], mean[i] - 3.0 * std[i]) for i in range(dimension)]
xMax = [min(xMax[i], mean[i] + 3.0 * std[i]) for i in range(dimension)]
size = 1000
sample = distribution.getSample(size)
sMin = sample.getMin()
sMax = sample.getMax()
xMin = [min(xMin[i], sMin[i]) for i in range(dimension)]
xMax = [max(xMax[i], sMax[i]) for i in range(dimension)]
n_rows = dimension
n_cols = dimension
fig = plt.figure(figsize=(10, 10))
for j in range(dimension):
for i in range(dimension):
pdf_axis = fig.add_subplot(n_rows, n_cols, j*dimension+i+1)
if i == j:
pdf_graph = distribution.drawMarginal1DPDF(i, xMin[i], xMax[i], 256)
else:
pdf_graph = distribution.drawMarginal2DPDF(i, j, [xMin[i], xMin[j]], [xMax[i], xMax[j]], [256]*2)
pdf_contour = pdf_graph.getDrawable(0).getImplementation()
pdf_contour.setColorBarPosition("")
pdf_contour.setColorMapNorm("rank")
pdf_graph.setDrawable(0, pdf_contour)
cloud = ot.Cloud(sample.getMarginal([i, j]))
cloud.setPointStyle("dot")
pdf_graph.add(cloud)
pdf_graph.setTitle("")
pdf_graph.setXTitle("")
pdf_graph.setYTitle("")
if i == 0:
pdf_graph.setYTitle(r"$x_" + str(j) + r"$")
if j == dimension-1:
pdf_graph.setXTitle(r"$x_" + str(i) + r"$")
otv.View(pdf_graph, figure=fig, axes=[pdf_axis], add_legend=False, square_axes=distribution.isCopula())
title = str(distribution)[:100].split("\n")[0]
fig.suptitle(title)
.. currentmodule:: {{ module }}
.. autoclass:: {{ objname }}
{% block methods %}
.. automethod:: __init__
{% endblock %}
.. minigallery:: {{module}}.{{objname}}
:add-heading: Examples using the class
|