# 1. The function G def functionCrue(X): Q, Ks, Zv, Zm = X alpha = (Zm - Zv) / 5.0e3 H = (Q / (Ks * 300.0 * sqrt(alpha)))**(3.0 / 5.0) S = [H + Zv] return S # Creation of the problem function g = ot.PythonFunction(4, 1, functionCrue) g = ot.MemoizeFunction(g) # 2. Random vector definition myParamQ = ot.GumbelAB(1013., 558.) Q = ot.ParametrizedDistribution(myParamQ) otLOW = ot.TruncatedDistribution.LOWER Q = ot.TruncatedDistribution(Q, 0, otLOW) Ks = ot.Normal(30.0, 7.5) Ks = ot.TruncatedDistribution(Ks, 0, otLOW) Zv = ot.Uniform(49.0, 51.0) Zm = ot.Uniform(54.0, 56.0) # 3. View the PDF 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")
maxDegree = 4 # %% # For real tests, we suggest using the following parameter value: # %% # maxDegree = 7 # %% # Let us define the parameters of the cantilever beam problem. # %% dist_E = ot.Beta(0.9, 2.2, 2.8e7, 4.8e7) dist_E.setDescription(["E"]) F_para = ot.LogNormalMuSigma(3.0e4, 9.0e3, 15.0e3) # in N dist_F = ot.ParametrizedDistribution(F_para) dist_F.setDescription(["F"]) dist_L = ot.Uniform(250.0, 260.0) # in cm dist_L.setDescription(["L"]) dist_I = ot.Beta(2.5, 1.5, 310.0, 450.0) # in cm^4 dist_I.setDescription(["I"]) myDistribution = ot.ComposedDistribution([dist_E, dist_F, dist_L, dist_I]) dim_input = 4 # dimension of the input dim_output = 1 # dimension of the output def function_beam(X): E, F, L, I = X Y = F * L**3 / (3 * E * I)
def Gumbel(alpha=1.0, gamma=0.0): """ Gumbel compatibility shim. """ return ot.ParametrizedDistribution(ot.GumbelLambdaGamma(alpha, gamma))
#! /usr/bin/env python import openturns as ot parameters = ot.GammaMuSigma(0.1, 0.489898, -0.5) distribution = ot.ParametrizedDistribution(parameters) print("Distribution ", distribution) # Is this distribution elliptical ? print("Elliptical = ", distribution.isElliptical()) # Is this distribution continuous ? print("Continuous = ", distribution.isContinuous()) # Test for realization of distribution oneRealization = distribution.getRealization() print("oneRealization=", oneRealization) # Test for sampling size = 10000 oneSample = distribution.getSample(size) print("oneSample first=", oneSample[0], " last=", oneSample[size - 1]) print("mean=", oneSample.computeMean()) print("covariance=", oneSample.computeCovariance()) # Define a point point = ot.Point(distribution.getDimension(), 1.0) print("Point= ", point) # Show PDF and CDF of point
#!/usr/bin/env python from __future__ import print_function import openturns as ot import otmorris poutre = ot.SymbolicFunction(['L', 'b', 'h', 'E', 'F'], ['F * L^3 / (48 * E * b * h^3 / 12)']) # define the model L = ot.ParametrizedDistribution(ot.LogNormalMuSigmaOverMu(5., 0.02)) b = ot.ParametrizedDistribution(ot.LogNormalMuSigmaOverMu(2., 0.05)) h = ot.ParametrizedDistribution(ot.LogNormalMuSigmaOverMu(0.4, 0.05)) E = ot.ParametrizedDistribution(ot.LogNormalMuSigmaOverMu(3e4, 0.12)) F = ot.ParametrizedDistribution(ot.LogNormalMuSigmaOverMu(0.1, 0.20)) list_marginals = [L, b, h, E, F] distribution = ot.ComposedDistribution(list_marginals) distribution.setDescription(('L', 'b', 'h', 'E', 'F')) dim = distribution.getDimension() level_number = 4 trajectories = 10 jump_step = int(level_number / 2) levels = [level_number] * dim # set the bounds of the grid experiment bound = ot.Interval( [marginal.computeQuantile(0.01)[0] for marginal in list_marginals], [marginal.computeQuantile(0.99)[0] for marginal in list_marginals]) experiment = otmorris.MorrisExperimentGrid(levels, bound, trajectories) experiment.setJumpStep(ot.Indices([jump_step] * dim))
#!/usr/bin/env python # -*- coding: utf8 -*- import openturns as ot from analytical_functions import gfun_8 from simulation_methods import run_MonteCarlo # Distributions d'entrée # ~ dist_X1 = ot.Normal(0., 1.) # ~ dist_X2 = ot.Normal(0., 1.) # ~ myDistribution = ot.ComposedDistribution([dist_X1, dist_X2]) parameters1 = ot.LogNormalMuSigma(120, 12, 0.0) dist_X1 = ot.ParametrizedDistribution(parameters1) parameters2 = ot.LogNormalMuSigma(120, 12, 0.0) dist_X2 = ot.ParametrizedDistribution(parameters2) parameters3 = ot.LogNormalMuSigma(120, 12, 0.0) dist_X3 = ot.ParametrizedDistribution(parameters3) parameters4 = ot.LogNormalMuSigma(120, 12, 0.0) dist_X4 = ot.ParametrizedDistribution(parameters4) parameters5 = ot.LogNormalMuSigma(50, 10, 0.0) dist_X5 = ot.ParametrizedDistribution(parameters5) parameters6 = ot.LogNormalMuSigma(40, 8, 0.0) dist_X6 = ot.ParametrizedDistribution(parameters6) myDistribution = ot.ComposedDistribution(
def __init__( self, threshold=0.0, mu1=120.0, sigma1=12.0, mu2=120.0, sigma2=12.0, mu3=120.0, sigma3=12.0, mu4=120.0, sigma4=12.0, mu5=50.0, sigma5=10.0, mu6=40.0, sigma6=8.0, ): """ Creates a reliability problem RP8. The event is {g(X) < threshold} where X = (x1, x2, x3, x4, x5, x6) g(X) = x1 + 2 * x2 + 2 * x3 + x4 - 5 * x5 - 5 * x6 We have : x1 ~ LogNormalMuSigma(mu1, sigma1) x2 ~ LogNormalMuSigma(mu2, sigma2) x3 ~ LogNormalMuSigma(mu3, sigma3) x4 ~ LogNormalMuSigma(mu4, sigma4) x5 ~ LogNormalMuSigma(mu5, sigma5) x6 ~ LogNormalMuSigma(mu6, sigma6) Parameters ---------- threshold : float The threshold. mu1 : float The mean of the LogNormal random variable X1. sigma1 : float The standard deviation of the LogNormal random variable X1. mu2 : float The mean of the LogNormal random variable X2. sigma2 : float The standard deviation of the LogNormal random variable X2. mu3 : float The mean of the LogNormal random variable X3. sigma3 : float The standard deviation of the LogNormal random variable X3. mu4 : float The mean of the LogNormal random variable X4. sigma4 : float The standard deviation of the LogNormal random variable X4. mu5 : float The mean of the LogNormal random variable X5. sigma5 : float The standard deviation of the LogNormal random variable X5. mu6 : float The mean of the LogNormal random variable X6. sigma6 : float The standard deviation of the LogNormal random variable X6. """ formula = "x1 + 2 * x2 + 2 * x3 + x4 - 5 * x5 - 5 * x6" limitStateFunction = ot.SymbolicFunction( ["x1", "x2", "x3", "x4", "x5", "x6"], [formula] ) parameters1 = ot.LogNormalMuSigma(mu1, sigma1, 0.0) X1 = ot.ParametrizedDistribution(parameters1) X1.setDescription(["X1"]) parameters2 = ot.LogNormalMuSigma(mu2, sigma2, 0.0) X2 = ot.ParametrizedDistribution(parameters2) X2.setDescription(["X2"]) parameters3 = ot.LogNormalMuSigma(mu3, sigma3, 0.0) X3 = ot.ParametrizedDistribution(parameters3) X3.setDescription(["X3"]) parameters4 = ot.LogNormalMuSigma(mu4, sigma4, 0.0) X4 = ot.ParametrizedDistribution(parameters4) X4.setDescription(["X4"]) parameters5 = ot.LogNormalMuSigma(mu5, sigma5, 0.0) X5 = ot.ParametrizedDistribution(parameters5) X5.setDescription(["X5"]) parameters6 = ot.LogNormalMuSigma(mu6, sigma6, 0.0) X6 = ot.ParametrizedDistribution(parameters6) X6.setDescription(["X6"]) myDistribution = ot.ComposedDistribution([X1, X2, X3, X4, X5, X6]) inputRandomVector = ot.RandomVector(myDistribution) outputRandomVector = ot.CompositeRandomVector( limitStateFunction, inputRandomVector ) thresholdEvent = ot.ThresholdEvent(outputRandomVector, ot.Less(), threshold) name = "RP8" Y = X1 + 2 * X2 + 2 * X3 + X4 - 5 * X5 - 5 * X6 probability = Y.computeCDF(threshold) super(ReliabilityProblem8, self).__init__(name, thresholdEvent, probability) return None
CS = 0.2 + 0.8 - expm1(-1000 / S**4) else: CS = 1 if (Hd < 8): CH = 8. / 20. else: CH = Hd / 20. C = CS + CH return [H, S, C] myFunction = ot.PythonFunction(8, 3, functionCrue) # 2. Create the Input and Output random variables myParam = ot.GumbelAB(1013., 558.) QGumbel = ot.ParametrizedDistribution(myParam) Q = ot.TruncatedDistribution(QGumbel, 0, ot.TruncatedDistribution.LOWER) KsNormal = ot.Normal(30.0, 7.5) Ks = ot.TruncatedDistribution(KsNormal, 0, ot.TruncatedDistribution.LOWER) Zv = ot.Uniform(49.0, 51.0) Zm = ot.Uniform(54.0, 56.0) # Hd = ot.Uniform(7., 9.) # Hd = 3.0; Zb = ot.Triangular(55.0, 55.5, 56.0) # Zb = 55.5 L = ot.Triangular(4990, 5000., 5010.) # L = 5.0e3; B = ot.Triangular(295., 300., 305.) # B = 300.0 Q.setDescription(["Q (m3/s)"]) Ks.setDescription(["Ks (m^(1/3)/s)"]) Zv.setDescription(["Zv (m)"]) Zm.setDescription(["Zm (m)"])
def __init__( self, threshold=0.0, a=70.0, b=80.0, mu2=39.0, sigma2=0.1, mu3=1500.0, sigma3=350.0, mu4=400.0, sigma4=0.1, mu5=250000.0, sigma5=35000.0, ): """ Creates a reliability problem RP14. The event is {g(X) < threshold} where X = (x1, x2, x3, x4, x5) g(X) = x1 - 32 / (pi_ * x2^3) * sqrt(x3^2 * x4^2 / 16 + x5^2) We have : x1 ~ Uniform(a, b) x2 ~ Normal(mu2, sigma2) x3 ~ Gumbel-max(mu3, sigma3) x4 ~ Normal(mu4, sigma4) x5 ~ Normal(mu5, sigma5) Parameters ---------- threshold : float The threshold. a : float Lower bound of the Uniform distribution X1. b : float Upper bound of the Uniform distribution X1. mu2 : float The mean of the X2 Normal distribution. sigma2 : float The standard deviation of the X2 Normal distribution. mu3 : float The mean of the X3 Gumbel distribution. sigma3 : float The standard deviation of the X3 Gumbel distribution. mu4 : float The mean of the X4 Normal distribution. sigma4 : float The standard deviation of the X4 Normal distribution. mu5 : float The mean of the X5 Normal distribution. sigma5 : float The standard deviation of the X5 Normal distribution. """ formula = "x1 - 32 / (pi_ * x2^3) * sqrt(x3^2 * x4^2 / 16 + x5^2)" limitStateFunction = ot.SymbolicFunction( ["x1", "x2", "x3", "x4", "x5"], [formula]) X1 = ot.Uniform(a, b) X1.setDescription(["X1"]) X2 = ot.Normal(mu2, sigma2) X2.setDescription(["X2"]) X3 = ot.ParametrizedDistribution(ot.GumbelMuSigma(mu3, sigma3)) X3.setDescription(["X3"]) X4 = ot.Normal(mu4, sigma4) X4.setDescription(["X4"]) X5 = ot.Normal(mu5, sigma5) X5.setDescription(["X5"]) myDistribution = ot.ComposedDistribution([X1, X2, X3, X4, X5]) inputRandomVector = ot.RandomVector(myDistribution) outputRandomVector = ot.CompositeRandomVector(limitStateFunction, inputRandomVector) thresholdEvent = ot.ThresholdEvent(outputRandomVector, ot.Less(), threshold) name = "RP14" probability = 0.00752 super(ReliabilityProblem14, self).__init__(name, thresholdEvent, probability) return None
def __init__( self, threshold=0.0, mu1=2200, sigma1=220, mu2=2100, sigma2=210, mu3=2300, sigma3=230, mu4=2000, sigma4=200, mu5=1200, sigma5=480, ): """ Creates a reliability problem RP60. The event is {g(X) < threshold} with: X = (x1, x2, x3, x4, x5) g1 = x1 - x5 g2 = x2 - x5 / 2 g3 = x3 - x5 / 2 g4 = x4 - x5 / 2 g5 = x2 - x5 g6 = x3 - x5 g7 = x4 - x5 g8 = min(g5, g6) g9 = max(g7, g8) g10 = min(g2, g3, g4) g11 = max(g10, g9) g(X) = min(g1, g11) We have : x1 ~ LogNormalMuSigma(mu1, sigma1) x2 ~ LogNormalMuSigma(mu2, sigma2) x3 ~ LogNormalMuSigma(mu3, sigma3) x4 ~ LogNormalMuSigma(mu4, sigma4) x5 ~ LogNormalMuSigma(mu5, sigma5) Parameters ---------- threshold : float The threshold. mu1 : float The mean of the LogNormal random variable X1. sigma1 : float The standard deviation of the LogNormal random variable X1. mu2 : float The mean of the LogNormal random variable X2. sigma2 : float The standard deviation of the LogNormal random variable X2. mu3 : float The mean of the LogNormal random variable X3. sigma3 : float The standard deviation of the LogNormal random variable X3. mu4 : float The mean of the LogNormal random variable X4. sigma4 : float The standard deviation of the LogNormal random variable X4. mu5 : float The mean of the LogNormal random variable X5. sigma5 : float The standard deviation of the LogNormal random variable X5. """ equations = ["var g1 := x1 - x5"] equations.append("var g2 := x2 - x5 / 2") equations.append("var g3 := x3 - x5 / 2") equations.append("var g4 := x4 - x5 / 2") equations.append("var g5 := x2 - x5") equations.append("var g6 := x3 - x5") equations.append("var g7 := x4 - x5") equations.append("var g8 := min(g5, g6)") equations.append("var g9 := max(g7, g8)") equations.append("var g10 := min(g2, g3, g4)") equations.append("var g11 := max(g10, g9)") equations.append("gsys := min(g1, g11)") formula = ";".join(equations) limitStateFunction = ot.SymbolicFunction( ["x1", "x2", "x3", "x4", "x5"], ["gsys"], formula ) parameters1 = ot.LogNormalMuSigma(mu1, sigma1, 0.0) X1 = ot.ParametrizedDistribution(parameters1) X1.setDescription(["X1"]) parameters2 = ot.LogNormalMuSigma(mu2, sigma2, 0.0) X2 = ot.ParametrizedDistribution(parameters2) X2.setDescription(["X2"]) parameters3 = ot.LogNormalMuSigma(mu3, sigma3, 0.0) X3 = ot.ParametrizedDistribution(parameters3) X3.setDescription(["X3"]) parameters4 = ot.LogNormalMuSigma(mu4, sigma4, 0.0) X4 = ot.ParametrizedDistribution(parameters4) X4.setDescription(["X4"]) parameters5 = ot.LogNormalMuSigma(mu5, sigma5, 0.0) X5 = ot.ParametrizedDistribution(parameters5) X5.setDescription(["X5"]) myDistribution = ot.ComposedDistribution([X1, X2, X3, X4, X5]) inputRandomVector = ot.RandomVector(myDistribution) outputRandomVector = ot.CompositeRandomVector( limitStateFunction, inputRandomVector ) thresholdEvent = ot.ThresholdEvent(outputRandomVector, ot.Less(), threshold) name = "RP60" probability = 0.0456 super(ReliabilityProblem60, self).__init__(name, thresholdEvent, probability) return None
hard_model_hparams = { 'model': var_dim, 'dim': 50, 'series': True # if series or parallel } # Surrogate model soft_model_hparams = { 'name': 'GP', 'kernel': None, 'n_restarts_optimizer': 0, 'normalize': False } # Distributions of random variables n = hard_model_hparams['dim'] dist_params = ot.LogNormalMuSigma(1.0, 0.2, 0.0) marginals = [ot.ParametrizedDistribution(dist_params)] * n dist = ot.ComposedDistribution(marginals) # Infill strategy infill_params_1 = { 'candidate': None, # 'uniform' 'num_pnt_re': 10000, 'num_neighbors': 1000, 'name': 'conv_comb', 'n_top': 1, 'decay_rate': None, 'metric': 'cosine', 'min_it': 40, 'max_it': 10000 } infill_params_2 = {