def test_DrawFilledEvent(self):
     # Distribution
     R = ot.Normal(4.0, 1.0)
     R.setDescription("R")
     S = ot.Normal(2.0, 1.0)
     S.setDescription("S")
     g = ot.SymbolicFunction(["R", "S"], ["R - S"])
     # Event
     inputvector = ot.ComposedDistribution([R, S])
     inputRV = ot.RandomVector(inputvector)
     outputRV = ot.CompositeRandomVector(g, inputRV)
     eventF = ot.Event(outputRV, ot.GreaterOrEqual(), 0)
     #
     # Bounds
     alphaMin = 0.01
     alphaMax = 1 - alphaMin
     lowerBound = ot.Point(
         [R.computeQuantile(alphaMin)[0],
          S.computeQuantile(alphaMin)[0]])
     upperBound = ot.Point(
         [R.computeQuantile(alphaMax)[0],
          S.computeQuantile(alphaMax)[0]])
     bounds = ot.Interval(lowerBound, upperBound)
     #
     drawEvent = otbenchmark.DrawEvent(eventF)
     graph = drawEvent.fillEvent(bounds)
     assert type(graph) is ot.Graph
Exemple #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.Event(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)
Exemple #3
0
    def _runMonteCarlo(self, defect):
        # set a parametric function where the first parameter = given defect
        g = ot.NumericalMathFunction(self._metamodel, [0], [defect])
        g.enableHistory()
        g.clearHistory()
        g.clearCache()
        output = ot.RandomVector(g, ot.RandomVector(self._distribution))
        event = ot.Event(output, ot.Greater(), self._detectionBoxCox)

        ##### Monte Carlo ########
        algo_MC = ot.MonteCarlo(event)
        algo_MC.setMaximumOuterSampling(self._samplingSize)
        # set negative coef of variation to be sure the stopping criterion is the sampling size
        algo_MC.setMaximumCoefficientOfVariation(-1)
        algo_MC.run()
        return algo_MC.getResult()
 def test_DrawSample(self):
     # Distribution
     R = ot.Normal(4.0, 1.0)
     R.setDescription("R")
     S = ot.Normal(2.0, 1.0)
     S.setDescription("S")
     g = ot.SymbolicFunction(["R", "S"], ["R - S"])
     # Event
     inputvector = ot.ComposedDistribution([R, S])
     inputRV = ot.RandomVector(inputvector)
     outputRV = ot.CompositeRandomVector(g, inputRV)
     eventF = ot.Event(outputRV, ot.GreaterOrEqual(), 0)
     #
     sampleSize = 500
     inputSample = inputvector.getSample(sampleSize)
     outputSample = g(inputSample)
     #
     drawEvent = otbenchmark.DrawEvent(eventF)
     graph = drawEvent.drawSample(inputSample, outputSample)
     assert type(graph) is ot.Graph
Exemple #5
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.Event(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)
Exemple #6
0
from __future__ import print_function
import openturns as ot
from openturns.viewer import View

threshold = 10.0
N = 10000
distribution = ot.Normal(2)
X = ot.RandomVector(distribution)
f = ot.SymbolicFunction(["x", "y"], ["x^2+y^2"])
Y = ot.RandomVector(f, X)
event = ot.Event(Y, ot.Greater(), threshold)
algo = ot.ProbabilitySimulationAlgorithm(event, ot.MonteCarloExperiment(1))
algo.setConvergenceStrategy(ot.Full())
algo.setMaximumOuterSampling(N)
algo.setMaximumCoefficientOfVariation(0.0)
algo.setMaximumStandardDeviation(0.0)
algo.run()
pRef = ot.ChiSquare(2).computeComplementaryCDF(threshold)

# Draw convergence
graph = algo.drawProbabilityConvergence()
graph.setXMargin(0.0)
graph.setLogScale(1)
graph.setLegendPosition("topright")
graph.setXTitle(r"n")
graph.setYTitle(r"$\hat{p}_n$")
graph.setTitle("Monte Carlo simulation - convergence history")
ref = ot.Curve([[1, pRef], [N, pRef]])
ref.setColor("black")
ref.setLineStyle("dashed")
ref.setLegend(r"$p_{ref}$")
Exemple #7
0
# coding: utf-8

