Example #1
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.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))
# a :class:`~openturns.CompositeRandomVector` by using the model.
vecX = ot.RandomVector(distX)
vecY = ot.CompositeRandomVector(f, vecX)

# %%
# Definition and vizualisation of a domain event
# ----------------------------------------------
#

# %%
# We define for each marginals of the output random vector `vecY` a domain of interest, say :math:`[0,1] \times [0,1]`
domain = ot.Interval([0.0, 0.0], [1.0, 1.0])

# %%
# The :class:`~openturns.DomainEvent` is then built from the output random vector `vecY` and the `domain` :
event = ot.DomainEvent(vecY, domain)

# %%
# This domain is
#
# .. math::
#
#    \mathcal{D} = \{ \vect{x}=(x_1, x_2) \in \mathbb{R}^2 \; | \; x_1+x_2 \in [0,1] \; \mathrm{and} \; 2x_1 \in [0,1] \}.
#
#

# %%
# We plot both marginals of the model and the domain of interest for each marginal using contour curves.
#

# %%
    # MinimumVolumeInterval
    probability = 0.9
    interval = distribution.computeMinimumVolumeIntervalWithMarginalProbability(probability)[
        0]
    CDF_up = distribution.computeCDF(interval.getUpperBound())
    CDF_low = distribution.computeCDF(interval.getLowerBound())
    computed_probability = CDF_up - CDF_low
    ott.assert_almost_equal(
        probability, computed_probability, 1e-5, 1e-5, str(distribution))

    # MinimumVolumeLevelSet
    probability = 0.9
    levelSet, threshold = distribution.computeMinimumVolumeLevelSetWithThreshold(
        probability)
    event = ot.DomainEvent(ot.RandomVector(distribution), levelSet)
    algo = ot.ProbabilitySimulationAlgorithm(event)
    algo.setBlockSize(int(1e6))
    algo.setMaximumOuterSampling(1)
    algo.run()
    p = algo.getResult().getProbabilityEstimate()
    if distribution.getName() != 'Histogram':
        ott.assert_almost_equal(p, probability, 1e-3, 1e-3, str(distribution))

    # parameters
    p = distribution.getParameter()
    pd = distribution.getParameterDescription()
    pc = distribution.getParametersCollection()
    assert len(p) == len(pd), "len p/pd"
    assert len(pc) == 1, "len(pc)"
    assert len(p) == len(pc[0]), "len p/pc"
Example #4
0
print('-' * 32)
ot.RandomGenerator.SetSeed(0)
description = ot.Description()
description.add('composite vector/comparison event')
dim = 2
distribution = ot.Normal(dim)
Xvector = ot.RandomVector(distribution)
f = ot.SymbolicFunction(['x0', 'x1'], ['x0+x1'])
Yvector = ot.CompositeRandomVector(f, Xvector)
s = 1.0
event1 = ot.ThresholdEvent(Yvector, ot.Greater(), s)
description.add('composite vector/domain event')
domain1D = ot.LevelSet(ot.SymbolicFunction(
    ['x0'], ['sin(x0)']), ot.LessOrEqual(), -0.5)
event2 = ot.DomainEvent(Yvector, domain1D)
description.add('composite vector/interval event')
interval = ot.Interval(0.5, 1.5)
event3 = ot.ThresholdEvent(Yvector, interval)
description.add('process/domain event')
Xprocess = ot.WhiteNoise(distribution, ot.RegularGrid(0.0, 0.1, 10))
domain2D = ot.LevelSet(
    ot.SymbolicFunction(['x0', 'x1'], ['(x0-1)^2+x1^2']), ot.LessOrEqual(), 1.0)
event4 = ot.ProcessEvent(Xprocess, domain2D)
all_events = [event1, event2, event3, event4]
for i, event in enumerate(all_events):
    print(description[i])
    if event.isComposite():
        experiment = ot.MonteCarloExperiment()
        myAlgo = ot.ProbabilitySimulationAlgorithm(event, experiment)
    else: