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
Beispiel #2
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
Beispiel #3
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
Beispiel #5
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
Beispiel #6
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
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
Beispiel #10
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
Beispiel #11
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
    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
Beispiel #13
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
Beispiel #14
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
Beispiel #15
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
Beispiel #16
0
mean[0] = 7.
mean[1] = 2.
sigma = ot.Point(dim, 1.0)

R = ot.IdentityMatrix(dim)
myDistribution = ot.Normal(mean, sigma, R)

#
# Limit state
#

vect = ot.RandomVector(myDistribution)

output = ot.CompositeRandomVector(limitState, vect)

myEvent = ot.ThresholdEvent(output, ot.Less(), 0.0)

#
# Computation
#
bs = 1

# Monte Carlo
experiment = ot.MonteCarloExperiment()
myMC = ot.ProbabilitySimulationAlgorithm(myEvent, experiment)
myMC.setMaximumOuterSampling(int(1e6) // bs)
myMC.setBlockSize(bs)
myMC.setMaximumCoefficientOfVariation(-1.0)
myMC.run()

#
# %%
# 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)
Beispiel #18
0
    inVars[i] = "x" + str(i)
model = ot.SymbolicFunction(inVars, inVars)
# The output vector
Y = ot.CompositeRandomVector(model, X)
# The domain: [0, 1]^dim
domain = ot.Interval(dim)
# The event
event = ot.DomainEvent(Y, domain)

print("sample=", event.getSample(10))

#
# Case 2: process based event
#

# The input process
X = ot.WhiteNoise(distribution)
# The domain: [0, 1]^dim
domain = ot.Interval(dim)
# The event
event = ot.ProcessEvent(X, domain)

print("sample=", event.getSample(10))

# 3. from distribution
antecedent = ot.RandomVector(ot.Normal(2))
domain = ot.LevelSet(ot.SymbolicFunction(['x', 'y'], ['x^2+y^2']), ot.Less(),
                     1.0)
event = ot.DomainEvent(antecedent, domain)
print('sample=', event.getSample(10))
Beispiel #19
0
#Create a copula : IndependentCopula (no correlation)
aCopula = ot.IndependentCopula(dim)
aCopula.setName('Independent copula')

#Instanciate one distribution object
myDistribution = ot.ComposedDistribution([R_dist, F_dist], aCopula)
myDistribution.setName('myDist')

#We create a 'usual' RandomVector from the Distribution
vect = ot.RandomVector(myDistribution)

#We create a composite random vector
G = ot.RandomVector(limitState, vect)

#We create an Event from this RandomVector
myEvent = ot.Event(G, 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)

#For statistics about the algorithm
initialNumberOfCall = limitState.getEvaluationCallsNumber()

#Perform the analysis
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
Beispiel #21
0
    function = hyperplane(linear)
    function.setName('H3')
    functions.append(function)

    for ih in range(len(functions)):
        function = functions[ih]

        distribution = ot.Normal(dim)
        randomVector = ot.RandomVector(distribution)
        composite = ot.CompositeRandomVector(function, randomVector)

        for pft in [1e-4, 1e-6, 1e-8][1:2]:

            k = ot.Normal().computeQuantile(pft)[0] * ot.Point(
                linears[ih]).norm()
            event = ot.ThresholdEvent(composite, ot.Less(), k)

            print('--------------------')
            print('model H' + str(ih) + ' dim=%d' % dim, 'pft=%.2e' % pft,
                  'k=%g' % k)

            for n in [100, 1000][1:]:
                for gamma1 in [0.25, 0.5, 0.75][1:2]:
                    # algo = ot.MonteCarlo(event)
                    # algo.setMaximumOuterSampling(100*n)
                    # algo.setMaximumCoefficientOfVariation(-1.)
                    # algo.run()
                    # result = algo.getResult()
                    # print result
                    algo = ot.AdaptiveDirectionalSampling(event)
                    algo.setMaximumOuterSampling(n)
Beispiel #22
0
    def __init__(
        self,
        threshold=0.0,
        mu=[0.0] * 3,
        sigma=[1.0] * 3,
    ):
        """
        Creates a reliability problem RP33.

        The event is {g(X) < threshold} where

        g(x1, x2, x3) = min(g1, g2) with

        g1 = -x1 - x2 - x3 + 3 * sqrt(3)

        g2 = -x3 + 3

        We have :
            x1 ~ Normal(mu[0], sigma[0])

            x2 ~ Normal(mu[1], sigma[1])

            x3 ~ Normal(mu[2], sigma[2]).

        Parameters
        ----------
        threshold : float
            The threshold.
        mu : sequence of floats
            The list of 3 items representing the means of the gaussian distributions.
        sigma : float
            The list of 3 items representing the standard deviations of
            the gaussian distributions.
        """
        formula = "min(-x1 - x2 - x3 + 3 * sqrt(3), -x3 + 3)"
        limitStateFunction = ot.SymbolicFunction(["x1", "x2", "x3"], [formula])
        inputDimension = len(mu)
        if inputDimension != 3:
            raise Exception(
                "The dimension of mu is %d, but the expected dimension is 3." %
                (inputDimension))

        inputDimension = len(sigma)
        if inputDimension != 3:
            raise Exception(
                "The dimension of sigma is %d, but the expected dimension is 3."
                % (inputDimension))
        X1 = ot.Normal(mu[0], sigma[0])
        X1.setDescription(["X1"])
        X2 = ot.Normal(mu[1], sigma[1])
        X2.setDescription(["X2"])
        X3 = ot.Normal(mu[2], sigma[2])
        X3.setDescription(["X3"])

        myDistribution = ot.ComposedDistribution([X1, X2, X3])
        inputRandomVector = ot.RandomVector(myDistribution)
        outputRandomVector = ot.CompositeRandomVector(limitStateFunction,
                                                      inputRandomVector)
        thresholdEvent = ot.ThresholdEvent(outputRandomVector, ot.Less(),
                                           threshold)

        name = "RP33"
        probability = 0.00257
        super(ReliabilityProblem33, self).__init__(name, thresholdEvent,
                                                   probability)
        return None
Beispiel #23
0
import openturns as ot

ot.TESTPREAMBLE()

# create a function
dim = 4
function = ot.SymbolicFunction(
    ['E', 'F', 'L', 'I'], ['F*L^3/(3.*E*I)'])

# create a distribution
distribution = ot.Normal(
    [50., 1.0, 10.0, 5.0], [1.0] * dim,
    ot.IdentityMatrix(dim))
vect = ot.RandomVector(distribution)
composite = ot.CompositeRandomVector(function, vect)
event = ot.Event(composite, ot.Less(), -3.0)

# create an ADS algorithm
n = int(1e4)
algo = ot.AdaptiveDirectionalSampling(event)
algo.setMaximumOuterSampling(n)
algo.setGamma([0.6, 0.4])

algo.run()
result = algo.getResult()
print(result)

# ADS-2+
algo2 = algo
algo2.setPartialStratification(True)
algo2.run()
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)
#create joint probability distribution heave
distribution_h = ot.ComposedDistribution(marginals_h, copula_h)
distribution_h.setDescription(['h_exit', 'D_cover', 'i_ch'])

