.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/stochastic_processes/spectral/spectral_nd_mv.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_stochastic_processes_spectral_spectral_nd_mv.py: N-dimensional & multiple-variables ================================================================= In this example, the Spectral Representation Method is used to generate stochastic processes from a prescribed Power Spectrum. This example illustrates how to use the SRM class for 'n' dimensional and one variable case and compare the statistics of the generated stochastic processes with the expected values. .. GENERATED FROM PYTHON SOURCE LINES 13-15 Import the necessary libraries. Here we import standard libraries such as numpy and matplotlib, but also need to import the :class:`.SpectralRepresentation` class from the :py:mod:`stochastic_processes` module of UQpy. .. GENERATED FROM PYTHON SOURCE LINES 18-25 .. code-block:: default from UQpy.stochastic_process import SpectralRepresentation import numpy as np import matplotlib.pyplot as plt from pylab import * plt.style.use('seaborn') .. GENERATED FROM PYTHON SOURCE LINES 26-27 The input parameters necessary for the generating of the stochastic processes are given below: .. GENERATED FROM PYTHON SOURCE LINES 30-49 .. code-block:: default n_sim = 1000 # Num of samples n = 2 # Num of dimensions m = 1 # Num of variables T = 10 nt = 200 dt = T/nt t = np.linspace(0, T-dt, nt) # Frequency W = np.array([1.0, 1.5]) nw = 100 dw = W / nw x_list = [np.linspace(0, W[i] - dw[i], nw) for i in range(n)] xy_list = np.array(np.meshgrid(*x_list, indexing='ij')) .. GENERATED FROM PYTHON SOURCE LINES 50-51 Defining the Power Spectral Density(S) .. GENERATED FROM PYTHON SOURCE LINES 54-57 .. code-block:: default S_nd_1v = 125 / 4 * np.linalg.norm(xy_list, axis=0) ** 2 * np.exp(-5 * np.linalg.norm(xy_list, axis=0)) .. GENERATED FROM PYTHON SOURCE LINES 58-59 Make sure that the input parameters are in order to prevent aliasing .. GENERATED FROM PYTHON SOURCE LINES 62-84 .. code-block:: default t_u = 2*np.pi/2/W if dt>t_u.all(): print('Error') SRM_object = SpectralRepresentation(n_sim, S_nd_1v, [dt, dt], dw, [nt, nt], [nw, nw], random_state=128) samples_nd_1v = SRM_object.samples t_list = [t for _ in range(n)] tt_list = np.array(np.meshgrid(*t_list, indexing='ij')) fig1 = plt.figure() plt.title('2d random field with a prescribed Power Spectrum') pcm = pcolor(tt_list[0], tt_list[1], samples_nd_1v[0, 0], cmap='RdBu_r', vmin=-6, vmax=6) plt.colorbar(pcm, extend='both', orientation='vertical') plt.xlabel('$X_{1}$') plt.ylabel('$X_{2}$') plt.show() print('The mean of the samples is ', np.mean(samples_nd_1v), 'whereas the expected mean is 0.000') print('The variance of the samples is ', np.var(samples_nd_1v), 'whereas the expected variance is ', np.sum(S_nd_1v)*np.prod(dw)*(2**n)) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_auto_examples_stochastic_processes_spectral_spectral_nd_mv.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/stochastic_processes/spectral/spectral_nd_mv.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: spectral_nd_mv.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: spectral_nd_mv.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_