.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_reliability_sensitivity/reliability/plot_probability_simulation_results.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_probability_simulation_results.py: Exploitation of simulation algorithm results ============================================ .. GENERATED FROM PYTHON SOURCE LINES 7-15 In this example we are going to retrieve all the results proposed by probability simulation algorithms: - the probability estimate - the estimator variance - the confidence interval - the convergence graph of the estimator - the stored input and output numerical samples - importance factors .. GENERATED FROM PYTHON SOURCE LINES 17-23 .. code-block:: Python import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 24-25 Create the joint distribution of the parameters. .. GENERATED FROM PYTHON SOURCE LINES 27-32 .. code-block:: Python distribution_R = ot.LogNormalMuSigma(300.0, 30.0, 0.0).getDistribution() distribution_F = ot.Normal(75e3, 5e3) marginals = [distribution_R, distribution_F] distribution = ot.ComposedDistribution(marginals) .. GENERATED FROM PYTHON SOURCE LINES 33-34 Create the model. .. GENERATED FROM PYTHON SOURCE LINES 36-38 .. code-block:: Python model = ot.SymbolicFunction(["R", "F"], ["R-F/(pi_*100.0)"]) .. GENERATED FROM PYTHON SOURCE LINES 39-43 .. code-block:: Python modelCallNumberBefore = model.getEvaluationCallsNumber() modelGradientCallNumberBefore = model.getGradientCallsNumber() modelHessianCallNumberBefore = model.getHessianCallsNumber() .. GENERATED FROM PYTHON SOURCE LINES 44-45 To have access to the input and output samples after the simulation, activate the History mechanism. .. GENERATED FROM PYTHON SOURCE LINES 47-49 .. code-block:: Python model = ot.MemoizeFunction(model) .. GENERATED FROM PYTHON SOURCE LINES 50-52 Remove all the values stored in the history mechanism. Care : it is done regardless the status of the History mechanism. .. GENERATED FROM PYTHON SOURCE LINES 54-56 .. code-block:: Python model.clearHistory() .. GENERATED FROM PYTHON SOURCE LINES 57-58 Create the event whose probability we want to estimate. .. GENERATED FROM PYTHON SOURCE LINES 60-64 .. code-block:: Python vect = ot.RandomVector(distribution) G = ot.CompositeRandomVector(model, vect) event = ot.ThresholdEvent(G, ot.Less(), 0.0) .. GENERATED FROM PYTHON SOURCE LINES 65-66 Create a Monte Carlo algorithm. .. GENERATED FROM PYTHON SOURCE LINES 68-74 .. code-block:: Python experiment = ot.MonteCarloExperiment() algo = ot.ProbabilitySimulationAlgorithm(event, experiment) algo.setMaximumCoefficientOfVariation(0.1) algo.setMaximumStandardDeviation(0.001) algo.setMaximumOuterSampling(int(1e4)) .. GENERATED FROM PYTHON SOURCE LINES 75-77 Define the HistoryStrategy to store the values of :math:`P_n` and :math:`\sigma_n` used ot draw the convergence graph. Compact strategy : N points .. GENERATED FROM PYTHON SOURCE LINES 79-83 .. code-block:: Python N = 1000 algo.setConvergenceStrategy(ot.Compact(N)) algo.run() .. GENERATED FROM PYTHON SOURCE LINES 84-85 Retrieve result structure. .. GENERATED FROM PYTHON SOURCE LINES 87-89 .. code-block:: Python result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 90-91 Display the simulation event probability. .. GENERATED FROM PYTHON SOURCE LINES 93-95 .. code-block:: Python result.getProbabilityEstimate() .. rst-class:: sphx-glr-script-out .. code-block:: none 0.028340080971659926 .. GENERATED FROM PYTHON SOURCE LINES 96-97 Criteria 3 : Display the Standard Deviation of the estimator .. GENERATED FROM PYTHON SOURCE LINES 97-99 .. code-block:: Python result.getStandardDeviation() .. rst-class:: sphx-glr-script-out .. code-block:: none 0.0028219232200701353 .. GENERATED FROM PYTHON SOURCE LINES 100-101 Display the variance of the simulation probability estimator. .. GENERATED FROM PYTHON SOURCE LINES 103-105 .. code-block:: Python result.getVarianceEstimate() .. rst-class:: sphx-glr-script-out .. code-block:: none 7.963250659971002e-06 .. GENERATED FROM PYTHON SOURCE LINES 106-107 Criteria 2 : Display the number of iterations of the simulation .. GENERATED FROM PYTHON SOURCE LINES 107-109 .. code-block:: Python result.getOuterSampling() .. rst-class:: sphx-glr-script-out .. code-block:: none 3458 .. GENERATED FROM PYTHON SOURCE LINES 110-111 Display the total number of evaluations of the model .. GENERATED FROM PYTHON SOURCE LINES 111-113 .. code-block:: Python result.getOuterSampling() * result.getBlockSize() .. rst-class:: sphx-glr-script-out .. code-block:: none 3458 .. GENERATED FROM PYTHON SOURCE LINES 114-115 Save the number of calls to the model, its gradient and hessian done so far. .. GENERATED FROM PYTHON SOURCE LINES 117-121 .. code-block:: Python modelCallNumberAfter = model.getEvaluationCallsNumber() modelGradientCallNumberAfter = model.getGradientCallsNumber() modelHessianCallNumberAfter = model.getHessianCallsNumber() .. GENERATED FROM PYTHON SOURCE LINES 122-123 Display the number of iterations executed and the number of evaluations of the model. .. GENERATED FROM PYTHON SOURCE LINES 125-127 .. code-block:: Python modelCallNumberAfter - modelCallNumberBefore .. rst-class:: sphx-glr-script-out .. code-block:: none 3458 .. GENERATED FROM PYTHON SOURCE LINES 128-129 Get the mean point in event domain care : only for Monte Carlo and LHS sampling methods. .. GENERATED FROM PYTHON SOURCE LINES 131-133 .. code-block:: Python result.getMeanPointInEventDomain() .. raw:: html
class=Point name=Unnamed dimension=2 values=[247.145,81191.1]


