.. 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 Click :ref:`here ` 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:: default 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) .. GENERATED FROM PYTHON SOURCE LINES 24-25 Create the joint distribution of the parameters. .. GENERATED FROM PYTHON SOURCE LINES 27-32 .. code-block:: default 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:: default model = ot.SymbolicFunction(['R', 'F'], ['R-F/(pi_*100.0)']) .. GENERATED FROM PYTHON SOURCE LINES 39-43 .. code-block:: default 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:: default 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:: default 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:: default 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:: default 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:: default 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:: default result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 90-91 Display the simulation event probability. .. GENERATED FROM PYTHON SOURCE LINES 93-95 .. code-block:: default result.getProbabilityEstimate() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 0.030340944635595897 .. 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:: default result.getStandardDeviation() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 0.0030335611908031547 .. GENERATED FROM PYTHON SOURCE LINES 100-101 Display the variance of the simulation probability estimator. .. GENERATED FROM PYTHON SOURCE LINES 103-105 .. code-block:: default result.getVarianceEstimate() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 9.202493498347055e-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:: default result.getOuterSampling() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 3197 .. 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:: default result.getOuterSampling() * result.getBlockSize() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 3197 .. 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:: default 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:: default modelCallNumberAfter - modelCallNumberBefore .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 3197 .. 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:: default result.getMeanPointInEventDomain() .. raw:: html

[247.749,80783.2]



.. 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:: default result.getImportanceFactors() .. raw:: html

[X0 : 0.722979, X1 : 0.277021]



.. GENERATED FROM PYTHON SOURCE LINES 140-143 .. code-block:: default 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-159 .. code-block:: default 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 Out: .. code-block:: none 0.95 Confidence Interval length = 0.011891341357745243 IC at 0.95 = [ 0.024395273956723276 ; 0.036286615314468515 ] .. GENERATED FROM PYTHON SOURCE LINES 160-161 Draw the convergence graph and the confidence interval of level alpha. By default, alpha = 0.95. .. GENERATED FROM PYTHON SOURCE LINES 163-167 .. code-block:: default 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 168-169 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 171-175 .. code-block:: default inputSampleStored = model.getInputHistory() outputSampleStored = model.getOutputHistory() inputSampleStored .. raw:: html
v0v1
0330.601481470.31
1319.757270140.39
2293.025970046.44
...
3194284.850575912.25
3195342.583481135.8
3196245.357377941.02


.. GENERATED FROM PYTHON SOURCE LINES 176-177 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 179-183 .. code-block:: default 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 Out: .. code-block:: none [0,-1] [0,-1] .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.227 seconds) .. _sphx_glr_download_auto_reliability_sensitivity_reliability_plot_probability_simulation_results.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. 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-jupyter :download:`Download Jupyter notebook: plot_probability_simulation_results.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_