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
|
{{ 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)
title = None
if "{{ objname }}" == "Bernoulli":
distribution = ot.Bernoulli(0.7)
elif "{{ objname }}" == "Binomial":
distribution = ot.Binomial(5, 0.2)
elif "{{ objname }}" == "Hypergeometric":
distribution = ot.Hypergeometric(10, 4, 7)
elif "{{ objname }}" == "CumulativeDistributionNetwork":
coll = [ot.Normal(2),ot.Dirichlet([0.5, 1.0, 1.5])]
distribution = ot.CumulativeDistributionNetwork(coll, ot.BipartiteGraph([[0,1], [0,1]]))
elif "{{ objname }}" == "Histogram":
distribution = ot.Histogram([-1.0, 0.5, 1.0, 2.0], [0.45, 0.4, 0.15])
elif "{{ objname }}" == "KernelMixture":
kernel = ot.Uniform()
sample = ot.Normal().getSample(5)
bandwidth = [1.0]
distribution = ot.KernelMixture(kernel, bandwidth, sample)
elif "{{ objname }}" == "MaximumDistribution":
coll = [ot.Uniform(2.5, 3.5), ot.LogUniform(1.0, 1.2), ot.Triangular(2.0, 3.0, 4.0)]
distribution = ot.MaximumDistribution(coll)
elif "{{ objname }}" == "Multinomial":
distribution = ot.Multinomial(5, [0.2])
elif "{{ objname }}" == "RandomMixture":
coll = [ot.Triangular(0.0, 1.0, 5.0), ot.Uniform(-2.0, 2.0)]
weights = [0.8, 0.2]
cst = 3.0
distribution = ot.RandomMixture(coll, weights, cst)
elif "{{ objname }}" == "SmoothedUniform":
distribution = ot.SmoothedUniform(-1.0, 10.0, 1.0)
elif "{{ objname }}" == "TruncatedDistribution":
distribution = ot.TruncatedDistribution(ot.Normal(2.0, 1.5), 1.0, 4.0)
elif "{{ objname }}" == "UserDefined":
distribution = ot.UserDefined([[1.0], [2.0], [3.0]], [0.4, 0.5, 1.0])
elif "{{ objname }}" == "ZipfMandelbrot":
distribution = ot.ZipfMandelbrot(10, 2.5, 0.3)
elif "{{ objname }}" == "Normal":
cov = ot.CovarianceMatrix([[1.0, -0.5], [-0.5, 1.0]])
distribution = ot.Normal([0.0, 0.0], cov)
title = "Normal dist. with correlation coefficient {}".format(cov[0, 1])
else:
distribution = ot.{{ objname }}()
dimension = distribution.getDimension()
if title is None:
title = str(distribution)[:100].split("\n")[0]
if dimension == 1:
distribution.setDescription(["$x$"])
pdf_graph = distribution.drawPDF()
cdf_graph = distribution.drawCDF()
fig = plt.figure(figsize=(10, 4))
pdf_axis = fig.add_subplot(121)
cdf_axis = fig.add_subplot(122)
otv.View(pdf_graph, figure=fig, axes=[pdf_axis], add_legend=False)
otv.View(cdf_graph, figure=fig, axes=[cdf_axis], add_legend=False)
fig.suptitle(title)
elif dimension == 2:
grid = ot.GridLayout(1, 2)
pdf_graph = distribution.drawPDF()
pdf_contour = pdf_graph.getDrawable(0).getImplementation()
pdf_contour.setColorBarPosition("")
pdf_contour.setColorMapNorm("rank")
pdf_graph.setDrawable(0, pdf_contour)
cdf_graph = distribution.drawCDF()
cdf_contour = cdf_graph.getDrawable(0).getImplementation()
cdf_contour.setColorBarPosition("")
cdf_contour.setColorMapNorm("rank")
cdf_graph.setDrawable(0, cdf_contour)
grid.setGraph(0, 0, pdf_graph)
grid.setGraph(0, 1, cdf_graph)
grid.setTitle(title)
fig = otv.View(grid).getFigure()
fig.axes[0].set_title("PDF")
fig.axes[1].set_title("CDF")
.. currentmodule:: {{ module }}
.. autoclass:: {{ objname }}
:exclude-members: __call__, thisown
{% block methods %}
.. automethod:: __init__
{% endblock %}
.. minigallery:: {{module}}.{{objname}}
:add-heading: Examples using the class
|