def __init__(self, threshold=0.0, expo=1): """ Creates a reliability problem RP54. The event is {g(X) < threshold} where X = (x1, x2, ...., x20) g(X) = (x1 + x2 + ... + x20) - 8.951 Parameters ---------- threshold : float The threshold. expo : float Rate parameter of the Xi Exponential distribution for i in {1, 2, ..., 20}. """ formula = "x1+x2+x3+x4+x5+x6+x7+x8+x9+x10" formula = formula + " + x11+x12+x13+x14+x15+x16+x17+x18+x19+x20-8.951" print(formula) limitStateFunction = ot.SymbolicFunction( [ "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x18", "x19", "x20", ], [formula], ) X = [ot.Exponential(expo) for i in range(20)] myDistribution = ot.ComposedDistribution(X) inputRandomVector = ot.RandomVector(myDistribution) outputRandomVector = ot.CompositeRandomVector( limitStateFunction, inputRandomVector ) thresholdEvent = ot.ThresholdEvent(outputRandomVector, ot.Less(), threshold) name = "RP54" probability = 0.000998 super(ReliabilityProblem54, self).__init__(name, thresholdEvent, probability) return None
print('covariance (ref)=', repr( cleanCovariance(referenceDistribution[testCase].getCovariance()))) parameters = distribution[testCase].getParametersCollection() print('parameters =', repr(parameters)) print('parameters (ref)=', repr( referenceDistribution[testCase].getParametersCollection())) print('parameter =', repr(distribution[testCase].getParameter())) print('parameter desc =', repr(distribution[testCase].getParameterDescription())) print('marginal 0 =', repr(distribution[testCase].getMarginal(0))) for i in range(6): print('standard moment n=', i, ' value=', referenceDistribution[testCase].getStandardMoment(i)) print('Standard representative=', referenceDistribution[ testCase].getStandardRepresentative()) # Check simplification candidates = [ot.Normal(1.0, 2.0), ot.Uniform(1.0, 2.0), ot.Exponential(1.0, 2.0), ot.TruncatedDistribution(ot.Weibull(), 1.5, 7.8), ot.Beta(1.5, 7.8, -1.0, 2.0)] intervals = [ot.Interval(-1.0, 4.0), ot.Interval(0.2, 2.4), ot.Interval(2.5, 65.0), ot.Interval(2.5, 6.0), ot.Interval(-2.5, 6.0)] for i in range(len(candidates)): d = ot.TruncatedDistribution(candidates[i], intervals[i]) print("d=", d, "simplified=", d.getSimplifiedVersion()) # Check that we can set the bounds independently truncated = ot.TruncatedDistribution() truncated.setDistribution(ot.Normal(20.0, 7.5)) truncated.setBounds(ot.Interval([0], [80], [True], [False])) print('after setbounds [email protected]=', truncated.computeQuantile(0.9))
from matplotlib import pylab as plt # %% # Position of the problem # ----------------------- # # We consider a bivariate random vector :math:`X = (X_1, X_2)` with the following independent marginals : # # - an exponential distribution with parameter :math:`\lambda=1`, :math:`X_1 \sim \mathcal{E}(1.0)` ; # - a standard unit gaussian :math:`X_2 \sim \mathcal{N}(0,1)`. # # The support of the input vector is :math:`[0, +\infty[ \times \mathbb{R}` # # %% distX1 = ot.Exponential(1.0) distX2 = ot.Normal() distX = ot.ComposedDistribution([distX1, distX2]) # %% # We can draw the bidimensional PDF of the distribution `distX` over :math:`[0,-10] \times [10,10]` : ot.ResourceMap_SetAsUnsignedInteger("Contour-DefaultLevelsNumber", 8) graphPDF = distX.drawPDF([0, -10], [10, 10]) graphPDF.setTitle(r'2D-PDF of the input variables $(X_1, X_2)$') graphPDF.setXTitle(r'$x_1$') graphPDF.setYTitle(r'$x_2$') graphPDF.setLegendPosition("bottomright") view = otv.View(graphPDF) # %% # We consider the model :math:`f : (x_1, x_2) \mapsto x_1 x_2` which maps the random input vector :math:`X` to the output variable :math:`Y=f(X) \in \mathbb{R}`. We also draw the isolines of the model `f`.
graph = result.drawPDF() result = ot.LogUniform() * ot.LogUniform() print('logu*logu:', result) graph = result.drawPDF() result = ot.LogUniform() * ot.LogNormal() print('logu*logn:', result) graph = result.drawPDF() result = ot.LogNormal() * ot.LogUniform() print('logn*logu:', result) graph = result.drawPDF() # For ticket #917 result = ot.WeibullMin() + ot.Exponential() print('WeibullMin+Exponential:', result) print('result.CDF(1.0)=%.6f' % result.computeCDF(1.0)) result = -1.0 * ot.WeibullMin() + ot.Exponential() print('-WeibullMin+Exponential:', result) print('result.CDF(1.0)=%.6f' % result.computeCDF(1.0)) result = ot.WeibullMin() - ot.Exponential() print('WeibullMin-Exponential:', result) print('result.CDF(1.0)=%.6f' % result.computeCDF(1.0)) result = -1.0 * ot.WeibullMin() - ot.Exponential() print('-WeibullMin-Exponential:', result) print('result.CDF(-1.0)=%.6f' % result.computeCDF(-1.0)) # 2-d print(ot.Normal(2) + ot.Normal(2)) print(ot.Normal(2) + 3.0)
# %% # In this example we are going to build a conditional random vector # # .. math:: # \underline{X}|\underline{\Theta} # # %% import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt # %% # create the random vector Theta (parameters of X) gammaDist = ot.Uniform(1.0, 2.0) alphaDist = ot.Uniform(0.0, 0.1) thetaDist = ot.ComposedDistribution([gammaDist, alphaDist]) thetaRV = ot.RandomVector(thetaDist) # %% # create the XgivenTheta distribution XgivenThetaDist = ot.Exponential() # %% # create the X distribution XDist = ot.ConditionalRandomVector(XgivenThetaDist, thetaRV) # %% # draw a sample XDist.getSample(5)
ot.Log.Show(ot.Log.NONE) # %% # Create an 1-d distribution dist_1 = ot.Normal() # Create a 2-d distribution dist_2 = ot.ComposedDistribution( [ot.Normal(), ot.Triangular(0.0, 2.0, 3.0)], ot.ClaytonCopula(2.3)) # Create a 3-d distribution copula_dim3 = ot.Student(5.0, 3).getCopula() dist_3 = ot.ComposedDistribution( [ot.Normal(), ot.Triangular(0.0, 2.0, 3.0), ot.Exponential(0.2)], copula_dim3) # %% # Get the dimension fo the distribution dist_2.getDimension() # %% # Get the 2nd marginal dist_2.getMarginal(1) # %% # Get a 2-d marginal dist_3.getMarginal([0, 1]).getDimension() # %% # Ask some properties of the distribution
# %% # We see that the sample is quite different from the previous sample with independent copula. # %% # Draw several distributions in the same plot # ------------------------------------------- # %% # It is sometimes convenient to create a plot presenting the PDF and CDF on the same graphics. This is possible thanks to Matplotlib. # %% beta = ot.Beta(5, 7, 9, 10) pdfbeta = beta.drawPDF() cdfbeta = beta.drawCDF() exponential = ot.Exponential(3) pdfexp = exponential.drawPDF() cdfexp = exponential.drawCDF() # %% import openturns.viewer as otv # %% slideshow={"slide_type": "subslide"} import pylab as plt fig = plt.figure(figsize=(12, 4)) ax = fig.add_subplot(2, 2, 1) _ = otv.View(pdfbeta, figure=fig, axes=[ax]) ax = fig.add_subplot(2, 2, 2) _ = otv.View(cdfbeta, figure=fig, axes=[ax]) ax = fig.add_subplot(2, 2, 3) _ = otv.View(pdfexp, figure=fig, axes=[ax])
import openturns.viewer as viewer from matplotlib import pylab as plt ot.Log.Show(ot.Log.NONE) # %% # Create an 1-d distribution dist_1 = ot.Normal() # Create a 2-d distribution dist_2 = ot.ComposedDistribution( [ot.Normal(), ot.Triangular(0.0, 2.0, 3.0)], ot.ClaytonCopula(2.3)) # Create a 3-d distribution copula_dim3 = ot.Student(5.0, 3).getCopula() dist_3 = ot.ComposedDistribution([ot.Normal(), ot.Triangular( 0.0, 2.0, 3.0), ot.Exponential(0.2)], copula_dim3) # %% # Get the dimension fo the distribution dist_2.getDimension() # %% # Get the 2nd marginal dist_2.getMarginal(1) # %% # Get a 2-d marginal dist_3.getMarginal([0, 1]).getDimension() # %% # Ask some properties of the distribution
import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View if ot.Exponential().__class__.__name__ == 'Bernoulli': distribution = ot.Bernoulli(0.7) elif ot.Exponential().__class__.__name__ == 'Binomial': distribution = ot.Binomial(5, 0.2) elif ot.Exponential().__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.Exponential().__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.Exponential().__class__.__name__ == 'Histogram': distribution = ot.Histogram([-1.0, 0.5, 1.0, 2.0], [0.45, 0.4, 0.15]) elif ot.Exponential().__class__.__name__ == 'KernelMixture': kernel = ot.Uniform() sample = ot.Normal().getSample(5) bandwith = [1.0] distribution = ot.KernelMixture(kernel, bandwith, sample) elif ot.Exponential().__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.Exponential().__class__.__name__ == 'Multinomial': distribution = ot.Multinomial(5, [0.2])
import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View if ot.Exponential().__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.Exponential().__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.Exponential().__class__.__name__ == 'Histogram': distribution = ot.Histogram([-1.0, 0.5, 1.0, 2.0], [0.45, 0.4, 0.15]) else: distribution = ot.Exponential() 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 distXgivenT = ot.Exponential() distGamma = ot.Uniform(1.0, 2.0) distAlpha = ot.Uniform(0.0, 0.1) distTheta = ot.ComposedDistribution([distGamma, distAlpha]) rvTheta = ot.RandomVector(distTheta) rvX = ot.ConditionalRandomVector(distXgivenT, rvTheta) sampleX = rvX.getSample(1000) histX = ot.HistogramFactory().build(sampleX) graph = histX.drawPDF() graph.setXTitle('x') graph.setYTitle('pdf') fig = plt.figure(figsize=(8, 4)) plt.suptitle( "Conditional Random Vector: Exp($\gamma$, $\lambda$), $\gamma \sim \mathcal{U}(1,2)$, $\lambda \sim \mathcal{U}(0,1)$" ) axis = fig.add_subplot(111) axis.set_xlim(auto=True) View(graph, figure=fig, axes=[axis], add_legend=False)
print("Inverse survival (ref)=", ref.computeInverseSurvivalFunction(0.95)) print("Survival(inverse survival)=%.5f" % distribution.computeSurvivalFunction(InverseSurvival)) # Get 50% quantile quantile = distribution.computeQuantile(0.5) print("Quantile =", quantile) print("Quantile (ref)=", ref.computeQuantile(0.5)) print("CDF(quantile) =%.5f" % distribution.computeCDF(quantile)) # Instantiate one distribution object R = ot.CorrelationMatrix(3) R[0, 1] = 0.5 R[0, 2] = 0.25 collection = [ot.ComposedDistribution([ot.Normal()]*2, ot.AliMikhailHaqCopula(0.5)), ot.Normal([1.0]*3, [2.0]*3, R), ot.ComposedDistribution([ot.Exponential()]*2, ot.FrankCopula(0.5))] distribution = ot.BlockIndependentDistribution(collection) print("Distribution ", distribution) # Is this distribution elliptical ? print("Elliptical distribution= ", distribution.isElliptical()) # Is this distribution continuous ? print("Continuous = ", distribution.isContinuous()) # Has this distribution an elliptical copula ? print("Elliptical = ", distribution.hasEllipticalCopula()) # Has this distribution an independent copula ? print("Independent = ", distribution.hasIndependentCopula())
"round": 0, # Already an integer (casted as double) }, "avg_provider_rating": { "marg": ot.Triangular(2.5, 4.0, 4.8), # mode is 4.0 "corr": 0.01, # Weak positive correlation "bounds": None, "round": 2, }, "has_multipayment": { "marg": ot.Bernoulli(0.4), # assume 40% of yes "corr": 0.0, # Assume no correlation "bounds": None, "round": 0, }, "conversion_rate": { "marg": ot.Exponential(15.0, 0.05), # mean is ~0.12 (0.05 + 1/15) "corr": None, # Corr not relevant for conversion_rate, because # it is the target variable. "bounds": None, "round": 4, }, } CORR_CONF_TRAIN = { # Conf file for adding correlations between variables ("price", "ratio_shipping"): -0.15, # The more expensive, the less costly # the shipping } VAR_CONF_EVAL = VAR_CONF_TRAIN.copy() CORR_CONF_EVAL = CORR_CONF_TRAIN.copy()
upper_bound = 2.0 * pi graph = f.draw(lower_bound, upper_bound, 100) graph.setTitle("Christian Robert tough density") graph.setXTitle("") graph.setYTitle("") _ = View(graph) # %% # Independent Metropolis-Hastings # ------------------------------- # Let us use a mixture distribution to approximate the target distribution. # # This approximation will serve as the instrumental distribution # in the independent Metropolis-Hastings algorithm. exp = ot.Exponential(1.0) unif = ot.Normal(5.3, 0.4) instrumentalDistribution = ot.Mixture([exp, unif], [0.9, 0.1]) # %% # Compare the instrumental density to the target density. graph = f.draw(lower_bound, upper_bound, 100) graph.setTitle("Instrumental PDF") graph.setXTitle("") graph.setYTitle("") graph.add(instrumentalDistribution.drawPDF(lower_bound, upper_bound, 100)) graph.setLegendPosition("topright") graph.setLegends(["Unnormalized target density", "Instrumental PDF"]) _ = View(graph) # %%
============================= """ # %% # In this example we are going to create a deterministic weighted design experiment using Gauss product. # %% import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt ot.Log.Show(ot.Log.NONE) # %% # Define the underlying distribution, degrees distribution = ot.ComposedDistribution( [ot.Exponential(), ot.Triangular(-1.0, -0.5, 1.0)]) marginalSizes = [15, 8] # %% # Create the design experiment = ot.GaussProductExperiment(distribution, marginalSizes) sample = experiment.generate() # %% # Plot the design graph = ot.Graph("GP design", "x1", "x2", True, "") cloud = ot.Cloud(sample, "blue", "fsquare", "") graph.add(cloud) view = viewer.View(graph) plt.show()
result = test.getResult() analysis = ot.LinearModelAnalysis(result) print(analysis) # Compute confidence level (95%) for coefficients estimate alpha = 0.95 # interval confidence bounds interval = analysis.getCoefficientsConfidenceInterval(alpha) print("confidence intervals with level=%1.2f : %s" % (alpha, interval)) # https://github.com/openturns/openturns/issues/1729 ot.RandomGenerator.SetSeed(1789) sample_size = 14605 # 14604 : OK, 14605 : Fail a0 = 0.6 a1 = 2.0 x = ot.Normal(0.5, 0.2).getSample(sample_size) epsilon = ot.Exponential(0.1).getSample(sample_size) y = ot.Sample([[a0]] * sample_size) + a1 * x + epsilon algo = ot.LinearModelAlgorithm(x, y) result = algo.getResult() analysis = ot.LinearModelAnalysis(result) results = str(analysis) # Fix #1820 ot.RandomGenerator.SetSeed(0) distribution = ot.Normal() sample = distribution.getSample(30) func = ot.SymbolicFunction('x', '2 * x + 1') firstSample = sample secondSample = func(sample) + ot.Normal().getSample(30) linear_model = ot.LinearModelAlgorithm(firstSample, secondSample) linear_result = linear_model.getResult()
# # We define an affine combination of input random variables. # # .. math:: # Y = 2 + 5 X_1 + X_2 # # where: # # - :math:`X_1 \sim \mathcal{E}(\lambda=1.5)` # - :math:`X_2 \sim \mathcal{N}(\mu=4, \sigma=1)` # # This notion is different from the Mixture where the combination is made on the probability density functions and not on the univariate random variable. # %% # We create the distributions associated to the input random variables : X1 = ot.Exponential(1.5) X2 = ot.Normal(4.0, 1.0) # %% # We define an offset `a0` : a0 = 2.0 # %% # We create the `weights` : weight = [5.0, 1.0] # %% # We create the affine combination :math:`Y` : distribution = ot.RandomMixture([X1, X2], weight, a0) print(distribution)
import otrobopt #ot.Log.Show(ot.Log.Info) calJ = ot.SymbolicFunction(['x', 'theta'], ['x^3 - 3*x + theta']) calG = ot.SymbolicFunction(['x', 'theta'], ['-(x + theta - 2)']) J = ot.ParametricFunction(calJ, [1], [0.5]) g = ot.ParametricFunction(calG, [1], [0.5]) dim = J.getInputDimension() solver = ot.Cobyla() solver.setMaximumIterationNumber(1000) solver.setStartingPoint([0.0] * dim) thetaDist = ot.Exponential(2.0) robustnessMeasure = otrobopt.MeanMeasure(J, thetaDist) reliabilityMeasure = otrobopt.JointChanceMeasure(g, thetaDist, ot.Greater(), 0.9) problem = otrobopt.RobustOptimizationProblem(robustnessMeasure, reliabilityMeasure) problem.setMinimization(False) algo = otrobopt.SequentialMonteCarloRobustAlgorithm(problem, solver) algo.setMaximumIterationNumber(10) algo.setMaximumAbsoluteError(1e-3) algo.setInitialSamplingSize(10) algo.run() result = algo.getResult() print ('x*=', result.getOptimalPoint(), 'J(x*)=', result.getOptimalValue(), 'iteration=', result.getIterationNumber())
#! /usr/bin/env python from __future__ import print_function import openturns as ot ot.PlatformInfo.SetNumericalPrecision(3) distribution = ot.Beta(2.3, 2.2, -1.0, 1.0) print('distribution=', distribution) sample = distribution.getSample(1000) factory = ot.MaximumLikelihoodFactory(ot.Beta()) inf_distribution = factory.build(sample) print('estimated distribution=', inf_distribution) # set (a,b) out of (r, t, a, b) factory.setKnownParameter([-1.0, 1.0], [2, 3]) inf_distribution = factory.build(sample) print('estimated distribution with bounds=', inf_distribution) factory = ot.MaximumLikelihoodFactory(ot.Exponential()) factory.setKnownParameter([0.1], [1]) print(factory.build()) print(factory.build([3, 0]))
import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View if (ot.Exponential().__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.Exponential().__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.Exponential() 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)) plt.suptitle(str(distribution)) pdf_axis = fig.add_subplot(111)
graph = result.drawPDF() result = ot.LogUniform() * ot.LogUniform() print('logu*logu:', result) graph = result.drawPDF() result = ot.LogUniform() * ot.LogNormal() print('logu*logn:', result) graph = result.drawPDF() result = ot.LogNormal() * ot.LogUniform() print('logn*logu:', result) graph = result.drawPDF() # For ticket #917 result = ot.Weibull() + ot.Exponential() print('Weibull+Exponential:', result) print('result.CDF(1.0)=%.6f' % result.computeCDF(1.0)) result = -1.0 * ot.Weibull() + ot.Exponential() print('-Weibull+Exponential:', result) print('result.CDF(1.0)=%.6f' % result.computeCDF(1.0)) result = ot.Weibull() - ot.Exponential() print('Weibull-Exponential:', result) print('result.CDF(1.0)=%.6f' % result.computeCDF(1.0)) result = -1.0 * ot.Weibull() - ot.Exponential() print('-Weibull-Exponential:', result) print('result.CDF(-1.0)=%.6f' % result.computeCDF(-1.0)) # 2-d print(ot.Normal(2) + ot.Normal(2)) print(ot.Normal(2) + 3.0)
ot.TESTPREAMBLE() ot.RandomGenerator.SetSeed(0) ot.ResourceMap.SetAsUnsignedInteger("RandomMixture-DefaultMaxSize", 4000000) # Deactivate the simplification mechanism as we want to test the Poisson formula # based algorithm here ot.ResourceMap.SetAsBool("RandomMixture-SimplifyAtoms", False) # Create a collection of test-cases and the associated references numberOfTests = 3 testCases = list() references = list() testCases.append([ot.Uniform(-1.0, 3.0)] * 2) references.append(ot.Triangular(-2.0, 2.0, 6.0)) testCases.append([ot.Normal(), ot.Normal(1.0, 2.0), ot.Normal(-2.0, 2.0)]) references.append(ot.Normal(-1.0, 3.0)) testCases.append([ot.Exponential()] * 3) references.append(ot.Gamma(3.0, 1.0, 0.0)) print("testCases=", testCases) print("references=", references) for testIndex in range(len(testCases)): # Instanciate one distribution object distribution = ot.RandomMixture(testCases[testIndex]) distribution.setBlockMin(5) distribution.setBlockMax(20) distributionReference = references[testIndex] print("Distribution ", repr(distribution)) print("Distribution ", distribution) # Is this distribution elliptical ? print("Elliptical = ", distribution.isElliptical())
repr(cleanCovariance(referenceDistribution[testCase].getCovariance()))) parameters = distribution[testCase].getParametersCollection() print('parameters =', repr(parameters)) print('parameters (ref)=', repr(referenceDistribution[testCase].getParametersCollection())) print('parameter =', repr(distribution[testCase].getParameter())) print('parameter desc =', repr(distribution[testCase].getParameterDescription())) print('marginal 0 =', repr(distribution[testCase].getMarginal(0))) print('Standard representative=', referenceDistribution[testCase].getStandardRepresentative()) # Check simplification candidates = [ ot.Normal(1.0, 2.0), ot.Uniform(1.0, 2.0), ot.Exponential(1.0, 2.0), ot.TruncatedDistribution(ot.WeibullMin(), 1.5, 7.8), ot.Beta(1.5, 6.3, -1.0, 2.0) ] intervals = [ ot.Interval(-1.0, 4.0), ot.Interval(0.2, 2.4), ot.Interval(2.5, 65.0), ot.Interval(2.5, 6.0), ot.Interval(-2.5, 6.0) ] for i in range(len(candidates)): d = ot.TruncatedDistribution(candidates[i], intervals[i]) print("d=", d, "simplified=", d.getSimplifiedVersion()) # Check that we can set the bounds independently
import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View candidate = ot.Exponential(0.07, 0.0) graph = candidate.drawCDF(0.0, 30.0) sample = ot.Sample([[5.0], [6.0], [10.0], [22.0], [27.0]]) empiricalDrawable = ot.VisualTest.DrawEmpiricalCDF(sample, 0.0, 30.0).getDrawable(0) empiricalDrawable.setColor('darkblue') graph.add(empiricalDrawable) graph.setTitle('CDF comparison') graph.setLegends(['Candidate CDF', 'Empirical CDF']) View(graph)