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
Exemplo n.º 2
0
 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 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
Exemplo n.º 4
0
def create_monte_carlo(model, inputRandomVector, coefficient_variation):
    """Create a Monte Carlo algorithm.

    Parameters
    ----------
    model : OpenTURNS Function.

    inputRandomVector : OpenTURNS RandomVector, vector of random inputs.

    coefficient_variation : Float, target for the coefficient of variation of
    the estimator.

    """

    outputVariableOfInterest = ot.CompositeRandomVector(model, inputRandomVector)
    # Create an Event from this RandomVector
    threshold = 30
    myEvent = ot.ThresholdEvent(outputVariableOfInterest, ot.Greater(), threshold)
    myEvent.setName("Deviation > %g cm" % threshold)

    # Create a Monte Carlo algorithm
    experiment = ot.MonteCarloExperiment()
    myAlgoMonteCarlo = ot.ProbabilitySimulationAlgorithm(myEvent, experiment)
    myAlgoMonteCarlo.setBlockSize(100)
    myAlgoMonteCarlo.setMaximumCoefficientOfVariation(coefficient_variation)

    return myAlgoMonteCarlo
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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
Exemplo n.º 8
0
    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
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
    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
Exemplo n.º 12
0
    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
Exemplo n.º 13
0
    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=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
Exemplo n.º 15
0
    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
Exemplo n.º 16
0
    def _runMonteCarlo(self, defect):
        # set a parametric function where the first parameter = given defect
        g = ot.ParametricFunction(self._metamodel, [0], [defect])
        g = ot.MemoizeFunction(g)
        g.enableHistory()
        g.clearHistory()
        g.clearCache()
        output = ot.CompositeRandomVector(g,
                                          ot.RandomVector(self._distribution))
        event = ot.ThresholdEvent(output, ot.Greater(), self._detectionBoxCox)

        ##### Monte Carlo ########
        algo_MC = ot.ProbabilitySimulationAlgorithm(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()
Exemplo n.º 17
0
    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
Exemplo n.º 18
0
    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
Exemplo n.º 19
0
 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)
Exemplo n.º 20
0
# %%
# We consider three functions `f1`, `f2` and `f3` :
f1 = ot.SymbolicFunction(['x0', 'x1'], ['x0'])
f2 = ot.SymbolicFunction(['x0', 'x1'], ['x1'])
f3 = ot.SymbolicFunction(['x0', 'x1'], ['x0+x1'])

# %%
# We build :class:`~openturns.CompositeRandomVector` from these functions and the initial distribution.
Y1 = ot.CompositeRandomVector(f1, X)
Y2 = ot.CompositeRandomVector(f2, X)
Y3 = ot.CompositeRandomVector(f3, X)

# %%
# We define three basic events :math:`E_1=\{(x_0,x_1)~:~x_0 < 0 \}`, :math:`E_2=\{(x_0,x_1)~:~x_1 > 0 \}` and :math:`E_3=\{(x_0,x_1)~:~x_0+x_1>0 \}`.
e1 = ot.ThresholdEvent(Y1, ot.Less(), 0.0)
e2 = ot.ThresholdEvent(Y2, ot.Greater(), 0.0)
e3 = ot.ThresholdEvent(Y3, ot.Greater(), 0.0)

# %%
# The restriction of the domain :math:`E_1` to :math:`[-4,4] \times [-4, 4]` is the grey area.
myGraph = ot.Graph(r'Representation of the event $E_1$', r'$x_1$', r'$x_2$',
                   True, '')
data = [[-4, -4], [0, -4], [0, 4], [-4, 4]]
myPolygon = ot.Polygon(data)
myPolygon.setColor('grey')
myPolygon.setEdgeColor('black')
myGraph.add(myPolygon)
view = otv.View(myGraph)
axes = view.getAxes()
_ = axes[0].set_xlim(-4.0, 4.0)
Exemplo n.º 21
0
# %%
g = ot.MemoizeFunction(g)

# %%
# Create the output random vector :math:`Y = g(X)`:

# %%
Y = ot.CompositeRandomVector(g, X)

