.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_reliability_sensitivity/reliability/plot_estimate_probability_importance_sampling.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_reliability_sensitivity_reliability_plot_estimate_probability_importance_sampling.py: Use the Importance Sampling algorithm ===================================== .. GENERATED FROM PYTHON SOURCE LINES 6-16 In this example we estimate a failure probability with the importance sampling simulation algorithm provided by the `ImportanceSamplingExperiment` class. The main steps of this method are: * run a FORM analysis, * create an importance distribution based on the results of the FORM results, * run a sampling-based probability estimate algorithm. We shall consider the analytical example of a :ref:`cantilever beam `. .. GENERATED FROM PYTHON SOURCE LINES 18-20 Define the cantilever beam model -------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 22-28 .. code-block:: Python from openturns.usecases import cantilever_beam import openturns as ot import openturns.viewer as viewer ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 29-30 The cantilever beam example can be accessed in the usecases module : .. GENERATED FROM PYTHON SOURCE LINES 30-32 .. code-block:: Python cb = cantilever_beam.CantileverBeam() .. GENERATED FROM PYTHON SOURCE LINES 33-34 The joint probability distribution of the input parameters is stored in the object `cb` : .. GENERATED FROM PYTHON SOURCE LINES 34-36 .. code-block:: Python distribution = cb.distribution .. GENERATED FROM PYTHON SOURCE LINES 37-38 We create the model. .. GENERATED FROM PYTHON SOURCE LINES 38-40 .. code-block:: Python model = cb.model .. GENERATED FROM PYTHON SOURCE LINES 41-43 Define the event ---------------- .. GENERATED FROM PYTHON SOURCE LINES 45-46 We create the event whose probability we want to estimate. .. GENERATED FROM PYTHON SOURCE LINES 48-52 .. code-block:: Python vect = ot.RandomVector(distribution) G = ot.CompositeRandomVector(model, vect) event = ot.ThresholdEvent(G, ot.Greater(), 0.30) .. GENERATED FROM PYTHON SOURCE LINES 53-55 Run a FORM analysis ------------------- .. GENERATED FROM PYTHON SOURCE LINES 57-58 Define a solver .. GENERATED FROM PYTHON SOURCE LINES 58-65 .. code-block:: Python optimAlgo = ot.Cobyla() optimAlgo.setMaximumEvaluationNumber(1000) optimAlgo.setMaximumAbsoluteError(1.0e-10) optimAlgo.setMaximumRelativeError(1.0e-10) optimAlgo.setMaximumResidualError(1.0e-10) optimAlgo.setMaximumConstraintError(1.0e-10) .. GENERATED FROM PYTHON SOURCE LINES 66-67 Run FORM .. GENERATED FROM PYTHON SOURCE LINES 67-71 .. code-block:: Python algo = ot.FORM(optimAlgo, event, distribution.getMean()) algo.run() result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 72-74 Configure an importance sampling algorithm ------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 76-77 The `getStandardSpaceDesignPoint` method returns the design point in the U-space. .. GENERATED FROM PYTHON SOURCE LINES 79-82 .. code-block:: Python standardSpaceDesignPoint = result.getStandardSpaceDesignPoint() standardSpaceDesignPoint .. raw:: html
class=Point name=Standard Space Design Point dimension=4 values=[-0.665643,4.31264,1.23029,-1.3689]


.. GENERATED FROM PYTHON SOURCE LINES 83-84 The key point is to define the importance distribution in the U-space. To define it, we use a multivariate standard Gaussian centered around the design point in the U-space. .. GENERATED FROM PYTHON SOURCE LINES 86-89 .. code-block:: Python dimension = distribution.getDimension() dimension .. rst-class:: sphx-glr-script-out .. code-block:: none 4 .. GENERATED FROM PYTHON SOURCE LINES 90-94 .. code-block:: Python myImportance = ot.Normal(dimension) myImportance.setMu(standardSpaceDesignPoint) myImportance .. raw:: html
Normal
  • name=Normal
  • dimension=4
  • weight=1
  • range=]-inf (-8.31627), (6.98499) +inf[ ]-inf (-3.33799), (11.9633) +inf[ ]-inf (-6.42034), (8.88091) +inf[ ]-inf (-9.01953), (6.28172) +inf[
  • description=[X0,X1,X2,X3]
  • isParallel=true
  • isCopula=false


.. GENERATED FROM PYTHON SOURCE LINES 95-96 Create the design of experiment corresponding to importance sampling. This generates a `WeightedExperiment` with weights fitting to the importance distribution. .. GENERATED FROM PYTHON SOURCE LINES 98-101 .. code-block:: Python experiment = ot.ImportanceSamplingExperiment(myImportance) type(experiment) .. GENERATED FROM PYTHON SOURCE LINES 102-103 Create the standard event corresponding to the event. This pushes the original problem to the U-space, with Gaussian independent marginals. .. GENERATED FROM PYTHON SOURCE LINES 105-107 .. code-block:: Python standardEvent = ot.StandardEvent(event) .. GENERATED FROM PYTHON SOURCE LINES 108-110 Run the importance sampling simulation -------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 112-113 We then create the simulation algorithm. .. GENERATED FROM PYTHON SOURCE LINES 115-120 .. code-block:: Python algo = ot.ProbabilitySimulationAlgorithm(standardEvent, experiment) algo.setMaximumCoefficientOfVariation(0.1) algo.setMaximumOuterSampling(40000) algo.run() .. GENERATED FROM PYTHON SOURCE LINES 121-122 We can retrieve results of this estimate : .. GENERATED FROM PYTHON SOURCE LINES 122-126 .. code-block:: Python result = algo.getResult() probability = result.getProbabilityEstimate() print("Probability = ", probability) .. rst-class:: sphx-glr-script-out .. code-block:: none Probability = 5.108962790908332e-07 .. GENERATED FROM PYTHON SOURCE LINES 127-129 In order to compute the confidence interval, we use the `getConfidenceLength` method, which returns the length of the interval. In order to compute the bounds of the interval, we divide this length by 2. .. GENERATED FROM PYTHON SOURCE LINES 131-133 .. code-block:: Python alpha = 0.05 .. GENERATED FROM PYTHON SOURCE LINES 134-140 .. code-block:: Python pflen = result.getConfidenceLength(1 - alpha) print( "%.2f%% confidence interval = [%.10f,%.10f]" % ((1 - alpha) * 100, probability - pflen / 2, probability + pflen / 2) ) .. rst-class:: sphx-glr-script-out .. code-block:: none 95.00% confidence interval = [0.0000004108,0.0000006110] .. GENERATED FROM PYTHON SOURCE LINES 141-143 We can observe the convergence history of the estimate with the `drawProbabilityConvergence` method which displays the estimate and confidence interval evolution. .. GENERATED FROM PYTHON SOURCE LINES 143-146 .. code-block:: Python graph = algo.drawProbabilityConvergence() graph.setLogScale(ot.GraphImplementation.LOGX) view = viewer.View(graph) .. image-sg:: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_estimate_probability_importance_sampling_001.png :alt: ProbabilitySimulationAlgorithm convergence graph at level 0.95 :srcset: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_estimate_probability_importance_sampling_001.png :class: sphx-glr-single-img .. _sphx_glr_download_auto_reliability_sensitivity_reliability_plot_estimate_probability_importance_sampling.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_estimate_probability_importance_sampling.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_estimate_probability_importance_sampling.py `