.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_reliability_sensitivity/design_of_experiments/plot_low_discrepancy_sequence.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_design_of_experiments_plot_low_discrepancy_sequence.py: Generate low discrepancy sequences ================================== .. GENERATED FROM PYTHON SOURCE LINES 6-18 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. .. GENERATED FROM PYTHON SOURCE LINES 20-26 .. code-block:: Python 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 27-28 1. Sobol sequence .. GENERATED FROM PYTHON SOURCE LINES 28-37 .. code-block:: Python dimension = 2 size = 1024 sequence = ot.SobolSequence(dimension) sample = sequence.generate(size) graph = ot.Graph("Sobol", "", "", True, "") cloud = ot.Cloud(sample) graph.add(cloud) view = viewer.View(graph) .. image-sg:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_low_discrepancy_sequence_001.png :alt: Sobol :srcset: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_low_discrepancy_sequence_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 38-39 2. Halton sequence .. GENERATED FROM PYTHON SOURCE LINES 39-47 .. code-block:: Python dimension = 2 sequence = ot.HaltonSequence(dimension) sample = sequence.generate(size) graph = ot.Graph("Halton", "", "", True, "") cloud = ot.Cloud(sample) graph.add(cloud) view = viewer.View(graph) .. image-sg:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_low_discrepancy_sequence_002.png :alt: Halton :srcset: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_low_discrepancy_sequence_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 48-49 3. Halton sequence in high dimension: bad filling in upper dimensions .. GENERATED FROM PYTHON SOURCE LINES 49-63 .. code-block:: Python dimension = 20 sequence = ot.HaltonSequence(dimension) sample = sequence.generate(size).getMarginal([dimension - 2, dimension - 1]) graph = ot.Graph( "Halton (" + str(dimension - 2) + "," + str(dimension - 1) + ")", "dim " + str(dimension - 2), "dim " + str(dimension - 1), True, "", ) cloud = ot.Cloud(sample) graph.add(cloud) view = viewer.View(graph) .. image-sg:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_low_discrepancy_sequence_003.png :alt: Halton (18,19) :srcset: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_low_discrepancy_sequence_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 64-65 4. Scrambled Halton sequence in high dimension .. GENERATED FROM PYTHON SOURCE LINES 65-80 .. code-block:: Python dimension = 20 sequence = ot.HaltonSequence(dimension) sequence.setScrambling("RANDOM") sample = sequence.generate(size).getMarginal([dimension - 2, dimension - 1]) graph = ot.Graph( "Halton (" + str(dimension - 2) + "," + str(dimension - 1) + ")", "dim " + str(dimension - 2), "dim " + str(dimension - 1), True, "", ) cloud = ot.Cloud(sample) graph.add(cloud) view = viewer.View(graph) .. image-sg:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_low_discrepancy_sequence_004.png :alt: Halton (18,19) :srcset: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_low_discrepancy_sequence_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 81-82 5. Reverse Halton sequence .. GENERATED FROM PYTHON SOURCE LINES 82-94 .. code-block:: Python dimension = 2 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-sg:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_low_discrepancy_sequence_005.png :alt: Reverse Halton :srcset: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_low_discrepancy_sequence_005.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none discrepancy= 0.0035074981424325635 .. GENERATED FROM PYTHON SOURCE LINES 95-96 6. Haselgrove sequence .. GENERATED FROM PYTHON SOURCE LINES 96-104 .. code-block:: Python dimension = 2 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-sg:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_low_discrepancy_sequence_006.png :alt: Haselgrove :srcset: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_low_discrepancy_sequence_006.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 105-106 Compare with uniform random sequence .. GENERATED FROM PYTHON SOURCE LINES 106-117 .. code-block:: Python 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-sg:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_low_discrepancy_sequence_007.png :alt: Mersenne Twister :srcset: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_low_discrepancy_sequence_007.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none discrepancy= 0.03921823278089642 .. _sphx_glr_download_auto_reliability_sensitivity_design_of_experiments_plot_low_discrepancy_sequence.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_low_discrepancy_sequence.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_low_discrepancy_sequence.py `