# %%
# Create the event :math:`\{ Y = g(X) \leq 0 \}`
# ----------------------------------------------

# %%
myEvent = ot.ThresholdEvent(Y, ot.LessOrEqual(), 0.0)

# %%
# Evaluate the probability with the subset sampling technique
# -----------------------------------------------------------

# %%
algo = ot.SubsetSampling(myEvent)

# %%
# In order to get all the inputs and outputs that realize the event, you have to mention it now:

# %%
algo.setKeepEventSample(True)

# %%
Exemplo n.º 22
0
    ot.Interval([low] * 2, [up] * 2, [False, True], [True, False]),
    ot.Interval([low] * 2, [up] * 2, [False, True], [False, True]),
    ot.Interval([low] * 2, [up] * 2, [False, True], [False, False]),
    ot.Interval([low] * 2, [up] * 2, [False, False], [True, True]),
    ot.Interval([low] * 2, [up] * 2, [False, False], [True, False]),
    ot.Interval([low] * 2, [up] * 2, [False, False], [False, True]),
    ot.Interval([low] * 2, [up] * 2, [False, False], [False, False])
]

for domain in intervals:
    print('#' * 50)
    print('domain=\n', domain)
    outDim = domain.getDimension()
    f = ot.SymbolicFunction(inVars, inVars[0:outDim])
    Y = ot.CompositeRandomVector(f, X)
    event = ot.ThresholdEvent(Y, domain)

    ot.RandomGenerator.SetSeed(0)
    # algo = getattr(openturns, algoName)(event)
    algo = ot.ProbabilitySimulationAlgorithm(event, ot.MonteCarloExperiment())
    algo.run()
    res = algo.getResult().getProbabilityEstimate()
    print('MC p=%.6g' % res)

    ot.RandomGenerator.SetSeed(0)
    # algo = getattr(openturns, algoName)(event)
    algo = ot.FORM(ot.Cobyla(), event, X.getMean())
    algo.run()
    res = algo.getResult().getEventProbability()
    print('FORM p=%.2f' % res)
# %%
# 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
algo = ot.FORM(optimAlgo, event, distribution.getMean())
algo.run()
Exemplo n.º 24
0
mycopula = ot.NormalCopula(R)

# %%
# And we endly create the composed input probability distribution.
inputDistribution = ot.ComposedDistribution([E, F, L, I], mycopula)
inputDistribution.setDescription(("E", "F", "L", "I"))

# %%
# Create the event whose probability we want to estimate:

inputRandomVector = ot.RandomVector(inputDistribution)
outputVariableOfInterest = ot.CompositeRandomVector(model_fmu,
                                                    inputRandomVector)

threshold = 30
event = ot.ThresholdEvent(outputVariableOfInterest, ot.Greater(), threshold)
event.setName("Deviation > %g cm" % threshold)

# %%
# Parameterize and run the Monte Carlo algorithm:

ot.RandomGenerator.SetSeed(23091926)  #  set seed for reproducibility

experiment = ot.MonteCarloExperiment()
algo = ot.ProbabilitySimulationAlgorithm(event, experiment)
algo.setMaximumOuterSampling(200)
algo.setMaximumCoefficientOfVariation(0.2)
algo.run()

# %%
# Draw the distribution of threshold excedance probability:
Exemplo n.º 25
0
    matrix = ot.Matrix(2, 3)
    matrix[0, 0] = 0
    matrix[0, 1] = 1
    matrix[0, 2] = 2
    matrix[1, 0] = 3
    matrix[1, 1] = 4
    matrix[1, 2] = 5
    myStudy.add('m', matrix)

    # Create a Point that we will try to reinstaciate after reloading
    point = ot.Point(2, 1000.)
    point.setName('point')
    myStudy.add('point', point)

    # Create a Simulation::Result
    simulationResult = ot.ProbabilitySimulationResult(ot.ThresholdEvent(), 0.5,
                                                      0.01, 150, 4)
    myStudy.add('simulationResult', simulationResult)

    cNameList = [
        'LHS', 'DirectionalSampling', 'SimulationSensitivityAnalysis',
        'ProbabilitySimulationAlgorithm'
    ]
    for cName in cNameList:
        otClass = getattr(ot, cName)
        instance = otClass()
        print('--', cName, instance)
        myStudy.add(cName, instance)

    # Create a Beta distribution
    beta = ot.Beta(3.0, 2.0, -1.0, 4.0)
