.. 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_design_of_experiments_plot_low_discrepancy_sequence.py: Generate low discrepancy sequences ================================== In this examples we are going to expose the available low discrepancy sequences in order to approximate some integrals. The following low-discrepancy sequences are available: - Sobol - Faure - Halton - reverse Halton - Haselgrove To illustrate these sequences we generate their first 1024 points and compare with the sequence obtained from the pseudo random generator (Merse Twister) as the latter has a higher discrepancy. .. code-block:: default from __future__ import print_function import openturns as ot import math as m import openturns.viewer as viewer from matplotlib import pylab as plt ot.Log.Show(ot.Log.NONE) 1. Sobol sequence .. code-block:: default dimension = 2 size = 1024 sequence = ot.SobolSequence(2) sample = sequence.generate(size) graph = ot.Graph("Sobol", "", "", True, "") cloud = ot.Cloud(sample) graph.add(cloud) view = viewer.View(graph) .. image:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_low_discrepancy_sequence_001.png :alt: Sobol :class: sphx-glr-single-img 2. Halton sequence .. code-block:: default dimension = 2 sequence = ot.HaltonSequence(2) sample = sequence.generate(size) graph = ot.Graph("Halton", "", "", True, "") cloud = ot.Cloud(sample) graph.add(cloud) view = viewer.View(graph) .. image:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_low_discrepancy_sequence_002.png :alt: Halton :class: sphx-glr-single-img 3. Reverse Halton sequence .. code-block:: default sequence = ot.ReverseHaltonSequence(dimension) sample = sequence.generate(size) print('discrepancy=', ot.LowDiscrepancySequenceImplementation.ComputeStarDiscrepancy(sample)) graph = ot.Graph("Reverse Halton", "", "", True, "") cloud = ot.Cloud(sample) graph.add(cloud) view = viewer.View(graph) .. image:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_low_discrepancy_sequence_003.png :alt: Reverse Halton :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none discrepancy= 0.0035074981424325635 4. Haselgrove sequence .. code-block:: default sequence = ot.HaselgroveSequence(dimension) sample = sequence.generate(size) graph = ot.Graph("Haselgrove", "", "", True, "") cloud = ot.Cloud(sample) graph.add(cloud) view = viewer.View(graph) .. image:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_low_discrepancy_sequence_004.png :alt: Haselgrove :class: sphx-glr-single-img Compare with uniform random sequence .. code-block:: default distribution = ot.ComposedDistribution([ot.Uniform(0.0, 1.0)]*2) sample = distribution.getSample(size) print('discrepancy=', ot.LowDiscrepancySequenceImplementation.ComputeStarDiscrepancy(sample)) graph = ot.Graph("Mersenne Twister", "", "", True, "") cloud = ot.Cloud(sample) graph.add(cloud) view = viewer.View(graph) plt.show() .. image:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_low_discrepancy_sequence_005.png :alt: Mersenne Twister :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none discrepancy= 0.030727095301450208 .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.460 seconds) .. _sphx_glr_download_auto_reliability_sensitivity_design_of_experiments_plot_low_discrepancy_sequence.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_low_discrepancy_sequence.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_low_discrepancy_sequence.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_