Demonstration of the DrawEvent class

import otbenchmark as otb
import openturns.viewer as otv

3D problem

problem = otb.ReliabilityProblem33()
event = problem.getEvent()
g = event.getFunction()
inputVector = event.getAntecedent()
distribution = inputVector.getDistribution()
inputDimension = distribution.getDimension()
inputDimension
3
alpha = 1 - 0.00001
bounds, marginalProb = distribution.computeMinimumVolumeIntervalWithMarginalProbability(
    alpha
)
referencePoint = distribution.getMean()
referencePoint
class=Point name=Unnamed dimension=3 values=[0,0,0]


inputVector = event.getAntecedent()
event = problem.getEvent()
g = event.getFunction()
drawEvent = otb.DrawEvent(event)

The highest level method is the draw method which flags allow to gather various graphics into a single one.

_ = drawEvent.draw(bounds)
plot drawevent
_ = drawEvent.draw(bounds, fillEvent=True)
plot drawevent

The drawLimitState method only draws the limit state.

_ = drawEvent.drawLimitState(bounds)
Limit state surface

The drawSample method plots a sample with a color code which specifies which points are inside or outside the event.

sampleSize = 500
_ = drawEvent.drawSample(sampleSize)
Points X s.t. g(X) < 0.0
_ = drawEvent.fillEvent(bounds)
Domain where g(x) < 0.0

2D problem

When the problem has 2 dimensions, single cross-cuts are sufficient. This is why we use the *CrossCut methods.

problem = otb.ReliabilityProblem22()
event = problem.getEvent()
g = event.getFunction()
inputVector = event.getAntecedent()
distribution = inputVector.getDistribution()
bounds, marginalProb = distribution.computeMinimumVolumeIntervalWithMarginalProbability(
    1.0 - 1.0e-6
)
sampleSize = 10000
drawEvent = otb.DrawEvent(event)
cloud = drawEvent.drawSampleCrossCut(sampleSize)
_ = otv.View(cloud)
Points X s.t. g(X) < 0.0
graph = drawEvent.drawLimitStateCrossCut(bounds)
graph.add(cloud)
_ = otv.View(graph)
Limit state surface
domain = drawEvent.fillEventCrossCut(bounds)
_ = otv.View(domain)
Domain where g(x) < 0.0
domain.add(cloud)
_ = otv.View(domain)
Domain where g(x) < 0.0

For a 2D sample, it is sometimes handy to re-use a precomputed sample. In this case, we can use the drawInputOutputSample method.

inputSample = distribution.getSample(sampleSize)
outputSample = g(inputSample)
drawEvent.drawInputOutputSample(inputSample, outputSample)
class=Graph name=Points X s.t. g(X) < 0.0 implementation=class=GraphImplementation name=Points X s.t. g(X) < 0.0 title=Points X s.t. g(X) < 0.0 xTitle=x1 yTitle=x2 axes=ON grid=ON legendposition=topright legendFontSize=10 drawables=[class=Drawable name=In implementation=class=Cloud name=In derived from class=DrawableImplementation name=In legend=In data=class=Sample name=Unnamed implementation=class=SampleImplementation name=Unnamed size=45 dimension=2 data=[[1.31277,2.71965],[3.3156,1.75571],[2.39195,1.47957],[1.60998,2.24372],[1.63643,2.08429],[1.72699,2.40801],[1.70214,1.97907],[1.66599,2.458],[2.18981,2.13144],[2.35059,1.75888],[1.493,2.11724],[2.99962,2.3627],[2.0186,1.85621],[1.80202,1.89287],[2.46352,1.87437],[2.77727,1.76564],[2.01074,2.15434],[1.60727,2.2611],[1.73981,1.88563],[1.54588,2.18626],[1.25568,3.22663],[3.44257,1.72667],[1.37209,2.79427],[1.14985,2.91308],[1.50868,3.02561],[1.93849,1.79072],[2.55903,1.23827],[2.64312,1.24703],[2.17579,2.19339],[2.209,3.03567],[2.48116,1.35506],[1.51661,2.09154],[2.09857,1.61811],[1.18732,3.40859],[1.56785,2.1641],[1.81553,2.12308],[1.75984,1.78651],[1.16883,3.94239],[1.44968,2.40717],[2.47853,1.82188],[1.76621,3.37416],[2.14632,1.91885],[1.7506,2.22008],[1.62437,2.71087],[1.83597,1.94489]] color=lightsalmon3 isColorExplicitlySet=true fillStyle=solid lineStyle=solid pointStyle=fsquare lineWidth=1,class=Drawable name=Out implementation=class=Cloud name=Out derived from class=DrawableImplementation name=Out legend=Out data=class=Sample name=Unnamed implementation=class=SampleImplementation name=Unnamed size=9955 dimension=2 data=[[-0.0579683,0.599561],[1.38318,0.46516],[-1.5327,0.487696],...,[0.0409517,-0.450823],[0.0887536,0.375381],[-1.52652,-0.952439]] color=darkseagreen3 isColorExplicitlySet=true fillStyle=solid lineStyle=solid pointStyle=fsquare lineWidth=1]
otv.View.ShowAll()

Total running time of the script: (0 minutes 5.699 seconds)