#create joint probability distribution
distribution_p = ot.ComposedDistribution(marginals_p, copula_p)
distribution_p.setDescription(['h_exit', 'D_cover', 'L', 'D', 'm_p', 'k', 'd70'])

#create joint probability distribution
distribution = ot.ComposedDistribution(marginals, copula)
distribution.setDescription(['h_exit', 'D_cover', 'm_u', 'i_ch', 'L', 'D', 'm_p', 'k', 'd70'])

#create the event we want to estimate the probability uplift
vect_u = ot.RandomVector(distribution_u)
G_u = ot.CompositeRandomVector(dijk.Z_u_function, vect_u)
event_u = ot.Event(G_u, ot.Less(), 0.0)
event_u.setName('uplift failure')

#create the event we want to estimate the probability heave
vect_h = ot.RandomVector(distribution_h)
G_h = ot.CompositeRandomVector(dijk.Z_h_function, vect_h)
event_h = ot.Event(G_h, ot.Less(), 0.0)
event_h.setName('heave failure')

#create the event we want to estimate the probability piping
vect_p = ot.RandomVector(distribution_p)
G_p = ot.CompositeRandomVector(dijk.Z_p_function, vect_p)
event_p = ot.Event(G_p, ot.Less(), 0.0)
event_p.setName('piping failure')

