def test_DrawFilledEvent(self): # Distribution R = ot.Normal(4.0, 1.0) R.setDescription("R") S = ot.Normal(2.0, 1.0) S.setDescription("S") g = ot.SymbolicFunction(["R", "S"], ["R - S"]) # Event inputvector = ot.ComposedDistribution([R, S]) inputRV = ot.RandomVector(inputvector) outputRV = ot.CompositeRandomVector(g, inputRV) eventF = ot.Event(outputRV, ot.GreaterOrEqual(), 0) # # Bounds alphaMin = 0.01 alphaMax = 1 - alphaMin lowerBound = ot.Point( [R.computeQuantile(alphaMin)[0], S.computeQuantile(alphaMin)[0]]) upperBound = ot.Point( [R.computeQuantile(alphaMax)[0], S.computeQuantile(alphaMax)[0]]) bounds = ot.Interval(lowerBound, upperBound) # drawEvent = otbenchmark.DrawEvent(eventF) graph = drawEvent.fillEvent(bounds) assert type(graph) is ot.Graph
def test_ReliabilityBenchmarkProblem(self): limitStateFunction = ot.SymbolicFunction(["R", "S"], ["R - S"]) muR = 4.0 sigmaR = 1.0 muS = 2.0 sigmaS = 1.0 threshold = 0.0 R = ot.Normal(muR, sigmaR) S = ot.Normal(muS, sigmaS) myDistribution = ot.ComposedDistribution([R, S]) inputRandomVector = ot.RandomVector(myDistribution) outputRandomVector = ot.CompositeRandomVector(limitStateFunction, inputRandomVector) thresholdEvent = ot.ThresholdEvent(outputRandomVector, ot.Less(), threshold) name = "R-S" probability = 0.123456789 problem = otb.ReliabilityBenchmarkProblem(name, thresholdEvent, probability) # print(problem) print(problem.toFullString()) p = problem.getProbability() assert p == probability s = problem.getName() assert s == name
def _runMonteCarlo(self, defect): # set a parametric function where the first parameter = given defect g = ot.NumericalMathFunction(self._metamodel, [0], [defect]) g.enableHistory() g.clearHistory() g.clearCache() output = ot.RandomVector(g, ot.RandomVector(self._distribution)) event = ot.Event(output, ot.Greater(), self._detectionBoxCox) ##### Monte Carlo ######## algo_MC = ot.MonteCarlo(event) algo_MC.setMaximumOuterSampling(self._samplingSize) # set negative coef of variation to be sure the stopping criterion is the sampling size algo_MC.setMaximumCoefficientOfVariation(-1) algo_MC.run() return algo_MC.getResult()
def test_DrawFilledEvent(self): # Distribution R = ot.Normal(4.0, 1.0) R.setDescription("R") S = ot.Normal(2.0, 1.0) S.setDescription("S") g = ot.SymbolicFunction(["R", "S"], ["R - S"]) # Event distribution = ot.ComposedDistribution([R, S]) inputRV = ot.RandomVector(distribution) outputRV = ot.CompositeRandomVector(g, inputRV) eventF = ot.ThresholdEvent(outputRV, ot.GreaterOrEqual(), 0) alpha = 1.0 - 1.0e-2 ( bounds, marginalProb, ) = distribution.computeMinimumVolumeIntervalWithMarginalProbability( alpha) # drawEvent = otbenchmark.DrawEvent(eventF) # Avoid failing on CircleCi # _tkinter.TclError: no display name and no $DISPLAY environment variable try: _ = drawEvent.fillEvent(bounds) except Exception as e: print(e)
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
def setInputRandomVector(inList): #setting the input random vector X myCollection = ot.DistributionCollection(len(inList)) for index in range(len(inList)): myCollection[index] = ot.Distribution(inList[index]) myDistribution = ot.ComposedDistribution(myCollection) VectX = ot.RandomVector(ot.Distribution(myDistribution)) return myDistribution, VectX
def __init__(self, threshold=0.0, mu=[0.0] * 2, sigma=[1.0] * 2): """ Creates a reliability problem RP35. The event is {g(X) < threshold} where g(x1, x2) = min(g1, g2) with g1 = 2 - x2 + exp(-0.1 * x1^2) + (0.2 * x1) ^ 4 g2 = 4.5 - x1 * x2 We have x1 ~ Normal(mu[0], sigma[0]) and x2 ~ Normal(mu[1], sigma[1]). Parameters ---------- threshold : float The threshold. mu : sequence of floats The list of two items representing the means of the gaussian distributions. sigma : float The list of two items representing the standard deviations of the gaussian distributions. """ equations = ["var g1 := 2 - x2 + exp(-0.1 * x1^2) + (0.2 * x1) ^ 4"] equations.append("var g2 := 4.5 - x1 * x2") equations.append("gsys := min(g1, g2)") formula = ";".join(equations) limitStateFunction = ot.SymbolicFunction(["x1", "x2"], ["gsys"], formula) inputDimension = len(mu) if inputDimension != 2: raise Exception( "The dimension of mu is %d, but the expected dimension is 2." % (inputDimension)) inputDimension = len(sigma) if inputDimension != 2: raise Exception( "The dimension of sigma is %d, but the expected dimension is 2." % (inputDimension)) X1 = ot.Normal(mu[0], sigma[0]) X1.setDescription(["X1"]) X2 = ot.Normal(mu[1], sigma[1]) X2.setDescription(["X2"]) myDistribution = ot.ComposedDistribution([X1, X2]) inputRandomVector = ot.RandomVector(myDistribution) outputRandomVector = ot.CompositeRandomVector(limitStateFunction, inputRandomVector) thresholdEvent = ot.ThresholdEvent(outputRandomVector, ot.Less(), threshold) name = "RP35" probability = 0.00354 super(ReliabilityProblem35, self).__init__(name, thresholdEvent, probability) return None
def __init__(self, threshold=0.0, muR=4.0, sigmaR=1.0, muS=2.0, sigmaS=1.0): """ Create a R-S reliability problem. The event is {g(X) < threshold} where g(R, S) = R - S We have R ~ Normal(muR, sigmaR) and S ~ Normal(muS, sigmaS). Waarts (2000) uses muR = 7.0 and muS = 2.0 leading to beta = 3.54. Parameters ---------- threshold : float The threshold. muR : float The mean of the R gaussian distribution. sigmaR : float The standard deviation of the R gaussian distribution. muS : float The mean of the S gaussian distribution. sigmaS : float The standard deviation of the S gaussian distribution. Example ------- problem = RminusSReliabilityBenchmarkProblem() """ limitStateFunction = ot.SymbolicFunction(["R", "S"], ["R - S"]) R = ot.Normal(muR, sigmaR) R.setDescription("R") S = ot.Normal(muS, sigmaS) S.setDescription("S") myDistribution = ot.ComposedDistribution([R, S]) inputRandomVector = ot.RandomVector(myDistribution) outputRandomVector = ot.CompositeRandomVector( limitStateFunction, inputRandomVector ) thresholdEvent = ot.ThresholdEvent(outputRandomVector, ot.Less(), threshold) name = "R-S" diff = R - S probability = diff.computeCDF(threshold) super(RminusSReliabilityBenchmarkProblem, self).__init__( name, thresholdEvent, probability ) return None
def __init__(self, threshold=0.0, mu1=1.5, sigma1=1.0, mu2=2.5, sigma2=1.0): """ Creates a reliability problem RP53. The event is {g(X) < threshold} where g(X1, X2) = sin(5 * X1 / 2) + 2 - (X1^2 + 4) * (X2 - 1) / 20 We have X1 ~ Normal(mu1, sigma1) and X2 ~ Normal(mu2, sigma2). Parameters ---------- threshold : float The threshold. mu1 : float The mean of the X1 gaussian distribution. sigma1 : float The standard deviation of the X1 gaussian distribution. mu2 : float The mean of the X2 gaussian distribution. sigma2 : float The standard deviation of the X2 gaussian distribution. """ formula = "sin(5 * x1 / 2) + 2 - ( x1 * x1 + 4 ) * ( x2 - 1 ) / 20" limitStateFunction = ot.SymbolicFunction(["x1", "x2"], [formula]) print("sin(5 * x1 / 2) + 2 - ( x1 * x1 + 4 ) * ( x2 - 1 ) / 20") X1 = ot.Normal(mu1, sigma1) X1.setDescription(["X1"]) X2 = ot.Normal(mu2, sigma2) X2.setDescription(["X2"]) myDistribution = ot.ComposedDistribution([X1, X2]) inputRandomVector = ot.RandomVector(myDistribution) outputRandomVector = ot.CompositeRandomVector(limitStateFunction, inputRandomVector) thresholdEvent = ot.ThresholdEvent(outputRandomVector, ot.Less(), threshold) name = "RP53" probability = 0.0313 super(ReliabilityProblem53, self).__init__(name, thresholdEvent, probability) return None
def __init__(self, threshold=0.0, mu1=0.0, sigma1=1.0, mu2=0.0, sigma2=1.0): """ Creates a reliability problem RP25. The event is {g(X) < threshold} where --- g(x1, x2) = max(x1^2 -8 * x2 + 16, -16 * x1 + x2 + 32) --- We have x1 ~ Normal(mu1, sigma1) and x2 ~ Normal(mu2, sigma2). --- Parameters ---------- threshold : float The threshold. *** mu1 : float The mean of the X1 gaussian distribution. *** sigma1 : float The standard deviation of the X1 gaussian distribution. *** mu2 : float The mean of the X2 gaussian distribution. *** sigma2 : float The standard deviation of the X2 gaussian distribution. """ equations = ["var g1 := x1^2 -8 * x2 + 16"] equations.append("var g2 := -16 * x1 + x2 + 32") equations.append("gsys := max(g1, g2)") formula = ";".join(equations) limitStateFunction = ot.SymbolicFunction(["x1", "x2"], ["gsys"], formula) print(formula) X1 = ot.Normal(mu1, sigma1) X1.setDescription(["X1"]) X2 = ot.Normal(mu2, sigma2) X2.setDescription(["X2"]) myDistribution = ot.ComposedDistribution([X1, X2]) inputRandomVector = ot.RandomVector(myDistribution) outputRandomVector = ot.CompositeRandomVector(limitStateFunction, inputRandomVector) thresholdEvent = ot.ThresholdEvent(outputRandomVector, ot.Less(), threshold) name = "RP25" probability = 0.00000614 super(ReliabilityProblem25, self).__init__(name, thresholdEvent, probability) return None
def getXEvent(b, t, mu_S, covariance, R, delta_t): full = buildCrossing(b, t, mu_S, covariance, R, delta_t) X = ot.RandomVector(full) f1 = ot.SymbolicFunction(["R", "X1", "X2"], ["X1 - R"]) e1 = ot.ThresholdEvent(ot.CompositeRandomVector(f1, X), ot.Less(), 0.0) f2 = ot.SymbolicFunction(["R", "X1", "X2"], ["X2 - R"]) e2 = ot.ThresholdEvent(ot.CompositeRandomVector(f2, X), ot.GreaterOrEqual(), 0.0) event = ot.IntersectionEvent([e1, e2]) return X, event
def __init__(self, threshold=0.0, mu1=0.0, sigma1=1.0, mu2=0.0, sigma2=1.0): """ Creates a reliability problem RP57. The event is {g(X) < threshold} where g(x1, x2) = min(max(g1, g2), g3) with g1 = -x1^2 + x2^3 + 3 g2 = 2 - x1 - 8 * x2 g3 = (x1 + 3)^2 + (x2 + 3)^2 - 4 We have x1 ~ Normal(mu1, sigma1) and x2 ~ Normal(mu2, sigma2). *** Parameters ---------- threshold : float The threshold. mu1 : float The mean of the X1 gaussian distribution. sigma1 : float The standard deviation of the X1 gaussian distribution. mu2 : float The mean of the X2 gaussian distribution. sigma2 : float The standard deviation of the X2 gaussian distribution. """ equations = ["var g1 := -x1^2 + x2^3 + 3"] equations.append("var g2 := 2 - x1 - 8 * x2") equations.append("var g3 := (x1 + 3)^2 + (x2 + 3)^2 - 4") equations.append("gsys := min(max(g1, g2), g3) ") formula = ";".join(equations) limitStateFunction = ot.SymbolicFunction(["x1", "x2"], ["gsys"], formula) print(formula) X1 = ot.Normal(mu1, sigma1) X1.setDescription(["X1"]) X2 = ot.Normal(mu2, sigma2) X2.setDescription(["X2"]) myDistribution = ot.ComposedDistribution([X1, X2]) inputRandomVector = ot.RandomVector(myDistribution) outputRandomVector = ot.CompositeRandomVector(limitStateFunction, inputRandomVector) thresholdEvent = ot.ThresholdEvent(outputRandomVector, ot.Less(), threshold) name = "RP57" probability = 0.0284 super(ReliabilityProblem57, self).__init__(name, thresholdEvent, probability) return None
def __init__(self, threshold=0.0, mu=[10.0] * 2, sigma=[3.0] * 2): """ Creates a reliability problem RP24. The event is {g(X) < threshold} where g(x1, x2) = 2.5 - 0.2357 * (x1 - x2) + 0.00463 * (x1 + x2 - 20)^4 We have x1 ~ Normal(mu[0], sigma[0]) and x2 ~ Normal(mu[1], sigma[1]). Parameters ---------- threshold : float The threshold. mu : sequence of floats The list of two items representing the means of the gaussian distributions. sigma : float The list of two items representing the standard deviations of the gaussian distributions. """ formula = "2.5 - 0.2357 * (x1 - x2) + 0.00463 * (x1 + x2 - 20)^4" limitStateFunction = ot.SymbolicFunction(["x1", "x2"], [formula]) inputDimension = len(mu) if inputDimension != 2: raise Exception( "The dimension of mu is %d, but the expected dimension is 2." % (inputDimension)) inputDimension = len(sigma) if inputDimension != 2: raise Exception( "The dimension of sigma is %d, but the expected dimension is 2." % (inputDimension)) X1 = ot.Normal(mu[0], sigma[0]) X1.setDescription(["X1"]) X2 = ot.Normal(mu[1], sigma[1]) X2.setDescription(["X2"]) myDistribution = ot.ComposedDistribution([X1, X2]) inputRandomVector = ot.RandomVector(myDistribution) outputRandomVector = ot.CompositeRandomVector(limitStateFunction, inputRandomVector) thresholdEvent = ot.ThresholdEvent(outputRandomVector, ot.Less(), threshold) name = "RP24" probability = 0.00286 super(ReliabilityProblem24, self).__init__(name, thresholdEvent, probability) return None
def __init__(self): """ Creates the four-branch serial system from Waarts. References ---------- Waarts, P.-H. (2000). Structural reliability using finite element methods: an appraisal of DARS: Directional Adaptive Response Surface Sampling. Ph. D. thesis, Technical University of Delft, The Netherlands. Pages 58, 69, 160. Thèse Vincent Dubourg 2011, Méta-modèles adaptatifs pour l’analyse de fiabilité et l’optimisation sous contrainte fiabiliste, section "A two-dimensional four-branch serial system", page 182 Parameters ---------- None. Example ------- problem = FourBranchSerialSystemReliabilityBenchmarkProblem() """ formulaList = [ "var y0 := 3 + 0.1 * (x0 - x1)^2 - (x0 + x1) / sqrt(2)", "var y1 := 3 + 0.1 * (x0 - x1)^2 + (x0 + x1) / sqrt(2)", "var y2 := x0 - x1 + 7 / sqrt(2)", "var y3 := x1 - x0 + 7 / sqrt(2)", "y := min(y0,y1,y2,y3)", ] formula = ";".join(formulaList) limitStateFunction = ot.SymbolicFunction(["x0", "x1"], ["y"], formula) x0 = ot.Normal(0.0, 1.0) x1 = ot.Normal(0.0, 1.0) inputDistribution = ot.ComposedDistribution((x0, x1)) inputRandomVector = ot.RandomVector(inputDistribution) outputRandomVector = ot.CompositeRandomVector( limitStateFunction, inputRandomVector ) thresholdEvent = ot.ThresholdEvent(outputRandomVector, ot.Less(), 0.0) name = "Four-branch serial system (Waarts, 2000)" beta = 2.85 probability = ot.Normal().computeComplementaryCDF(beta) super(FourBranchSerialSystemReliabilityBenchmarkProblem, self).__init__( name, thresholdEvent, probability ) return None
def __init__(self, threshold=146.14, mu1=78064.0, sigma1=11710.0, mu2=0.0104, sigma2=0.00156): """ Creates a reliability problem RP28. The event is {g(X) < threshold} where g(x1, x2) = x1 * x2 - threshold with threshold = 146.14. We have x1 ~ Normal(mu1, sigma1) and x2 ~ Normal(mu2, sigma2). Parameters ---------- threshold : float The threshold. mu1 : float The mean of the X1 gaussian distribution. sigma1 : float The standard deviation of the X1 gaussian distribution. mu2 : float The mean of the X2 gaussian distribution. sigma2 : float The standard deviation of the X2 gaussian distribution. """ formula = "x1 * x2" limitStateFunction = ot.SymbolicFunction(["x1", "x2"], [formula]) X1 = ot.Normal(mu1, sigma1) X1.setDescription(["X1"]) X2 = ot.Normal(mu2, sigma2) X2.setDescription(["X2"]) myDistribution = ot.ComposedDistribution([X1, X2]) inputRandomVector = ot.RandomVector(myDistribution) outputRandomVector = ot.CompositeRandomVector(limitStateFunction, inputRandomVector) thresholdEvent = ot.ThresholdEvent(outputRandomVector, ot.Less(), threshold) name = "RP28" Y = X1 * X2 probability = Y.computeCDF(threshold) super(ReliabilityProblem28, self).__init__(name, thresholdEvent, probability) return None
def __init__(self, threshold=0.0, mu1=10.0, sigma1=3.0, mu2=10.0, sigma2=3.0): """ Creates a reliability problem RP24. The event is {g(X) < threshold} where g(x1, x2) = 2.5 - 0.2357 * (x1 - x2) + 0.00463 * (x1 + x2 - 20)^4 We have x1 ~ Normal(mu1, sigma1) and x2 ~ Normal(mu2, sigma2). *** Parameters ---------- threshold : float The threshold. mu1 : float The mean of the X1 gaussian distribution. sigma1 : float The standard deviation of the X1 gaussian distribution. mu2 : float The mean of the X2 gaussian distribution. sigma2 : float The standard deviation of the X2 gaussian distribution. """ formula = "2.5 - 0.2357 * (x1 - x2) + 0.00463 * (x1 + x2 - 20)^4" limitStateFunction = ot.SymbolicFunction(["x1", "x2"], [formula]) print(formula) X1 = ot.Normal(mu1, sigma1) X1.setDescription(["X1"]) X2 = ot.Normal(mu2, sigma2) X2.setDescription(["X2"]) myDistribution = ot.ComposedDistribution([X1, X2]) inputRandomVector = ot.RandomVector(myDistribution) outputRandomVector = ot.CompositeRandomVector(limitStateFunction, inputRandomVector) thresholdEvent = ot.ThresholdEvent(outputRandomVector, ot.Less(), threshold) name = "RP24" probability = 0.00286 super(ReliabilityProblem24, self).__init__(name, thresholdEvent, probability) return None
def __init__(self, threshold=0.0): """ Create a axial stressed beam reliability problem. The inputs are R, the Yield strength, and F, the traction load. The event is {g(X) < threshold} where g(R, F) = R - F/(pi_ * 100.0) We have R ~ LogNormalMuSigma() and F ~ Normal(). Parameters ---------- threshold : float The threshold. Example ------- problem = AxialStressedBeamReliability() """ limitStateFunction = ot.SymbolicFunction(["R", "F"], ["R - F/(pi_ * 100.0)"]) R_dist = ot.LogNormalMuSigma(300.0, 30.0, 0.0).getDistribution() R_dist.setName("Yield strength") R_dist.setDescription("R") F_dist = ot.Normal(75000.0, 5000.0) F_dist.setName("Traction load") F_dist.setDescription("F") myDistribution = ot.ComposedDistribution([R_dist, F_dist]) inputRandomVector = ot.RandomVector(myDistribution) outputRandomVector = ot.CompositeRandomVector( limitStateFunction, inputRandomVector ) thresholdEvent = ot.ThresholdEvent(outputRandomVector, ot.Less(), 0.0) name = "Axial stressed beam" diff = R_dist - F_dist / (np.pi * 100.0) probability = diff.computeCDF(threshold) super(AxialStressedBeamReliability, self).__init__( name, thresholdEvent, probability ) return None
def functionCrue4VarsStochastic(X): Q, Ks, Zv, Zm = X # 1. Creation of the problem function f8v = ot.PythonFunction(8, 1, functionCrue8vars) g = ot.ParametricFunction(f8v, [0, 1, 2, 3], X) # 2. Random vector definition Hd = ot.Uniform(4.,14.) Zb = ot.Uniform(50.,60.) L = ot.Uniform(1000.,10000.) B = ot.Uniform(50.,500.) inputvector = ot.ComposedDistribution([Hd, Zb, L, B]) inputRV = ot.RandomVector(inputvector) S = ot.CompositeRandomVector(g, inputRV) # 3. Sample output sampleSize = 10 outputSample = S.getSample(sampleSize) Smean = outputSample.computeMean()[0] return [Smean]
def __init__(self, threshold=0.0, mu=0, sigma=1): """ Creates a reliability problem RP107. The event is {g(X) < threshold} where X = (x1, x2, ...., x10) g(X) = 5*sqrt(10) -(x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10). We have xi ~ Normal(0, 1) for i in {1, 2, ...,10} Parameters ---------- threshold : float The threshold. mu : float The mean of the Xi Normal distribution for i in {1, 2, ..., 10}. sigma : float The standard deviation of the Xi Normal distribution for i in {1, 2, ..., 10}. """ formula = "5*sqrt(10)-(x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10)" limitStateFunction = ot.SymbolicFunction( ["x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10"], [formula]) X = [ot.Normal(mu, sigma) for i in range(10)] myDistribution = ot.ComposedDistribution(X) inputRandomVector = ot.RandomVector(myDistribution) outputRandomVector = ot.CompositeRandomVector(limitStateFunction, inputRandomVector) thresholdEvent = ot.ThresholdEvent(outputRandomVector, ot.Less(), threshold) name = "RP107" probability = 0.000000292 super(ReliabilityProblem107, self).__init__(name, thresholdEvent, probability) return None
def __init__(self, threshold=0.0, a1=-1.0, b1=1.0, a2=-1.0, b2=1.0): """ Creates a reliability problem RP55. The event is {g(X) < threshold} where We have x1 ~ Uniform(a1, b1) and x2 ~ Uniform(a2, b2). *** Parameters ---------- threshold : float The threshold. a1 , b1 : float Parameters of the X1 uniform distribution. a2 , b2 : float Parameters of the X2 uniform distribution. """ equations = ["var g1 := 0.2 + 0.6 * (x0 - x1)^4 - (x0 - x1) / sqrt(2)"] equations.append( "var g2 := 0.2 + 0.6 * (x0 - x1)^4 + (x0 - x1) / sqrt(2)") equations.append("var g3 := (x0 - x1) + 5 / sqrt(2) - 2.2") equations.append("var g4 := (x1 - x0) + 5 / sqrt(2) - 2.2") equations.append("gsys := min(g1, g2, g3, g4)") formula = ";".join(equations) limitStateFunction = ot.SymbolicFunction(["x0", "x1"], ["gsys"], formula) print(formula) X1 = ot.Uniform(a1, b1) X1.setDescription(["X1"]) X2 = ot.Uniform(a2, b2) X2.setDescription(["X2"]) myDistribution = ot.ComposedDistribution([X1, X2]) inputRandomVector = ot.RandomVector(myDistribution) outputRandomVector = ot.CompositeRandomVector(limitStateFunction, inputRandomVector) thresholdEvent = ot.ThresholdEvent(outputRandomVector, ot.Less(), threshold) name = "RP55" probability = 0.36 super(ReliabilityProblem55, self).__init__(name, thresholdEvent, probability) return None
def test_DrawSample(self): # Distribution R = ot.Normal(4.0, 1.0) R.setDescription("R") S = ot.Normal(2.0, 1.0) S.setDescription("S") g = ot.SymbolicFunction(["R", "S"], ["R - S"]) # Event inputvector = ot.ComposedDistribution([R, S]) inputRV = ot.RandomVector(inputvector) outputRV = ot.CompositeRandomVector(g, inputRV) eventF = ot.Event(outputRV, ot.GreaterOrEqual(), 0) # sampleSize = 500 inputSample = inputvector.getSample(sampleSize) outputSample = g(inputSample) # drawEvent = otbenchmark.DrawEvent(eventF) graph = drawEvent.drawSample(inputSample, outputSample) assert type(graph) is ot.Graph
def test_DrawSample(self): # Distribution R = ot.Normal(4.0, 1.0) R.setDescription("R") S = ot.Normal(2.0, 1.0) S.setDescription("S") g = ot.SymbolicFunction(["R", "S"], ["R - S"]) # Event distribution = ot.ComposedDistribution([R, S]) inputRV = ot.RandomVector(distribution) outputRV = ot.CompositeRandomVector(g, inputRV) eventF = ot.ThresholdEvent(outputRV, ot.GreaterOrEqual(), 0) # sampleSize = 500 drawEvent = otbenchmark.DrawEvent(eventF) _ = drawEvent.drawSampleCrossCut(sampleSize, 0, 1) # Avoid failing on CircleCi # _tkinter.TclError: no display name and no $DISPLAY environment variable try: _ = drawEvent.drawSample(sampleSize) except Exception as e: print(e)
def GenerateExperiencePlan(paras_range=paras_ris_range, n_sample=50000): """ """ for k, v in paras_range.items(): assert v[0] < v[1], 'ERROR of v[0]>=v[1] for ranges {}'.format(k) # le nombre de paramètre doit être proportionné au dimension de ranges len_actual_parameters = len(paras_range) # Specify the input random vector. # instance de classe densite de proba a definir myCollection = ot.DistributionCollection(len_actual_parameters) for i, p_name in enumerate(paras_range): distribution = ot.Uniform(paras_range[p_name][0], paras_range[p_name][1]) myCollection[i] = ot.Distribution(distribution) myDistribution = ot.ComposedDistribution(myCollection) vectX = ot.RandomVector(ot.Distribution(myDistribution)) # Sample the input random vector. Xsample = GenerateSample(vectX, n_sample, method='QMC') xsample = np.array(Xsample) return xsample
def test_GetSample(self): """ Teste l'utilisation de l'objet ModelePensionProbabiliste. """ simulateur = SimulateurRetraites() S = 0.0 D = 0.14 annee = 2050 modele = ModelePensionProbabiliste(simulateur, annee, S, D) fonction = modele.getFonction() inputDistribution = modele.getInputDistribution() # Crée un vecteur aléatoire inputRandomVector = ot.RandomVector(inputDistribution) outputRandomVector = ot.CompositeRandomVector(fonction, inputRandomVector) sampleSize = 100 sample = outputRandomVector.getSample(sampleSize) # Vérifie l'échantillon dim = sample.getDimension() self.assertEqual(dim, 1) size = sample.getSize() self.assertEqual(size, sampleSize) return None
def setParameter(self, offset_point): self._offset = offset_point[0] def getParameter(self): return [self._offset] def getParameterDescription(self): return ["offset"] R = RVEC() print(R) # Instance creation myRV = ot.RandomVector(R) print("myRV=", repr(myRV)) # Copy constructor newRV = ot.RandomVector(myRV) # Dimension dim = myRV.getDimension() print('dimension=', dim) # Realization X = myRV.getRealization() print('realization=', X) # Sample X = myRV.getSample(5)
import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt import math as m import time ot.Log.Show(ot.Log.NONE) # %% # Define an event to compute a probability myFunction = ot.SymbolicFunction(['E', 'F', 'L', 'I'], ['-F*L^3/(3.0*E*I)']) dim = myFunction.getInputDimension() mean = [50.0, 1.0, 10.0, 5.0] sigma = [1.0] * dim R = ot.IdentityMatrix(dim) myDistribution = ot.Normal(mean, sigma, R) vect = ot.RandomVector(myDistribution) output = ot.CompositeRandomVector(myFunction, vect) myEvent = ot.ThresholdEvent(output, ot.Less(), -3.0) # %% # **Stop a FORM algorithm using a calls number limit** # # A FORM algorithm termination can be controlled by the maximum number of iterations # # of its underlying optimization solver, but not directly by a maximum number of evaluations. # %% # Create the optimization algorithm myCobyla = ot.Cobyla() myCobyla.setMaximumEvaluationNumber(400) myCobyla.setMaximumAbsoluteError(1.0e-10)
cb = cantilever_beam.CantileverBeam() # %% # We use the input parameters distribution from the data class : distribution = cb.distribution distribution.setDescription(['E', 'F', 'L', 'I']) # %% # We define the model model = cb.model # %% # Create the event whose probability we want to estimate. # %% vect = ot.RandomVector(distribution) G = ot.CompositeRandomVector(model, vect) event = ot.ThresholdEvent(G, ot.Greater(), 0.3) event.setName("deviation") # %% # Define a solver optimAlgo = ot.Cobyla() optimAlgo.setMaximumEvaluationNumber(1000) optimAlgo.setMaximumAbsoluteError(1.0e-10) optimAlgo.setMaximumRelativeError(1.0e-10) optimAlgo.setMaximumResidualError(1.0e-10) optimAlgo.setMaximumConstraintError(1.0e-10) # %% # Run FORM
Q.setDescription(["Q (m3/s)"]) Ks.setDescription(["Ks (m^(1/3)/s)"]) Zv.setDescription(["Zv (m)"]) Zm.setDescription(["Zm (m)"]) View(Q.drawPDF()).show() pl.savefig("Q.pdf") View(Ks.drawPDF()).show() View(Zv.drawPDF()).show() View(Zm.drawPDF()).show() # 4. Create the joint distribution function, # the output and the event. X = ot.ComposedDistribution([Q, Ks, Zv, Zm]) Y = ot.RandomVector(g, ot.RandomVector(X)) # 5. Estimate expectation with simple Monte-Carlo sampleSize = 10000 sampleX = X.getSample(sampleSize) sampleY = g(sampleX) sampleMean = sampleY.computeMean() print("Mean by MC = %f" % (sampleMean[0])) # 6. Estimate expectation with algorithm algo = ot.ExpectationSimulationAlgorithm(Y) algo.setMaximumOuterSampling(1000) algo.setBlockSize(1) algo.setCoefficientOfVariationCriterionType('NONE') algo.run() result = algo.getResult()
# We create a normal distribution point of dimension 1 mean = [0.0] * dim # E mean[0] = 50.0 # F mean[1] = 1.0 # L mean[2] = 10.0 # I mean[3] = 5.0 sigma = [1.0] * dim R = ot.IdentityMatrix(dim) myDistribution = ot.Normal(mean, sigma, R) # We create a 'usual' RandomVector from the Distribution vect = ot.RandomVector(myDistribution) # We create a composite random vector output = ot.RandomVector(myFunction, vect) # We create an Event from this RandomVector myEvent = ot.Event(output, ot.Less(), -3.0) # We create a Monte Carlo algorithm myAlgo = ot.MonteCarlo(myEvent) myAlgo.setMaximumOuterSampling(250) myAlgo.setBlockSize(4) myAlgo.setMaximumCoefficientOfVariation(0.1) print("MonteCarlo=", myAlgo)
# %% F_dist = sm.distribution_F graph = F_dist.drawPDF() view = viewer.View(graph) # %% # These independent marginals define the joint distribution of the input parameters : myDistribution = sm.distribution # %% # We create a `RandomVector` from the `Distribution`, then a composite random vector. Finally, we create a `ThresholdEvent` from this `RandomVector`. # %% inputRandomVector = ot.RandomVector(myDistribution) outputRandomVector = ot.CompositeRandomVector( limitStateFunction, inputRandomVector) myEvent = ot.ThresholdEvent(outputRandomVector, ot.Less(), 0.0) # %% # Using Monte Carlo simulations # ----------------------------- # %% cv = 0.05 NbSim = 100000 experiment = ot.MonteCarloExperiment() algoMC = ot.ProbabilitySimulationAlgorithm(myEvent, experiment) algoMC.setMaximumOuterSampling(NbSim)