coll.add(rm) weights.add(-2.5) coll.add(ot.Gamma(3.0, 4.0, -2.0)) weights.add(2.5) distribution = ot.RandomMixture(coll, weights) print("distribution=", repr(distribution)) print("distribution=", distribution) mu = distribution.getMean()[0] sigma = distribution.getStandardDeviation()[0] for i in range(10): x = mu + (-3.0 + 6.0 * i / 9.0) * sigma print("pdf( %.6f )=%.6f" % (x, distribution.computePDF(x))) # Tests of the projection mechanism collFactories = [ot.UniformFactory(), ot.NormalFactory( ), ot.TriangularFactory(), ot.ExponentialFactory(), ot.GammaFactory()] # , TrapezoidalFactory() result, norms = distribution.project(collFactories) print("projections=", result) print("norms=", norms) # ------------------------------ Multivariate tests ------------------------------# # 2D RandomMixture collection = [ot.Normal(0.0, 1.0)] * 3 weightMatrix = ot.Matrix(2, 3) weightMatrix[0, 0] = 1.0 weightMatrix[0, 1] = -2.0 weightMatrix[0, 2] = 1.0 weightMatrix[1, 0] = 1.0 weightMatrix[1, 1] = 1.0 weightMatrix[1, 2] = -3.0
import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View ot.RandomGenerator.SetSeed(0) factory = ot.TriangularFactory() ref = factory.build() dimension = ref.getDimension() if dimension <= 2: sample = ref.getSample(50) distribution = factory.build(sample) if dimension == 1: distribution.setDescription(['$t$']) pdf_graph = distribution.drawPDF(256) cloud = ot.Cloud(sample, ot.NumericalSample(sample.getSize(), 1)) cloud.setColor('blue') cloud.setPointStyle('fcircle') pdf_graph.add(cloud) fig = plt.figure(figsize=(10, 4)) plt.suptitle(str(distribution)) pdf_axis = fig.add_subplot(111) View(pdf_graph, figure=fig, axes=[pdf_axis], add_legend=False) else: sample = ref.getSample(500) distribution.setDescription(['$t_0$', '$t_1$']) pdf_graph = distribution.drawPDF([256]*2) cloud = ot.Cloud(sample) cloud.setColor('red') cloud.setPointStyle('fcircle') pdf_graph.add(cloud) fig = plt.figure(figsize=(10, 4)) plt.suptitle(str(distribution))
from matplotlib import pylab as plt ot.Log.Show(ot.Log.NONE) # %% # Create a sample from a continuous distribution distribution = ot.Beta(2.0, 2.0, 0.0, 1.) sample = distribution.getSample(1000) graph = ot.UserDefined(sample).drawCDF() view = viewer.View(graph) # %% # **1. Specify the model only** # %% # Create the list of distribution estimators factories = [ot.BetaFactory(), ot.TriangularFactory()] # %% # Rank the continuous models by the Lilliefors p-values: estimated_distribution, test_result = ot.FittingTest.BestModelLilliefors( sample, factories) test_result # %% # Rank the continuous models wrt the BIC criteria (no test result): ot.FittingTest.BestModelBIC(sample, factories) # %% # Rank the continuous models wrt the AIC criteria (no test result) ot.FittingTest.BestModelAIC(sample, factories)