.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/sampling/simplex/plot_simplex.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 or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_sampling_simplex_plot_simplex.py: Simplex Sampling ================================== This example shows the use of the Simplex sampling class. In particular: .. GENERATED FROM PYTHON SOURCE LINES 10-13 - How to define the Simplex sampling method supported by UQpy - How to draw samples using Simplex sampling - How to plot simplices as well as their corresponding samples. .. GENERATED FROM PYTHON SOURCE LINES 18-19 Initially we have to import the necessary modules. .. GENERATED FROM PYTHON SOURCE LINES 22-27 .. code-block:: default from UQpy.sampling import SimplexSampling import numpy as np import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 28-31 Define Simplices ---------------------------------------------- Create an array of 3 points in 2-D, which will be the vertex coordinates of the simplex. .. GENERATED FROM PYTHON SOURCE LINES 34-37 .. code-block:: default vertex = np.array([[0, 0], [0.5, 1], [1, 0]]) .. GENERATED FROM PYTHON SOURCE LINES 38-43 Add new samples to existing sampling object ---------------------------------------------- Use Simplex class to generate uniformly distributed samples. This class needs two input parameters, i.e. :code:`nodes` and :code:`nsamples`. Nodes are the vertex coordinates of simplex and nsamples is the number of new samples to be generated. In this example, we are generating ten new samples inside our simplex. .. GENERATED FROM PYTHON SOURCE LINES 46-49 .. code-block:: default x = SimplexSampling(nodes=vertex, nsamples=10, random_state=1) .. GENERATED FROM PYTHON SOURCE LINES 50-53 Plot the samples of the simplex ------------------------------------ A schematic illustration of the 2-D simplex and new samples generated using Simplex class are presented below. .. GENERATED FROM PYTHON SOURCE LINES 56-61 .. code-block:: default plt.plot(np.array([0, 0.5, 1, 0]), np.array([0, 1, 0, 0]), color='blue') plt.scatter(x.samples[:, 0], x.samples[:, 1], color='red') plt.show() .. image-sg:: /auto_examples/sampling/simplex/images/sphx_glr_plot_simplex_001.png :alt: plot simplex :srcset: /auto_examples/sampling/simplex/images/sphx_glr_plot_simplex_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 62-63 User can also define a Simplex object using vertices and generate samples using :py:meth:`run` method. .. GENERATED FROM PYTHON SOURCE LINES 66-69 .. code-block:: default y = SimplexSampling(nodes=vertex) y.run(nsamples=5) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.043 seconds) .. _sphx_glr_download_auto_examples_sampling_simplex_plot_simplex.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/SURGroup/UQpy/master?urlpath=lab/tree/notebooks/auto_examples/sampling/simplex/plot_simplex.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_simplex.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_simplex.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_