.. 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_experiment_continuous_discrete.py: Create a design of experiments with discrete and continuous variables ===================================================================== In this example we present how to create a design of experiments when one (or several) of the marginals are discrete. .. code-block:: default from __future__ import print_function import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt ot.Log.Show(ot.Log.NONE) 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. .. code-block:: default sample = ot.Sample([[-2.], [-1.], [1.], [2.]]) sample .. raw:: html
v0
0-2
1-1
21
32


.. code-block:: default X0 = ot.UserDefined(sample) For the second marginal, we pick a Gaussian distribution. .. code-block:: default X1 = ot.Normal() Create the multivariate distribution from its marginals and an independent copula. .. code-block:: default distribution = ot.ComposedDistribution([X0,X1]) Create the design. .. code-block:: default size = 100 experiment = ot.MonteCarloExperiment(distribution, size) sample = experiment.generate() Plot the design. .. code-block:: default graph = ot.Graph("MonteCarloExperiment", "x0", "x1", True, "") cloud = ot.Cloud(sample, "blue", "fsquare", "") graph.add(cloud) view = viewer.View(graph) .. image:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_design_of_experiment_continuous_discrete_001.png :alt: MonteCarloExperiment :class: sphx-glr-single-img Any other type of design of experiments can be generated based on this distribution. The following example shows a LHS experiment. .. code-block:: default size = 100 alwaysShuffle = True randomShift = True experiment = ot.LHSExperiment(distribution, size, alwaysShuffle, randomShift) sample = experiment.generate() .. code-block:: default graph = ot.Graph("LHSExperiment", "x0", "x1", True, "") cloud = ot.Cloud(sample, "blue", "fsquare", "") graph.add(cloud) view = viewer.View(graph) plt.show() .. image:: /auto_reliability_sensitivity/design_of_experiments/images/sphx_glr_plot_design_of_experiment_continuous_discrete_002.png :alt: LHSExperiment :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.140 seconds) .. _sphx_glr_download_auto_reliability_sensitivity_design_of_experiments_plot_design_of_experiment_continuous_discrete.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_experiment_continuous_discrete.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_design_of_experiment_continuous_discrete.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_