.. 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_parametrization.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_parametrization.py: Specify a simulation algorithm ============================== .. GENERATED FROM PYTHON SOURCE LINES 6-13 In this example we are going to parameterize a simulation algorithm: - parameters linked to the number of points generated - the precision of the probability estimator - the sample storage strategy - using callbacks to monitor progress and stopping criteria. .. GENERATED FROM PYTHON SOURCE LINES 15-19 .. code-block:: Python import openturns as ot ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 20-21 Create the joint distribution of the parameters. .. GENERATED FROM PYTHON SOURCE LINES 23-28 .. 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 29-30 Create the model. .. GENERATED FROM PYTHON SOURCE LINES 32-34 .. code-block:: Python model = ot.SymbolicFunction(["R", "F"], ["R-F/(pi_*100.0)"]) .. GENERATED FROM PYTHON SOURCE LINES 35-36 Create the event whose probability we want to estimate. .. GENERATED FROM PYTHON SOURCE LINES 38-42 .. 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 43-44 Create a Monte Carlo algorithm. .. GENERATED FROM PYTHON SOURCE LINES 46-49 .. code-block:: Python experiment = ot.MonteCarloExperiment() algo = ot.ProbabilitySimulationAlgorithm(event, experiment) .. GENERATED FROM PYTHON SOURCE LINES 50-51 Criteria 1: Define the Maximum Coefficient of variation of the probability estimator. .. GENERATED FROM PYTHON SOURCE LINES 53-55 .. code-block:: Python algo.setMaximumCoefficientOfVariation(0.05) .. GENERATED FROM PYTHON SOURCE LINES 56-57 Criteria 2: Define the number of iterations of the simulation. .. GENERATED FROM PYTHON SOURCE LINES 59-61 .. code-block:: Python algo.setMaximumOuterSampling(int(1e4)) .. GENERATED FROM PYTHON SOURCE LINES 62-63 The block size parameter represents the number of samples evaluated per iteration, useful for parallelization. .. GENERATED FROM PYTHON SOURCE LINES 65-67 .. code-block:: Python algo.setBlockSize(2) .. GENERATED FROM PYTHON SOURCE LINES 68-69 HistoryStrategy to store the values of the probability used to draw the convergence graph. .. GENERATED FROM PYTHON SOURCE LINES 71-72 Null strategy .. GENERATED FROM PYTHON SOURCE LINES 72-82 .. code-block:: Python algo.setConvergenceStrategy(ot.Null()) # Full strategy algo.setConvergenceStrategy(ot.Full()) # Compact strategy: N points N = 1000 algo.setConvergenceStrategy(ot.Compact(N)) .. GENERATED FROM PYTHON SOURCE LINES 83-84 Use a callback to display the progress every 10%. .. GENERATED FROM PYTHON SOURCE LINES 87-98 .. code-block:: Python def progress(p): if p >= progress.t: progress.t += 10.0 print("progress=", p, "%") return False progress.t = 10.0 algo.setProgressCallback(progress) .. GENERATED FROM PYTHON SOURCE LINES 99-100 Use a callback to stop the simulation. .. GENERATED FROM PYTHON SOURCE LINES 103-110 .. code-block:: Python def stop(): # here we never stop, but we could return False algo.setStopCallback(stop) .. GENERATED FROM PYTHON SOURCE LINES 111-113 .. code-block:: Python algo.run() .. rst-class:: sphx-glr-script-out .. code-block:: none progress= 10.0 % progress= 20.0 % progress= 30.0 % progress= 40.0 % progress= 50.0 % progress= 60.0 % progress= 70.0 % progress= 80.0 % progress= 90.0 % .. GENERATED FROM PYTHON SOURCE LINES 114-115 Retrieve results. .. GENERATED FROM PYTHON SOURCE LINES 117-120 .. code-block:: Python result = algo.getResult() probability = result.getProbabilityEstimate() print("Pf=", probability) .. rst-class:: sphx-glr-script-out .. code-block:: none Pf= 0.029626994613273696 .. _sphx_glr_download_auto_reliability_sensitivity_reliability_plot_probability_simulation_parametrization.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_parametrization.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_probability_simulation_parametrization.py `