.. 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_design_of_experiments.py:
Various design of experiments in OpenTURNS
==========================================
The goal of this example is to present several design of experiments available in OpenTURNS.
Distribution
------------
.. code-block:: default
import openturns as ot
import openturns.viewer as otv
import pylab as pl
import openturns.viewer as viewer
from matplotlib import pylab as plt
ot.Log.Show(ot.Log.NONE)
Monte-Carlo sampling in 2D
--------------------------
.. code-block:: default
dim = 2
X = [ot.Uniform()] * dim
distribution = ot.ComposedDistribution(X)
bounds = distribution.getRange()
.. code-block:: default
sampleSize = 10
sample = distribution.getSample(sampleSize)
.. code-block:: default
fig = otv.PlotDesign(sample, bounds);
.. image:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_design_of_experiments_001.png
:alt: plot design of experiments
:class: sphx-glr-single-img
We see that there a empty zones in the input space.
Monte-Carlo sampling in 3D
--------------------------
.. code-block:: default
dim = 3
X = [ot.Uniform()] * dim
distribution = ot.ComposedDistribution(X)
bounds = distribution.getRange()
.. code-block:: default
sampleSize = 10
sample = distribution.getSample(sampleSize)
.. code-block:: default
fig = otv.PlotDesign(sample, bounds)
fig.set_size_inches(10, 10)
.. image:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_design_of_experiments_002.png
:alt: plot design of experiments
:class: sphx-glr-single-img
Latin Hypercube Sampling
------------------------
.. code-block:: default
distribution = ot.ComposedDistribution([ot.Uniform()]*3)
samplesize = 5
experiment = ot.LHSExperiment(distribution, samplesize, False, False)
sample = experiment.generate()
In order to see the LHS property, we need to set the bounds.
.. code-block:: default
bounds = distribution.getRange()
.. code-block:: default
fig = otv.PlotDesign(sample, bounds)
fig.set_size_inches(10, 10)
.. image:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_design_of_experiments_003.png
:alt: plot design of experiments
:class: sphx-glr-single-img
We see that each column or row exactly contains one single point. This shows that a LHS design of experimens has good 1D projection properties, and, hence, is a good candidate for a space filling design.
Optimized LHS
-------------
.. code-block:: default
distribution = ot.ComposedDistribution([ot.Uniform()]*3)
samplesize = 10
.. code-block:: default
bounds = distribution.getRange()
.. code-block:: default
lhs = ot.LHSExperiment(distribution, samplesize)
lhs.setAlwaysShuffle(True) # randomized
space_filling = ot.SpaceFillingC2()
temperatureProfile = ot.GeometricProfile(10.0, 0.95, 1000)
algo = ot.SimulatedAnnealingLHS(lhs, temperatureProfile, space_filling)
# optimal design
sample = algo.generate()
.. code-block:: default
fig = otv.PlotDesign(sample, bounds)
fig.set_size_inches(10, 10)
.. image:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_design_of_experiments_004.png
:alt: plot design of experiments
:class: sphx-glr-single-img
We see that this LHS is optimized in the sense that it fills the space more evenly than a non-optimized does in general.
Sobol' low discrepancy sequence
-------------------------------
.. code-block:: default
dim = 2
distribution = ot.ComposedDistribution([ot.Uniform()]*dim)
bounds = distribution.getRange()
.. code-block:: default
sequence = ot.SobolSequence(dim)
.. code-block:: default
samplesize = 2**5 # Sobol' sequences are in base 2
experiment = ot.LowDiscrepancyExperiment(sequence, distribution, samplesize, False)
sample = experiment.generate()
.. code-block:: default
samplesize
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
32
.. code-block:: default
subdivisions = [2**2, 2**1]
fig = otv.PlotDesign(sample, bounds, subdivisions);
fig.set_size_inches(6, 6)
.. image:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_design_of_experiments_005.png
:alt: plot design of experiments
:class: sphx-glr-single-img
We have elementary intervals in 2 dimensions, each having a volume equal to 1/8. Since there are 32 points, the Sobol' sequence is so that each elementary interval contains exactly 32/8 = 4 points. Notice that each elementary interval is closed on the left (or bottom) and open on the right (or top).
Halton low discrepancy sequence
-------------------------------
.. code-block:: default
dim = 2
distribution = ot.ComposedDistribution([ot.Uniform()]*dim)
bounds = distribution.getRange()
.. code-block:: default
sequence = ot.HaltonSequence(dim)
.. code-block:: default
samplesize = 2**2 * 3**2 # Halton sequence uses prime numbers 2 and 3 in two dimensions.
experiment = ot.LowDiscrepancyExperiment(sequence, distribution, samplesize, False)
sample = experiment.generate()
.. code-block:: default
samplesize
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
36
.. code-block:: default
subdivisions = [2**2, 3]
fig = otv.PlotDesign(sample, bounds, subdivisions);
fig.set_size_inches(6, 6)
.. image:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_design_of_experiments_006.png
:alt: plot design of experiments
:class: sphx-glr-single-img
We have elementary intervals in 2 dimensions, each having a volume equal to 1/12. Since there are 36 points, the Halton sequence is so that each elementary interval contains exactly 36/12 = 3 points. Notice that each elementary interval is closed on the left (or bottom) and open on the right (or top).
.. rst-class:: sphx-glr-timing
**Total running time of the script:** ( 0 minutes 1.288 seconds)
.. _sphx_glr_download_auto_reliability_sensitivity_design_of_experiments_plot_design_of_experiments.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_design_of_experiments.py `
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: plot_design_of_experiments.ipynb `
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery `_