.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_reliability/reliability_analysis/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_reliability_analysis_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-20 .. code-block:: Python import openturns as ot import openturns.viewer as otv .. GENERATED FROM PYTHON SOURCE LINES 21-22 Create the joint distribution of the parameters. .. GENERATED FROM PYTHON SOURCE LINES 22-27 .. 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.JointDistribution(marginals) .. GENERATED FROM PYTHON SOURCE LINES 28-29 Create the model. .. GENERATED FROM PYTHON SOURCE LINES 29-31 .. code-block:: Python model = ot.SymbolicFunction(["R", "F"], ["R-F/(pi_*100.0)"]) .. GENERATED FROM PYTHON SOURCE LINES 32-36 .. code-block:: Python modelCallNumberBefore = model.getEvaluationCallsNumber() modelGradientCallNumberBefore = model.getGradientCallsNumber() modelHessianCallNumberBefore = model.getHessianCallsNumber() .. GENERATED FROM PYTHON SOURCE LINES 37-38 To have access to the input and output samples after the simulation, activate the History mechanism. .. GENERATED FROM PYTHON SOURCE LINES 40-42 .. code-block:: Python model = ot.MemoizeFunction(model) .. GENERATED FROM PYTHON SOURCE LINES 43-45 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 47-49 .. code-block:: Python model.clearHistory() .. GENERATED FROM PYTHON SOURCE LINES 50-51 Create the event whose probability we want to estimate. .. GENERATED FROM PYTHON SOURCE LINES 53-57 .. 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 58-59 Create a Monte Carlo algorithm. .. GENERATED FROM PYTHON SOURCE LINES 61-67 .. 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 68-70 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 72-76 .. code-block:: Python N = 1000 algo.setConvergenceStrategy(ot.Compact(N)) algo.run() .. GENERATED FROM PYTHON SOURCE LINES 77-78 Retrieve result structure. .. GENERATED FROM PYTHON SOURCE LINES 80-82 .. code-block:: Python result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 83-84 Display the simulation event probability. .. GENERATED FROM PYTHON SOURCE LINES 86-88 .. code-block:: Python result.getProbabilityEstimate() .. rst-class:: sphx-glr-script-out .. code-block:: none 0.030580075662042867 .. GENERATED FROM PYTHON SOURCE LINES 89-90 Criteria 3 : Display the Standard Deviation of the estimator .. GENERATED FROM PYTHON SOURCE LINES 90-92 .. code-block:: Python result.getStandardDeviation() .. rst-class:: sphx-glr-script-out .. code-block:: none 0.003057093060511293 .. GENERATED FROM PYTHON SOURCE LINES 93-94 Display the variance of the simulation probability estimator. .. GENERATED FROM PYTHON SOURCE LINES 96-98 .. code-block:: Python result.getVarianceEstimate() .. rst-class:: sphx-glr-script-out .. code-block:: none 9.345817980626304e-06 .. GENERATED FROM PYTHON SOURCE LINES 99-100 Criteria 2 : Display the number of iterations of the simulation .. GENERATED FROM PYTHON SOURCE LINES 100-102 .. code-block:: Python result.getOuterSampling() .. rst-class:: sphx-glr-script-out .. code-block:: none 3172 .. GENERATED FROM PYTHON SOURCE LINES 103-104 Display the total number of evaluations of the model .. GENERATED FROM PYTHON SOURCE LINES 104-106 .. code-block:: Python result.getOuterSampling() * result.getBlockSize() .. rst-class:: sphx-glr-script-out .. code-block:: none 3172 .. GENERATED FROM PYTHON SOURCE LINES 107-108 Save the number of calls to the model, its gradient and hessian done so far. .. GENERATED FROM PYTHON SOURCE LINES 110-114 .. code-block:: Python modelCallNumberAfter = model.getEvaluationCallsNumber() modelGradientCallNumberAfter = model.getGradientCallsNumber() modelHessianCallNumberAfter = model.getHessianCallsNumber() .. GENERATED FROM PYTHON SOURCE LINES 115-116 Display the number of iterations executed and the number of evaluations of the model. .. GENERATED FROM PYTHON SOURCE LINES 118-120 .. code-block:: Python modelCallNumberAfter - modelCallNumberBefore .. rst-class:: sphx-glr-script-out .. code-block:: none 3172 .. GENERATED FROM PYTHON SOURCE LINES 121-122 Get the mean point in event domain care : only for Monte Carlo and LHS sampling methods. .. GENERATED FROM PYTHON SOURCE LINES 124-126 .. code-block:: Python result.getMeanPointInEventDomain() .. raw:: html
class=Point name=Unnamed dimension=2 values=[245.843,80222]


.. GENERATED FROM PYTHON SOURCE LINES 127-128 Get the associated importance factors care : only for Monte Carlo and LHS sampling methods. .. GENERATED FROM PYTHON SOURCE LINES 130-132 .. code-block:: Python result.getImportanceFactors() .. raw:: html
class=PointWithDescription name=Unnamed dimension=2 description=[X0,X1] values=[0.776373,0.223627]


.. GENERATED FROM PYTHON SOURCE LINES 133-136 .. code-block:: Python graph = result.drawImportanceFactors() view = otv.View(graph) .. image-sg:: /auto_reliability/reliability_analysis/images/sphx_glr_plot_probability_simulation_results_001.svg :alt: Importance Factors from Simulation - v0 :srcset: /auto_reliability/reliability_analysis/images/sphx_glr_plot_probability_simulation_results_001.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 137-144 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 146-157 .. 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.011983584591978923 IC at 0.95 = [ 0.024588283366053405 ; 0.03657186795803233 ] .. GENERATED FROM PYTHON SOURCE LINES 158-159 Draw the convergence graph and the confidence interval of level alpha. By default, alpha = 0.95. .. GENERATED FROM PYTHON SOURCE LINES 161-165 .. code-block:: Python alpha = 0.90 graph = algo.drawProbabilityConvergence(alpha) view = otv.View(graph) .. image-sg:: /auto_reliability/reliability_analysis/images/sphx_glr_plot_probability_simulation_results_002.svg :alt: ProbabilitySimulationAlgorithm convergence graph at level 0.9 :srcset: /auto_reliability/reliability_analysis/images/sphx_glr_plot_probability_simulation_results_002.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 166-167 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 169-173 .. code-block:: Python inputSampleStored = model.getInputHistory() outputSampleStored = model.getOutputHistory() inputSampleStored .. raw:: html
v0v1
0317.182268669.13
1285.742181027.39
2240.137476750.21
...
3169266.956374830.12
3170282.28578480.19
3171247.172481708.23


.. GENERATED FROM PYTHON SOURCE LINES 174-175 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 177-181 .. code-block:: Python estimator_probability_sample = algo.getConvergenceStrategy().getSample()[0] estimator_variance_sample = algo.getConvergenceStrategy().getSample()[1] print(estimator_probability_sample, estimator_variance_sample) .. rst-class:: sphx-glr-script-out .. code-block:: none [0,-1,2] [0.25,0.046875,4] .. GENERATED FROM PYTHON SOURCE LINES 182-183 .. code-block:: Python otv.View.ShowAll() .. _sphx_glr_download_auto_reliability_reliability_analysis_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 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_probability_simulation_results.zip `