#create the event we want to estimate the probability
Beispiel #26
0
# Model
X0 = persalys.Input('X0', ot.Normal(1, 1))
X1 = persalys.Input('X1', ot.Normal(1, 1))
Y0 = persalys.Output('Y0')

model = persalys.SymbolicPhysicalModel('aModelPhys', [X0, X1], [Y0],
                                       ['sin(X0) + 8*X1'])
myStudy.add(model)

# limit state ##
limitState = persalys.LimitState('aLimitState', model, 'Y0', ot.Greater(), 20.)
print(limitState)
myStudy.add(limitState)

limitState.setThreshold(10.)
limitState.setOperator(ot.Less())
print(limitState)

# limit state ##
limitState2 = persalys.LimitState('aLimitState2', model)
print(limitState2)
myStudy.add(limitState2)

limitState2.setThreshold(15.)
print(limitState2)

model.addOutput(persalys.Output('Y1'))
model.setFormula('Y1', '1 + sin(X0) + 8*X1')
limitState2.setOutputName('Y1')
print(limitState2)
Beispiel #27
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)

# Perform the simulation
myAlgo.run()

# Stream out the result
print("MonteCarlo result=", myAlgo.getResult())
Beispiel #28
0
ot.TESTPREAMBLE()

dim = 2
distribution = ot.Normal(dim)

X = ot.RandomVector(distribution)

# 1. Composite/Composite
f1 = ot.SymbolicFunction(['x' + str(i) for i in range(dim)], ['x0'])
f2 = ot.SymbolicFunction(['x' + str(i) for i in range(dim)], ['x1'])

Y1 = ot.CompositeRandomVector(f1, X)
Y2 = ot.CompositeRandomVector(f2, X)

e1 = ot.ThresholdEvent(Y1, ot.Less(), 0.0)
e2 = ot.ThresholdEvent(Y2, ot.Greater(), 0.0)

e3 = e1.intersect(e2)
#print('e3=', e3)

proba_e3 = e3.getSample(10000).computeMean()[0]
print("proba_e3 = %.3g" % proba_e3)
ott.assert_almost_equal(proba_e3, 0.25, 1e-2, 1e-2)

e4 = e1.join(e2)
#print('e4=', e4)

proba_e4 = e4.getSample(10000).computeMean()[0]
print("proba_e4 = %.3g" % proba_e4)
ott.assert_almost_equal(proba_e4, 0.75, 1e-2, 1e-2)
Beispiel #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)
from __future__ import print_function
import openturns as ot

ot.TESTPREAMBLE()

# Uncertain parameters
distribution = ot.Normal([1.0] * 3, [2.0] * 3, ot.CorrelationMatrix(3))
distribution.setName("Unnamed")
# Model
f = ot.SymbolicFunction(["x", "y", "z"], ["x-1.5*y+2*z"])
# Sampling
size = 100
inputSample = distribution.getSample(size)
outputSample = f(inputSample)
comparisonOperators = [
    ot.Less(), ot.LessOrEqual(),
    ot.Greater(),
    ot.GreaterOrEqual()
]
threshold = 3.0
ot.ResourceMap.SetAsUnsignedInteger(
    "SimulationSensitivityAnalysis-DefaultSampleMargin", 10)
for i in range(4):
    # Analysis based on an event
    X = ot.RandomVector(distribution)
    Y = ot.CompositeRandomVector(f, X)
    event = ot.ThresholdEvent(Y, comparisonOperators[i], threshold)
    algo = ot.SimulationSensitivityAnalysis(event, inputSample, outputSample)
    print("algo=", algo)
    # Perform the analysis
    print("Mean point in event domain=", algo.computeMeanPointInEventDomain())