.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/distributions/multivariate/plot_multivariate_copulas.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_distributions_multivariate_plot_multivariate_copulas.py: Multivariate from independent marginals and copula ================================================== .. GENERATED FROM PYTHON SOURCE LINES 9-12 - How to define α bivariate distribution from independent marginals and change its structure based on a copula supported by UQpy - How to plot the pdf of the distribution - How to modify the parameters of the distribution .. GENERATED FROM PYTHON SOURCE LINES 17-18 Import the necessary modules. .. GENERATED FROM PYTHON SOURCE LINES 21-25 .. code-block:: default import numpy as np import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 26-28 Example of a multivariate distribution from joint independent marginals ------------------------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 32-35 .. code-block:: default from UQpy.distributions import Normal, JointIndependent from UQpy.distributions import Gumbel, JointCopula .. GENERATED FROM PYTHON SOURCE LINES 36-40 Define a Copula --------------- The definition of bivariate distribution with a copula, is similar to defining a multivariate distribution from independent marginals. In both cases a list of marginals needs to be defined. In case of .. GENERATED FROM PYTHON SOURCE LINES 43-56 .. code-block:: default marginals = [Normal(loc=0., scale=1), Normal(loc=0., scale=1)] copula = Gumbel(theta=3.) # dist_1 is a multivariate normal with independent marginals dist_1 = JointIndependent(marginals) print('Does the distribution with independent marginals have an rvs method?') print(hasattr(dist_1, 'rvs')) # dist_2 exhibits dependence between the two dimensions, defined using a gumbel copula dist_2 = JointCopula(marginals=marginals, copula=copula) print('Does the distribution with copula have an rvs method?') print(hasattr(dist_2, 'rvs')) .. rst-class:: sphx-glr-script-out .. code-block:: none Does the distribution with independent marginals have an rvs method? True Does the distribution with copula have an rvs method? False .. GENERATED FROM PYTHON SOURCE LINES 57-60 Plot the pdf of the distribution before and after the copula ------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 63-85 .. code-block:: default fig, ax = plt.subplots(ncols=2, figsize=(10, 4)) x = np.arange(-3, 3, 0.1) y = np.arange(-3, 3, 0.1) X, Y = np.meshgrid(x, y) Z = dist_1.pdf(x=np.concatenate([X.reshape((-1, 1)), Y.reshape((-1, 1))], axis=1)) CS = ax[0].contour(X, Y, Z.reshape(X.shape)) ax[0].clabel(CS, inline=1, fontsize=10) ax[0].set_title('Contour plot of pdf - independent normals') x = np.arange(-3, 3, 0.1) y = np.arange(-3, 3, 0.1) X, Y = np.meshgrid(x, y) Z = dist_2.pdf(x=np.concatenate([X.reshape((-1, 1)), Y.reshape((-1, 1))], axis=1)) CS = ax[1].contour(X, Y, Z.reshape(X.shape)) ax[1].clabel(CS, inline=1, fontsize=10) ax[1].set_title('Contour plot of pdf - normals with Gumbel copula') plt.show() .. image-sg:: /auto_examples/distributions/multivariate/images/sphx_glr_plot_multivariate_copulas_001.png :alt: Contour plot of pdf - independent normals, Contour plot of pdf - normals with Gumbel copula :srcset: /auto_examples/distributions/multivariate/images/sphx_glr_plot_multivariate_copulas_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 86-90 Modify the parameters of the multivariate copula. ------------------------------------------------- Use the update_parameters method. .. GENERATED FROM PYTHON SOURCE LINES 93-95 .. code-block:: default print(dist_2.copula.parameters) dist_2.update_parameters(theta_c=2.) print(dist_2.copula.parameters) .. rst-class:: sphx-glr-script-out .. code-block:: none {'theta': 3.0} {'theta': 2.0} .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.105 seconds) .. _sphx_glr_download_auto_examples_distributions_multivariate_plot_multivariate_copulas.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/distributions/multivariate/plot_multivariate_copulas.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_multivariate_copulas.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_multivariate_copulas.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_