import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View if ot.Rayleigh().__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.Rayleigh().__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.Rayleigh().__class__.__name__ == 'Histogram': distribution = ot.Histogram([-1.0, 0.5, 1.0, 2.0], [0.45, 0.4, 0.15]) else: distribution = ot.Rayleigh() 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() fig = plt.figure(figsize=(10, 5)) plt.suptitle(str(distribution))
import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View if ot.Rayleigh().__class__.__name__ == 'Bernoulli': distribution = ot.Bernoulli(0.7) elif ot.Rayleigh().__class__.__name__ == 'Binomial': distribution = ot.Binomial(5, 0.2) elif ot.Rayleigh().__class__.__name__ == 'ComposedDistribution': copula = ot.IndependentCopula(2) marginals = [ot.Uniform(1.0, 2.0), ot.Normal(2.0, 3.0)] distribution = ot.ComposedDistribution(marginals, copula) elif ot.Rayleigh().__class__.__name__ == 'CumulativeDistributionNetwork': coll = [ot.Normal(2), ot.Dirichlet([0.5, 1.0, 1.5])] distribution = ot.CumulativeDistributionNetwork( coll, ot.BipartiteGraph([[0, 1], [0, 1]])) elif ot.Rayleigh().__class__.__name__ == 'Histogram': distribution = ot.Histogram([-1.0, 0.5, 1.0, 2.0], [0.45, 0.4, 0.15]) elif ot.Rayleigh().__class__.__name__ == 'KernelMixture': kernel = ot.Uniform() sample = ot.Normal().getSample(5) bandwith = [1.0] distribution = ot.KernelMixture(kernel, bandwith, sample) elif ot.Rayleigh().__class__.__name__ == '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 ot.Rayleigh().__class__.__name__ == 'Multinomial': distribution = ot.Multinomial(5, [0.2])
def clean(polynomial): coefficients = polynomial.getCoefficients() for i in range(coefficients.getDimension()): if abs(coefficients[i]) < 1.0e-12: coefficients[i] = 0.0 return ot.UniVariatePolynomial(coefficients) iMax = 5 distributionCollection = [ ot.Laplace(1.0, 0.0), ot.Logistic(0.0, 1.0), ot.Normal(0.0, 1.0), ot.Normal(1.0, 1.0), ot.Rayleigh(1.0), ot.Student(22.0), ot.Triangular(-1.0, 0.3, 1.0), ot.Uniform(-1.0, 1.0), ot.Uniform(-1.0, 3.0), ot.Weibull(1.0, 3.0), ot.Beta(1.0, 3.0, -1.0, 1.0), ot.Beta(0.5, 1.0, -1.0, 1.0), ot.Beta(0.5, 1.0, -2.0, 3.0), ot.Gamma(1.0, 3.0), ot.Arcsine() ] for n in range(len(distributionCollection)): distribution = distributionCollection[n] name = distribution.getClassName() polynomialFactory = ot.StandardDistributionPolynomialFactory(
import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View if (ot.Rayleigh().__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.Rayleigh().__class__.__name__ == 'CumulativeDistributionNetwork'): distribution = ot.CumulativeDistributionNetwork( [ot.Normal(2), ot.Dirichlet([0.5, 1.0, 1.5])], ot.BipartiteGraph([[0, 1], [0, 1]])) else: distribution = ot.Rayleigh() dimension = distribution.getDimension() if dimension <= 2: if distribution.getDimension() == 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) else: distribution.setDescription(['$x_1$', '$x_2$']) pdf_graph = distribution.drawPDF() fig = plt.figure(figsize=(10, 5))