# Use the Adaptive Directional Sampling Algorithm¶

In this example we estimate a failure probability with the adaptive directional simulation algorithm provided by the `AdaptiveDirectionalSampling` class.

## Introduction¶

The adaptive directional simulation algorithm operates in the standard. It relies 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 here.

```from __future__ import print_function
import openturns as ot
import openturns.viewer as viewer
from matplotlib import pylab as plt
ot.Log.Show(ot.Log.NONE)
```

We load the model from the usecases module :

```from openturns.usecases import cantilever_beam as cantilever_beam
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.RandomDirection()
```

Create a simulation algorithm.

```algo = ot.AdaptiveDirectionalSampling(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( result )
print('Pf=', probability)
```

Out:

```probabilityEstimate=4.858973e-07 varianceEstimate=1.396794e-19 standard deviation=3.74e-10 coefficient of variation=7.69e-04 confidenceLength(0.95)=1.47e-09 outerSampling=39997 blockSize=1
Pf= 4.858972851698883e-07
```

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

Gallery generated by Sphinx-Gallery