import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View if ot.Triangular().__class__.__name__ == 'ComposedDistribution': correlation = ot.CorrelationMatrix(2) correlation[1, 0] = 0.25 aCopula = ot.NormalCopula(correlation) marginals = [ot.Normal(1.0, 2.0), ot.Normal(2.0, 3.0)] distribution = ot.ComposedDistribution(marginals, aCopula) elif ot.Triangular().__class__.__name__ == 'CumulativeDistributionNetwork': distribution = ot.CumulativeDistributionNetwork( [ot.Normal(2), ot.Dirichlet([0.5, 1.0, 1.5])], ot.BipartiteGraph([[0, 1], [0, 1]])) elif ot.Triangular().__class__.__name__ == 'Histogram': distribution = ot.Histogram([-1.0, 0.5, 1.0, 2.0], [0.45, 0.4, 0.15]) else: distribution = ot.Triangular() dimension = distribution.getDimension() if dimension == 1: distribution.setDescription(['$x$']) pdf_graph = distribution.drawPDF() cdf_graph = distribution.drawCDF() fig = plt.figure(figsize=(10, 4)) plt.suptitle(str(distribution)) pdf_axis = fig.add_subplot(121) cdf_axis = fig.add_subplot(122) View(pdf_graph, figure=fig, axes=[pdf_axis], add_legend=False) View(cdf_graph, figure=fig, axes=[cdf_axis], add_legend=False) elif dimension == 2: distribution.setDescription(['$x_1$', '$x_2$']) pdf_graph = distribution.drawPDF()
#! /usr/bin/env python from __future__ import print_function import openturns as ot ot.TESTPREAMBLE() try: l = [1.0, 0.7, 1.2, 0.9] h = [0.5, 1.5, 3.5, 2.5] distribution = ot.Histogram(-1.5, l, h) size = 10000 sample = distribution.getSample(size) factory = ot.HistogramFactory() estimatedDistribution = factory.build(sample) print("distribution=", repr(distribution)) print("Estimated distribution=", repr(estimatedDistribution)) estimatedDistribution = factory.build() print("Default distribution=", estimatedDistribution) estimatedHistogram = factory.buildAsHistogram(sample) print("Histogram =", distribution) print("Estimated histogram=", estimatedHistogram) estimatedHistogram = factory.buildAsHistogram(sample, 0.1) print("Histogram =", distribution) print("Estimated histogram=", estimatedHistogram) estimatedHistogram = factory.buildAsHistogram(sample, 15) print("Histogram =", distribution) print("Estimated histogram=", estimatedHistogram) first = -2. width = ot.Point(5, 1.) estimatedHistogram = factory.buildAsHistogram(sample, first, width)