1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
"""
Use the Directional Sampling Algorithm
======================================
"""
# %%
# In this example we estimate a failure probability with the directional simulation algorithm provided by the :class:`~openturns.DirectionalSampling` class.
# %%
# Introduction
# ------------
#
# The directional simulation algorithm operates in the standard space based on:
#
# 1. a *root strategy* to evaluate the nearest failure point along each direction and take the contribution of each direction to the failure event probability into account.
# The available strategies are:
# - `RiskyAndFast`
# - `MediumSafe`
# - `SafeAndSlow`
#
# 2. a *sampling strategy* to choose directions in the standard space. The available strategies are:
# - `RandomDirection`
# - `OrthogonalDirection`
#
# Let us consider the analytical example of the cantilever beam described :ref:`here <use-case-cantilever-beam>`.
#
# %%
from openturns.usecases import cantilever_beam
import openturns as ot
import openturns.viewer as otv
# %%
# We load the model from the usecases module :
cb = cantilever_beam.CantileverBeam()
# %%
# We load the joint probability distribution of the input parameters :
distribution = cb.distribution
# %%
# We load the model giving the displacement at the end of the beam :
model = cb.model
# %%
# We 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.30)
# %%
# Root finding algorithm.
# %%
solver = ot.Brent()
rootStrategy = ot.MediumSafe(solver)
# %%
# Direction sampling algorithm.
# %%
samplingStrategy = ot.OrthogonalDirection()
# %%
# Create a simulation algorithm.
# %%
algo = ot.DirectionalSampling(event, rootStrategy, samplingStrategy)
algo.setMaximumCoefficientOfVariation(0.1)
algo.setMaximumOuterSampling(40000)
algo.setConvergenceStrategy(ot.Full())
algo.run()
# %%
# Retrieve results.
# %%
result = algo.getResult()
probability = result.getProbabilityEstimate()
print("Pf=", probability)
# %%
# We can observe the convergence history with the `drawProbabilityConvergence`
# method.
graph = algo.drawProbabilityConvergence()
graph.setLogScale(ot.GraphImplementation.LOGX)
view = otv.View(graph)
# %%
# Display all figures
otv.View.ShowAll()
|