def _PODgaussModelCl(self, defects, intercept, slope, stderr, detection): class buildPODModel(): def __init__(self, intercept, slope, sigmaEpsilon, detection): self.intercept = intercept self.slope = slope self.sigmaEpsilon = sigmaEpsilon self.detection = detection def PODmodel(self, x): t = (self.detection - (self.intercept + self.slope * x)) / self.sigmaEpsilon return ot.DistFunc.pNormal(t, True) N = defects.getSize() X = ot.Sample(N, [1, 0]) X[:, 1] = defects X = ot.Matrix(X) covMatrix = X.computeGram(True).solveLinearSystem(ot.IdentityMatrix(2)) sampleNormal = ot.Normal([0, 0], ot.CovarianceMatrix( covMatrix.getImplementation())).getSample( self._simulationSize) sampleSigmaEpsilon = (ot.Chi(N - 2).inverse() * np.sqrt(N - 2) * stderr).getSample(self._simulationSize) PODcoll = [] for i in range(self._simulationSize): sigmaEpsilon = sampleSigmaEpsilon[i][0] interceptSimu = sampleNormal[i][0] * sigmaEpsilon + intercept slopeSimu = sampleNormal[i][1] * sigmaEpsilon + slope PODcoll.append( buildPODModel(interceptSimu, slopeSimu, sigmaEpsilon, detection).PODmodel) return PODcoll
import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View if ot.Chi().__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.Chi().__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.Chi().__class__.__name__ == 'Histogram': distribution = ot.Histogram([-1.0, 0.5, 1.0, 2.0], [0.45, 0.4, 0.15]) else: distribution = ot.Chi() 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() distribution = ot.Chi(0.5) size = 10000 sample = distribution.getSample(size) factory = ot.ChiFactory() estimatedDistribution = factory.build(sample) print("distribution=", repr(distribution)) print("Estimated distribution=", repr(estimatedDistribution)) distribution = ot.Chi(1.0) sample = distribution.getSample(size) estimatedDistribution = factory.build(sample) print("distribution=", repr(distribution)) print("Estimated distribution=", repr(estimatedDistribution)) distribution = ot.Chi(2.5) sample = distribution.getSample(size) estimatedDistribution = factory.build(sample) print("distribution=", repr(distribution)) print("Estimated distribution=", repr(estimatedDistribution)) estimatedDistribution = factory.build() print("Default distribution=", estimatedDistribution) estimatedDistribution = factory.build(distribution.getParameter()) print("Distribution from parameters=", estimatedDistribution) estimatedChi = factory.buildAsChi(sample) print("Chi =", distribution) print("Estimated chi=", estimatedChi)
import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View if ot.Chi().__class__.__name__ == 'Bernoulli': distribution = ot.Bernoulli(0.7) elif ot.Chi().__class__.__name__ == 'Binomial': distribution = ot.Binomial(5, 0.2) elif ot.Chi().__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.Chi().__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.Chi().__class__.__name__ == 'Histogram': distribution = ot.Histogram([-1.0, 0.5, 1.0, 2.0], [0.45, 0.4, 0.15]) elif ot.Chi().__class__.__name__ == 'KernelMixture': kernel = ot.Uniform() sample = ot.Normal().getSample(5) bandwith = [1.0] distribution = ot.KernelMixture(kernel, bandwith, sample) elif ot.Chi().__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.Chi().__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.Chi().__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.Chi().__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.Chi() 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))