import openturns as ot

R = ot.Normal(4., 1.)
R.setDescription("R")

S = ot.Normal(2., 1.)
S.setDescription("S")

g = ot.SymbolicFunction(["R","S"],["R-S"])

inputvector = ot.ComposedDistribution([R,S])
inputRV = ot.RandomVector(inputvector)
outputRV = ot.CompositeRandomVector(g, inputRV)
eventF = ot.Event(outputRV, ot.GreaterOrEqual(), 0) 

# Create the Monte-Carlo algorithm
algoProb = ot.ProbabilitySimulationAlgorithm(eventF)
algoProb.setMaximumOuterSampling(1000)
algoProb.setMaximumCoefficientOfVariation(0.01)
algoProb.run()

# Get the results
resultAlgo = algoProb.getResult()
neval = g.getEvaluationCallsNumber()
print("Number of function calls = %d" %(neval))
pf = resultAlgo.getProbabilityEstimate()
print("Failure Probability = %.4f" % (pf))
level = 0.95
c95 = resultAlgo.getConfidenceLength(level)
Exemple #8
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())
Exemple #9
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.SimulationResult(ot.Event(), 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()
        myStudy.add(cName, instance)

    # Create a Beta distribution
    beta = ot.Beta(3.0, 5.0, -1.0, 4.0)
    myStudy.add('beta', beta)
Exemple #10
0
    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.Event(), 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()
        myStudy.add(cName, instance)

    # Create a Beta distribution
    beta = ot.Beta(3.0, 5.0, -1.0, 4.0)
    myStudy.add('beta', beta)

    # Create an analytical Function
    input = ot.Description(3)
Exemple #11
0
parameters6 = ot.LogNormalMuSigma(40, 8, 0.0)
dist_X6 = ot.ParametrizedDistribution(parameters6)

myDistribution = ot.ComposedDistribution(
    [dist_X1, dist_X2, dist_X3, dist_X4, dist_X5, dist_X6])
myRandomVector = ot.RandomVector(myDistribution)

# Fonction
# ~ myFunction = ot.PythonFunction(2, 1, gfun_22)
myFunction = ot.PythonFunction(6, 1, gfun_8)

myOutputVector = ot.CompositeRandomVector(myFunction, myRandomVector)

# Evènement fiabiliste
event = ot.Event(myOutputVector, ot.LessOrEqual(), 0.0)

# ~ #Run FORM
# ~ FORM_result = run_FORM(event, myRandomVector, verbose=True,
#                          failure_domain=None)

# ~ #Run CMC

CMC_result = run_MonteCarlo(
    event,
    coefVar=0.01,
    outerSampling=3000,
    blockSize=100,
    verbose=True,
    failure_domain=None,
)
Exemple #12
0
# Case 1: composite random vector based event
#

# The input vector
X = ot.RandomVector(distribution)
# The model: the identity function
inVars = ot.Description(dim)
for i in range(dim):
    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.Event(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.Event(X, domain)

print("sample=", event.getSample(10))
Exemple #13
0
from __future__ import print_function
import openturns as ot

ot.TESTPREAMBLE()

model = ot.SymbolicFunction(['x0', 'x1', 'x2', 'x3'], ['-(6+x0^2-x1+x2+3*x3)'])
dim = model.getInputDimension()
marginals = [ot.Normal(5.0, 3.0) for i in range(dim)]
distribution = ot.ComposedDistribution(
    marginals, ot.ComposedCopula([ot.ClaytonCopula(),
                                  ot.NormalCopula()]))
#distribution = ot.Normal([5]*dim, [3]*dim, ot.CorrelationMatrix(dim))
#distribution = ot.ComposedDistribution(marginals, ot.IndependentCopula(dim))
distribution.setDescription(['marginal' + str(i) for i in range(dim)])
vect = ot.RandomVector(distribution)
output = ot.CompositeRandomVector(model, vect)
event = ot.Event(output, ot.Greater(), 0.0)
solver = ot.Cobyla()
solver.setMaximumEvaluationNumber(200)
solver.setMaximumAbsoluteError(1.0e-10)
solver.setMaximumRelativeError(1.0e-10)
solver.setMaximumResidualError(1.0e-10)
solver.setMaximumConstraintError(1.0e-10)
algo = ot.FORM(solver, event, distribution.getMean())
algo.run()
result = algo.getResult()
hasoferReliabilityIndexSensitivity = result.getHasoferReliabilityIndexSensitivity(
)
print(hasoferReliabilityIndexSensitivity)
Exemple #14
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.CompositeRandomVector(myFunction, vect)

# We create an Event from this RandomVector
myEvent = ot.Event(output, ot.Less(), -3.0)

# Monte Carlo
experiments = [ot.MonteCarloExperiment()]
# Quasi Monte Carlo
experiments.append(ot.LowDiscrepancyExperiment())
# Randomized Quasi Monte Carlo
experiment = ot.LowDiscrepancyExperiment()
experiment.setRandomize(True)
experiments.append(experiment)
# Importance sampling
mean[0] = 4.99689645939288809018e+01
mean[1] = 1.84194175946153282375e+00
mean[2] = 1.04454036676956398821e+01
mean[3] = 4.66776215562709406726e+00
myImportance = ot.Normal(mean, sigma, R)
    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.Event(), 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()
        myStudy.add(cName, instance)

    # Create a Beta distribution
    beta = ot.Beta(3.0, 5.0, -1.0, 4.0)
    myStudy.add('beta', beta)
Exemple #16
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
Exemple #17
0
Zm_law = ot.Triangular(54., 55., 56.)
coll = ot.DistributionCollection([Q_law, Ks_law, Zv_law, Zm_law])
distribution = ot.ComposedDistribution(coll)

x = list(map(lambda dist: dist.computeQuantile(0.5)[0], coll))
fx = function(x)

for k in [0.0, 2.0, 5.0, 8.][0:1]:
    randomVector = ot.RandomVector(distribution)
    composite = ot.RandomVector(function, randomVector)

    print('--------------------')
    print('model flood S <', k, 'gamma=', end=' ')
    print('f(', ot.NumericalPoint(x), ')=', fx)

    event = ot.Event(composite, ot.Greater(), k)
    for n in [100, 1000, 5000][1:2]:
        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 = otads.AdaptiveDirectionalSampling(event)
            algo.setMaximumOuterSampling(n)
            algo.setGamma([gamma1, 1.0 - gamma1])
            calls0 = function.getEvaluationCallsNumber()
            algo.run()
            calls = function.getEvaluationCallsNumber() - calls0
            result = algo.getResult()
Exemple #18
0
    graph.add(myPairs)
    # graph.draw('curve9.png')
    view = View(graph)
    # view.save('curve9.png')
    view.show()

    # Convergence graph curve
    aCollection = []
    aCollection.append(ot.LogNormalFactory().build(
        ot.LogNormalMuSigma()([300.0, 30.0, 0.0])))
    aCollection.append(ot.Normal(75e3, 5e3))
    myDistribution = ot.ComposedDistribution(aCollection)
    vect = ot.RandomVector(myDistribution)
    LimitState = ot.SymbolicFunction(('R', 'F'), ('R-F/(_pi*100.0)', ))
    G = ot.RandomVector(LimitState, vect)
    myEvent = ot.Event(G, ot.Less(), 0.0)
    experiment = ot.MonteCarloExperiment()
    myAlgo = ot.ProbabilitySimulationAlgorithm(myEvent, experiment)
    myAlgo.setMaximumCoefficientOfVariation(0.05)
    myAlgo.setMaximumOuterSampling(int(1e5))
    myAlgo.run()
    graph = myAlgo.drawProbabilityConvergence()
    # graph.draw('curve10.png')
    view = View(graph)
    # view.save('curve10.png')
    view.show()

    # Polygon
    size = 50
    cursor = [0.] * 2
    data1 = ot.Sample(size, 2)  # polygon y = 2x for x in [-25]
    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.RandomVector(f, X)
    # event = buildEvent(Y, domain)
    event = ot.Event(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)
def buildEvent(vector, interval):
    dimension = vector.getDimension()
    if dimension != interval.getDimension():
        raise Exception('Dimensions not compatible')
    finiteLowerBound = interval.getFiniteLowerBound()
    finiteUpperBound = interval.getFiniteUpperBound()
    lowerBound = interval.getLowerBound()
    upperBound = interval.getUpperBound()
    # Easy case: 1D interval
    if (dimension == 1):
        if finiteLowerBound[0] and not finiteUpperBound[0]:
            print('case 1')
            return ot.Event(vector, Greater(), lowerBound[0])
        if not finiteLowerBound[0] and finiteUpperBound[0]:
            print('case 2')
            return ot.Event(vector, Less(), upperBound[0])
        if finiteLowerBound[0] and finiteUpperBound[0]:
            print('case 3')
            testFunction = ot.SymbolicFunction(
                'x', 'min(x-(' + str(lowerBound[0]) + '), (' +
                str(upperBound[0]) + ') - x)')
            newVector = ot.RandomVector(
                ot.Function(testFunction, vector.getFunction()),
                vector.getAntecedent())
            return ot.Event(newVector, Greater(), 0.0)
        # Here we build an event that is always true and much cheaper to
        # compute
        print('case 4')
        inputDimension = vector.getFunction().getInputDimension()
        return ot.Event(
            ot.RandomVector(
                ot.SymbolicFunction(
                    ot.Description.BuildDefault(inputDimension, 'x'), ['0.0']),
                vector.getAntecedent()), Less(), 1.0)
    # General case
    numConstraints = 0
    inVars = ot.Description.BuildDefault(dimension, 'y')
    slacks = ot.Description(0)
    for i in range(dimension):
        if finiteLowerBound[i]:
            slacks.add(inVars[i] + '-(' + str(lowerBound[i]) + ')')
        if finiteUpperBound[i]:
            slacks.add('(' + str(upperBound[i]) + ')-' + inVars[i])
    # No constraint
    if slacks.getSize() == 0:
        # Here we build an event that is always true and much cheaper to
        # compute
        inputDimension = vector.getFunction().getInputDimension()
        return ot.Event(
            ot.RandomVector(
                ot.SymbolicFunction(
                    ot.Description.BuildDefault(inputDimension, 'x'), ['0.0']),
                vector.getAntecedent()), Less(), 1.0)
    # Only one constraint
    if slacks.getSize() == 1:
        print('case 6')
        testFunction = ot.SymbolicFunction(inVars, [slacks[0]])
    # Several constraints
    else:
        print('case 7')
        formula = 'min(' + slacks[0]
        for i in range(1, slacks.getSize()):
            formula += ',' + slacks[i]
        formula += ')'
        testFunction = ot.SymbolicFunction(inVars, [formula])
    newVector = ot.RandomVector(
        ot.Function(testFunction, vector.getFunction()),
        vector.getAntecedent())
    return ot.Event(newVector, Greater(), 0.0)
#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
G = ot.RandomVector(g, X_random_vector)
G.setDescription(['Deviation'])

# In[16]:

G_sample = G.getSample(int(1e3))
G_hist = ot.VisualTest_DrawHistogram(G_sample)
G_hist.setXTitle(G.getDescription()[0])
_ = View(G_hist, bar_kwargs={'label': 'G_sample'})

# # Event

# In[17]:

event = ot.Event(G, ot.GreaterOrEqual(), 30.)
event.setName("deviation > 30 cm")

# # Estimation of the event probability using (crude) Monte Carlo sampling

# In[18]:

g.clearHistory()

# In[19]:

ot.RandomGenerator.SetSeed(0)

# In[20]:

# create a Monte Carlo algorithm
Exemple #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()
Exemple #24
0
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.Event(Y1, ot.Less(), 0.0)
e2 = ot.Event(Y2, ot.Greater(), 0.0)

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

# sampling test
algo = ot.ProbabilitySimulationAlgorithm(e3)
algo.setMaximumOuterSampling(250)
algo.setBlockSize(4)
algo.setMaximumCoefficientOfVariation(-0.1)
algo.run()
print("proba_e3 = %.3g" % algo.getResult().getProbabilityEstimate())


e4 = e1.join(e2)