.. 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 7-14 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 16-20 .. code-block:: Python import openturns as ot ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 21-22 Create the joint distribution of the parameters. .. GENERATED FROM PYTHON SOURCE LINES 24-29 .. 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 30-31 Create the model. .. GENERATED FROM PYTHON SOURCE LINES 33-35 .. code-block:: Python model = ot.SymbolicFunction(["R", "F"], ["R-F/(pi_*100.0)"]) .. GENERATED FROM PYTHON SOURCE LINES 36-37 Create the event whose probability we want to estimate. .. GENERATED FROM PYTHON SOURCE LINES 39-43 .. 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 44-45 Create a Monte Carlo algorithm. .. GENERATED FROM PYTHON SOURCE LINES 47-50 .. code-block:: Python experiment = ot.MonteCarloExperiment() algo = ot.ProbabilitySimulationAlgorithm(event, experiment) .. GENERATED FROM PYTHON SOURCE LINES 51-52 Criteria 1: Define the Maximum Coefficient of variation of the probability estimator. .. GENERATED FROM PYTHON SOURCE LINES 54-56 .. code-block:: Python algo.setMaximumCoefficientOfVariation(0.05) .. GENERATED FROM PYTHON SOURCE LINES 57-58 Criteria 2: Define the number of iterations of the simulation. .. GENERATED FROM PYTHON SOURCE LINES 60-62 .. code-block:: Python algo.setMaximumOuterSampling(int(1e4)) .. GENERATED FROM PYTHON SOURCE LINES 63-64 The block size parameter represents the number of samples evaluated per iteration, useful for parallelization. .. GENERATED FROM PYTHON SOURCE LINES 66-68 .. code-block:: Python algo.setBlockSize(2) .. GENERATED FROM PYTHON SOURCE LINES 69-70 HistoryStrategy to store the values of the probability used to draw the convergence graph. .. GENERATED FROM PYTHON SOURCE LINES 72-73 Null strategy .. GENERATED FROM PYTHON SOURCE LINES 73-83 .. 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 84-85 Use a callback to display the progress every 10%. .. GENERATED FROM PYTHON SOURCE LINES 88-99 .. 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 100-101 Use a callback to stop the simulation. .. GENERATED FROM PYTHON SOURCE LINES 104-111 .. code-block:: Python def stop(): # here we never stop, but we could return False algo.setStopCallback(stop) .. GENERATED FROM PYTHON SOURCE LINES 112-114 .. 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 115-116 Retrieve results. .. GENERATED FROM PYTHON SOURCE LINES 118-121 .. code-block:: Python result = algo.getResult() probability = result.getProbabilityEstimate() print("Pf=", probability) .. rst-class:: sphx-glr-script-out .. code-block:: none Pf= 0.029667519181585684 .. _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 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_probability_simulation_parametrization.zip `