.. 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-22 .. code-block:: Python import openturns as ot import openturns.viewer as viewer from matplotlib import pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 23-24 Create the joint distribution of the parameters. .. GENERATED FROM PYTHON SOURCE LINES 26-31 .. 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 32-33 Create the model. .. GENERATED FROM PYTHON SOURCE LINES 35-37 .. code-block:: Python model = ot.SymbolicFunction(["R", "F"], ["R-F/(pi_*100.0)"]) .. GENERATED FROM PYTHON SOURCE LINES 38-42 .. code-block:: Python modelCallNumberBefore = model.getEvaluationCallsNumber() modelGradientCallNumberBefore = model.getGradientCallsNumber() modelHessianCallNumberBefore = model.getHessianCallsNumber() .. GENERATED FROM PYTHON SOURCE LINES 43-44 To have access to the input and output samples after the simulation, activate the History mechanism. .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: Python model = ot.MemoizeFunction(model) .. GENERATED FROM PYTHON SOURCE LINES 49-51 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 53-55 .. code-block:: Python model.clearHistory() .. GENERATED FROM PYTHON SOURCE LINES 56-57 Create the event whose probability we want to estimate. .. GENERATED FROM PYTHON SOURCE LINES 59-63 .. 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 64-65 Create a Monte Carlo algorithm. .. GENERATED FROM PYTHON SOURCE LINES 67-73 .. 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 74-76 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 78-82 .. code-block:: Python N = 1000 algo.setConvergenceStrategy(ot.Compact(N)) algo.run() .. GENERATED FROM PYTHON SOURCE LINES 83-84 Retrieve result structure. .. GENERATED FROM PYTHON SOURCE LINES 86-88 .. code-block:: Python result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 89-90 Display the simulation event probability. .. GENERATED FROM PYTHON SOURCE LINES 92-94 .. code-block:: Python result.getProbabilityEstimate() .. rst-class:: sphx-glr-script-out .. code-block:: none 0.030580075662042867 .. GENERATED FROM PYTHON SOURCE LINES 95-96 Criteria 3 : Display the Standard Deviation of the estimator .. GENERATED FROM PYTHON SOURCE LINES 96-98 .. code-block:: Python result.getStandardDeviation() .. rst-class:: sphx-glr-script-out .. code-block:: none 0.003057093060511293 .. GENERATED FROM PYTHON SOURCE LINES 99-100 Display the variance of the simulation probability estimator. .. GENERATED FROM PYTHON SOURCE LINES 102-104 .. code-block:: Python result.getVarianceEstimate() .. rst-class:: sphx-glr-script-out .. code-block:: none 9.345817980626304e-06 .. GENERATED FROM PYTHON SOURCE LINES 105-106 Criteria 2 : Display the number of iterations of the simulation .. GENERATED FROM PYTHON SOURCE LINES 106-108 .. code-block:: Python result.getOuterSampling() .. rst-class:: sphx-glr-script-out .. code-block:: none 3172 .. GENERATED FROM PYTHON SOURCE LINES 109-110 Display the total number of evaluations of the model .. GENERATED FROM PYTHON SOURCE LINES 110-112 .. code-block:: Python result.getOuterSampling() * result.getBlockSize() .. rst-class:: sphx-glr-script-out .. code-block:: none 3172 .. GENERATED FROM PYTHON SOURCE LINES 113-114 Save the number of calls to the model, its gradient and hessian done so far. .. GENERATED FROM PYTHON SOURCE LINES 116-120 .. code-block:: Python modelCallNumberAfter = model.getEvaluationCallsNumber() modelGradientCallNumberAfter = model.getGradientCallsNumber() modelHessianCallNumberAfter = model.getHessianCallsNumber() .. GENERATED FROM PYTHON SOURCE LINES 121-122 Display the number of iterations executed and the number of evaluations of the model. .. GENERATED FROM PYTHON SOURCE LINES 124-126 .. code-block:: Python modelCallNumberAfter - modelCallNumberBefore .. rst-class:: sphx-glr-script-out .. code-block:: none 3172 .. GENERATED FROM PYTHON SOURCE LINES 127-128 Get the mean point in event domain care : only for Monte Carlo and LHS sampling methods. .. GENERATED FROM PYTHON SOURCE LINES 130-132 .. code-block:: Python result.getMeanPointInEventDomain() .. raw:: html
class=Point name=Unnamed dimension=2 values=[245.843,80222]


.. GENERATED FROM PYTHON SOURCE LINES 133-134 Get the associated importance factors care : only for Monte Carlo and LHS sampling methods. .. GENERATED FROM PYTHON SOURCE LINES 136-138 .. 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 139-142 .. code-block:: Python graph = result.drawImportanceFactors() view = viewer.View(graph) .. image-sg:: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_probability_simulation_results_001.svg :alt: Importance Factors from Simulation - v0 :srcset: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_probability_simulation_results_001.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 143-150 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 152-163 .. 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 164-165 Draw the convergence graph and the confidence interval of level alpha. By default, alpha = 0.95. .. GENERATED FROM PYTHON SOURCE LINES 167-171 .. 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.svg :alt: ProbabilitySimulationAlgorithm convergence graph at level 0.9 :srcset: /auto_reliability_sensitivity/reliability/images/sphx_glr_plot_probability_simulation_results_002.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 172-173 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 175-179 .. 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 180-181 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 183-187 .. 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.25,0.046875] .. _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 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_probability_simulation_results.zip `