.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/dimension_reduction/diffusion_maps/diffusion_maps_circle.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_dimension_reduction_diffusion_maps_diffusion_maps_circle.py: Circle =================================================================== This example shows how to use the UQpy DiffusionMaps class to reveal the embedded structure of noisy data. .. GENERATED FROM PYTHON SOURCE LINES 10-12 Import the necessary libraries. Here we import standard libraries such as numpy and matplotlib, but also need to import the DiffusionMaps class from UQpy implemented in the DimensionReduction module. .. GENERATED FROM PYTHON SOURCE LINES 15-22 .. code-block:: default import numpy as np from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt from UQpy.utilities.kernels.GaussianKernel import GaussianKernel from UQpy.dimension_reduction.diffusion_maps.DiffusionMaps import DiffusionMaps .. GENERATED FROM PYTHON SOURCE LINES 23-24 Sample points randomly following a parametric curve and plot the 3D graphic. .. GENERATED FROM PYTHON SOURCE LINES 27-54 .. code-block:: default a = 6 b = 1 k = 10 u = np.linspace(0, 2 * np.pi, 1000) v = k * u x0 = (a + b * np.cos(0.8 * v)) * (np.cos(u)) y0 = (a + b * np.cos(0.8 * v)) * (np.sin(u)) z0 = b * np.sin(0.8 * v) rox = 0.2 roy = 0.2 roz = 0.2 x = x0 + rox * np.random.normal(0, 1, len(x0)) y = y0 + roy * np.random.normal(0, 1, len(y0)) z = z0 + roz * np.random.normal(0, 1, len(z0)) X = np.array([x, y, z]).transpose() fig = plt.figure() ax = fig.gca(projection='3d') ax.scatter(x, y, z, c='b', cmap=plt.cm.Spectral, s=8) ax.plot(x0, y0, z0, 'r', label='parametric curve') plt.show() .. GENERATED FROM PYTHON SOURCE LINES 55-57 Instantiate the class `DiffusionMaps` using `alpha=1`; `n_eigenvectors=3`, because the first eigenvector is non-informative. Moreover, a Gaussian is used in the kernel construction. .. GENERATED FROM PYTHON SOURCE LINES 60-64 .. code-block:: default dmaps = DiffusionMaps(data=X, alpha=1, n_eigenvectors=5, kernel=GaussianKernel(epsilon=0.3)) .. GENERATED FROM PYTHON SOURCE LINES 65-66 Plot the second and third diffusion coordinates to reveal the embedded structure of the data. .. GENERATED FROM PYTHON SOURCE LINES 69-75 .. code-block:: default color = dmaps.eigenvectors[:, 1] plt.scatter(dmaps.diffusion_coordinates[:, 1], dmaps.diffusion_coordinates[:, 2], c=color, cmap=plt.cm.Spectral, s=8) plt.axis('equal') plt.show() .. GENERATED FROM PYTHON SOURCE LINES 76-77 Use the colormap to observe how the embedded structure is distributed in the original set. .. GENERATED FROM PYTHON SOURCE LINES 80-85 .. code-block:: default fig = plt.figure() ax = fig.gca(projection='3d') ax.scatter(x, y, z, c=color, cmap=plt.cm.Spectral, s=8) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_auto_examples_dimension_reduction_diffusion_maps_diffusion_maps_circle.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/dimension_reduction/diffusion_maps/diffusion_maps_circle.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: diffusion_maps_circle.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: diffusion_maps_circle.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_