.. 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_design_of_experiment_continuous_discrete.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_design_of_experiment_continuous_discrete.py: Create a design of experiments with discrete and continuous variables ===================================================================== .. GENERATED FROM PYTHON SOURCE LINES 6-7 In this example we present how to create a design of experiments when one (or several) of the marginals are discrete. .. GENERATED FROM PYTHON SOURCE LINES 9-15 .. 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 16-19 To create the first marginal of the distribution, we select a univariate discrete distribution. Some of them, like the `Bernoulli` or `Geometric` distributions, are implemented in the library as classes. In this example however, we pick the `UserDefined` distribution that assigns equal weights to the values -2, -1, 1 and 2. .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. code-block:: Python sample = ot.Sample([[-2.0], [-1.0], [1.0], [2.0]]) sample .. raw:: html
v0
0-2
1-1
21
32


.. GENERATED FROM PYTHON SOURCE LINES 25-27 .. code-block:: Python X0 = ot.UserDefined(sample) .. GENERATED FROM PYTHON SOURCE LINES 28-29 For the second marginal, we pick a Gaussian distribution. .. GENERATED FROM PYTHON SOURCE LINES 31-33 .. code-block:: Python X1 = ot.Normal() .. GENERATED FROM PYTHON SOURCE LINES 34-35 Create the multivariate distribution from its marginals and an independent copula. .. GENERATED FROM PYTHON SOURCE LINES 37-39 .. code-block:: Python distribution = ot.ComposedDistribution([X0, X1]) .. GENERATED FROM PYTHON SOURCE LINES 40-41 Create the design. .. GENERATED FROM PYTHON SOURCE LINES 43-47 .. code-block:: Python size = 100 experiment = ot.MonteCarloExperiment(distribution, size) sample = experiment.generate() .. GENERATED FROM PYTHON SOURCE LINES 48-49 Plot the design. .. GENERATED FROM PYTHON SOURCE LINES 51-56 .. code-block:: Python graph = ot.Graph("MonteCarloExperiment", "x0", "x1", True, "") cloud = ot.Cloud(sample, "blue", "fsquare", "") graph.add(cloud) view = viewer.View(graph) .. image-sg:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_design_of_experiment_continuous_discrete_001.png :alt: MonteCarloExperiment :srcset: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_design_of_experiment_continuous_discrete_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 57-58 Any other type of design of experiments can be generated based on this distribution. The following example shows a LHS experiment. .. GENERATED FROM PYTHON SOURCE LINES 60-66 .. code-block:: Python size = 100 alwaysShuffle = True randomShift = True experiment = ot.LHSExperiment(distribution, size, alwaysShuffle, randomShift) sample = experiment.generate() .. GENERATED FROM PYTHON SOURCE LINES 67-72 .. code-block:: Python graph = ot.Graph("LHSExperiment", "x0", "x1", True, "") cloud = ot.Cloud(sample, "blue", "fsquare", "") graph.add(cloud) view = viewer.View(graph) plt.show() .. image-sg:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_design_of_experiment_continuous_discrete_002.png :alt: LHSExperiment :srcset: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_design_of_experiment_continuous_discrete_002.png :class: sphx-glr-single-img .. _sphx_glr_download_auto_reliability_sensitivity_design_of_experiments_plot_design_of_experiment_continuous_discrete.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_design_of_experiment_continuous_discrete.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_design_of_experiment_continuous_discrete.py `