Exemplo n.º 26
0
# %%
# We want to estimate the probability :math:`P_f` of the output variable to be greater than a prescribed threshold :math:`s=10` : this is the failure event. This probability is simply expressed as an integral :
#
# .. math::
#
#    P_f = \int_{\mathcal{D}} \mathbf{1}_{\mathcal{D}}(x) df_{X_1,X_2}(x)
#
# where :math:`\mathcal{D} = \{ (x_1, x_2) \in [0,+\infty[ \times \mathbb{R} / x_1 x_2 \geq s \}` is the failure domain.
# In the general case the probability density function :math:`f_{X_1,X_2}` and the domain of integration :math:`\mathcal{D}` are difficult to handle.

# %%
# We first define RandomVector objects and the failure event associated to the ouput random variable.
vectorX = ot.RandomVector(distX)
vectorY = ot.CompositeRandomVector(f, vectorX)
s = 10.0
event = ot.ThresholdEvent(vectorY, ot.Greater(), s)

# %%
# This event can easily be represented with a 1D curve as it is a branch of an hyperbole.
# If :math:`y =  x_1 x_2 = 10.0`, then the boundary of the domain of failure is the curve :
#
# .. math::
#
#    h : x_1 \mapsto \frac{10.0}{x_1}
#

# %%
# We shall represent this curve using a :class:`~openturns.Contour` object.
nx, ny = 15, 15
xx = ot.Box([nx], ot.Interval([0.0], [10.0])).generate()
yy = ot.Box([ny], ot.Interval([-10.0], [10.0])).generate()
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)
algoMC.setBlockSize(1)
algoMC.setMaximumCoefficientOfVariation(cv)
model = ot.SymbolicFunction(["x1", "x2"], ["x1+2*x2"])

# Create the input distribution and random vector X
inputDist = ot.Normal(2)
inputDist.setDescription(['X1', 'X2'])

inputVector = ot.RandomVector(inputDist)

# Create the output random vector Y=model(X)
output = ot.CompositeRandomVector(model, inputVector)
output.setName("MyOutputY")

# %%
# Create the physical event Y > 4
threshold = 4
myEvent = ot.ThresholdEvent(output, ot.Greater(), threshold)

# Create the associated standard event in the standard space
myStandardEvent = ot.StandardEvent(myEvent)

# %%
# First : FORM analyses to get the design point
myCobyla = ot.Cobyla()
myStartingPoint = inputDist.getMean()
myAlgoFORM = ot.FORM(myCobyla, myEvent, myStartingPoint)
myAlgoFORM.run()
FORMResult = myAlgoFORM.getResult()
standardSpaceDesignPoint = FORMResult.getStandardSpaceDesignPoint()

# %%
# Fix the importance level epsilon of the test
Exemplo n.º 29
0
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)
myCobyla.setMaximumRelativeError(1.0e-10)
myCobyla.setMaximumResidualError(1.0e-10)
model = ot.MemoizeFunction(model)

# %%
# Remove all the values stored in the history mechanism.
# Care : it is done regardless the status of the History mechanism.

# %%
model.clearHistory()

# %%
# Create the event whose probability we want to estimate.

# %%
vect = ot.RandomVector(distribution)
G = ot.CompositeRandomVector(model, vect)
event = ot.ThresholdEvent(G, ot.Less(), 0.0)

# %%
# Create a Monte Carlo algorithm.

# %%
experiment = ot.MonteCarloExperiment()
algo = ot.ProbabilitySimulationAlgorithm(event, experiment)
algo.setMaximumCoefficientOfVariation(0.1)
algo.setMaximumStandardDeviation(0.001)
algo.setMaximumOuterSampling(int(1e4))

# %%
# Define the HistoryStrategy to store the values of :math:`P_n` and :math:`\sigma_n` used ot draw the convergence graph.
# Compact strategy : N points