.. GENERATED FROM PYTHON SOURCE LINES 134-135 Get the associated importance factors care : only for Monte Carlo and LHS sampling methods. .. GENERATED FROM PYTHON SOURCE LINES 137-139 .. code-block:: Python result.getImportanceFactors() .. raw:: html
class=PointWithDescription name=Unnamed dimension=2 description=[X0,X1] values=[0.700364,0.299636]


.. GENERATED FROM PYTHON SOURCE LINES 140-143 .. code-block:: Python graph = result.drawImportanceFactors() view = viewer.View(graph) .. image-sg:: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_probability_simulation_results_001.png :alt: Importance Factors from Simulation - v0 :srcset: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_probability_simulation_results_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 144-151 Display the confidence interval length centered around the MonteCarlo probability. The confidence interval is .. math:: IC = [\tilde{p} - 0.5 \ell, \tilde{p} + 0.5 \ell] with level 0.95, where :math:`\tilde{p}` is the estimated probability and :math:`\ell` is the confidence interval length. .. GENERATED FROM PYTHON SOURCE LINES 153-164 .. code-block:: Python probability = result.getProbabilityEstimate() length95 = result.getConfidenceLength(0.95) print("0.95 Confidence Interval length = ", length95) print( "IC at 0.95 = [", probability - 0.5 * length95, "; ", probability + 0.5 * length95, "]", ) .. rst-class:: sphx-glr-script-out .. code-block:: none 0.95 Confidence Interval length = 0.011061735756949524 IC at 0.95 = [ 0.022809213093185163 ; 0.03387094885013469 ] .. GENERATED FROM PYTHON SOURCE LINES 165-166 Draw the convergence graph and the confidence interval of level alpha. By default, alpha = 0.95. .. GENERATED FROM PYTHON SOURCE LINES 168-172 .. code-block:: Python alpha = 0.90 graph = algo.drawProbabilityConvergence(alpha) view = viewer.View(graph) .. image-sg:: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_probability_simulation_results_002.png :alt: ProbabilitySimulationAlgorithm convergence graph at level 0.9 :srcset: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_probability_simulation_results_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 173-174 Get the numerical samples of the input and output random vectors stored according to the History Strategy specified and used to evaluate the probability estimator and its variance. .. GENERATED FROM PYTHON SOURCE LINES 176-180 .. code-block:: Python inputSampleStored = model.getInputHistory() outputSampleStored = model.getOutputHistory() inputSampleStored .. raw:: html
v0v1
0313.315767742.49
1235.27171457.94
2352.658375848.37
...
3455309.844176286.06
3456312.050884510.8
3457252.146179243.84


.. GENERATED FROM PYTHON SOURCE LINES 181-182 Get the values of the estimator and its variance stored according to the History Strategy specified and used to draw the convergence graph. .. GENERATED FROM PYTHON SOURCE LINES 184-188 .. code-block:: Python estimator_probability_sample = algo.getConvergenceStrategy().getSample()[0] estimator_variance_sample = algo.getConvergenceStrategy().getSample()[1] print(estimator_probability_sample, estimator_variance_sample) plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none [0,-1] [0,-1] .. _sphx_glr_download_auto_reliability_sensitivity_reliability_plot_probability_simulation_results.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_probability_simulation_results.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_probability_simulation_results.py `