.. 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-22 .. code-block:: default 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 23-24 Create the joint distribution of the parameters. .. GENERATED FROM PYTHON SOURCE LINES 26-31 .. 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 32-33 Create the model. .. GENERATED FROM PYTHON SOURCE LINES 35-37 .. code-block:: default model = ot.SymbolicFunction(['R', 'F'], ['R-F/(pi_*100.0)']) .. GENERATED FROM PYTHON SOURCE LINES 38-42 .. code-block:: default 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:: default 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:: default 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:: default 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:: 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 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:: default 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:: default result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 89-90 Display the simulation event probability. .. GENERATED FROM PYTHON SOURCE LINES 92-94 .. code-block:: default result.getProbabilityEstimate() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 0.030068195908245512 .. 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:: default result.getStandardDeviation() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 0.0030067138916507713 .. GENERATED FROM PYTHON SOURCE LINES 99-100 Display the variance of the simulation probability estimator. .. GENERATED FROM PYTHON SOURCE LINES 102-104 .. code-block:: default result.getVarianceEstimate() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 9.040328426245726e-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:: default result.getOuterSampling() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 3226 .. 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:: default result.getOuterSampling() * result.getBlockSize() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 3226 .. 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:: default 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:: default modelCallNumberAfter - modelCallNumberBefore .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 3226 .. 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:: default result.getMeanPointInEventDomain() .. raw:: html

[248.016,80943.2]



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

[X0 : 0.709531, X1 : 0.290469]



.. GENERATED FROM PYTHON SOURCE LINES 139-142 .. 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 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-158 .. 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.011786101878903554 IC at 0.95 = [ 0.024175144968793735 ; 0.03596124684769729 ] .. GENERATED FROM PYTHON SOURCE LINES 159-160 Draw the convergence graph and the confidence interval of level alpha. By default, alpha = 0.95. .. GENERATED FROM PYTHON SOURCE LINES 162-166 .. 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 167-168 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 170-174 .. code-block:: default inputSampleStored = model.getInputHistory() outputSampleStored = model.getOutputHistory() inputSampleStored .. raw:: html
v0v1
0282.195677277.93
1267.89570529.54
2309.384975188.02
...
3223300.966880330.26
3224303.878878105.85
3225249.322786237.41


.. GENERATED FROM PYTHON SOURCE LINES 175-176 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 178-182 .. 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.143 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 `_