<jupyter_start><jupyter_text>Nataf - Example 1Author: <NAME><jupyter_code>from UQpy.SampleMethods import MCS
from UQpy.Transformations import Nataf
from UQpy.Distributions import Distribution
import numpy as np
import matplotlib.pyplot as plt
from UQpy.Distributions import Normal, Uniform
dist1 = Normal(loc=0.0, scale=1.0)
dist2 = Normal(loc=0.0, scale=1.0)
Rx = np.array([[1.0, 0.8], [0.8, 1.0]])
nataf_obj = Nataf(dist_object=[dist1,dist2], corr_x=Rx)
print('Cz', nataf_obj.corr_z)
corr_x = Nataf.distortion_z2x(dist_object=[dist1,dist2], corr_z=nataf_obj.corr_z)
print('Cx', corr_x)
from UQpy.Distributions import Gamma, Lognormal
dist1 = Gamma(4.0, loc=0.0, scale=1.0)
dist2 = Lognormal(s=2., loc=0., scale=np.exp(1))
Rx = np.array([[1.0, 0.9], [0.9, 1.0]])
nataf_obj = Nataf(dist_object=[dist1,dist2], corr_x=Rx)
samples_x = nataf_obj.rvs(1000)
plt.figure()
plt.title('non-Gaussian random variables')
plt.scatter(samples_x[:, 0], samples_x[:, 1])
plt.grid(True)
plt.xlabel('$X_1$')
plt.ylabel('$X_2$')
plt.show()
nataf_obj.run(samples_x=samples_x, jacobian=True)
plt.figure()
plt.title('Correlated standard normal samples')
plt.scatter(nataf_obj.samples_z[:, 0], nataf_obj.samples_z[:, 1])
plt.grid(True)
plt.xlabel('$Z_1$')
plt.ylabel('$Z_2$')
plt.show()
from UQpy.Transformations import Decorrelate

samples_u = Decorrelate(nataf_obj.samples_z, nataf_obj.corr_z).samples_u

plt.figure()
plt.title('Uncorrelated standard normal samples')
plt.scatter(samples_u[:, 0], samples_u[:, 1])
plt.grid(True)
plt.xlabel('$U_1$')
plt.ylabel('$U_2$')
plt.show()
from UQpy.Transformations import Correlate

samples_z = Correlate(samples_u, nataf_obj.corr_z).samples_z

plt.figure()
plt.title('Correlated standard normal samples')
plt.scatter(samples_z[:, 0], samples_z[:, 1])
plt.grid(True)
plt.xlabel('$U_1$')
plt.ylabel('$U_2$')
plt.show()
from UQpy.Distributions import Gamma, Lognormal
dist1 = Gamma(4.0, loc=0.0, scale=1.0)
dist2 = Lognormal(s=2., loc=0., scale=np.exp(1))
N = 20
w3 = np.zeros(N)
rho = np.linspace(-0.999, 0.999, N)
for i in range(10):
    Rho1 = np.array([[1.0, rho[i]], [rho[i], 1.0]])
    ww = Nataf([dist1,dist2], corr_x=Rho1).corr_z
    w3[i] = ww[0, 1]

plt.plot(w3, rho)
plt.plot(rho, rho)
plt.show()
# Calculate correlation distortion for the transformation of two random variables from normal to lognormal.
# Compute the correlation distortion at various values of Gaussian correlation.

N = 20
w4 = np.zeros(N)
rho = np.linspace(-0.999, 0.999, N)
for i in range(N):
    Rho1 = np.array([[1.0, rho[i]], [rho[i], 1.0]])
    ww = Nataf(dist_object=[dist1,dist2], corr_z=Rho1)
    w4[i] = ww[0, 1]

plt.plot(rho, w4)
plt.plot(rho, rho)
plt.show()
from UQpy.Distributions import Gamma, Lognormal
dist1 = Gamma(4.0, loc=0.0, scale=1.0)
dist2 = Lognormal(s=2., loc=0., scale=np.exp(1))

nataf_obj1 = Nataf(dist_object=[dist1,dist2])

samples_x = nataf_obj1.rvs(1000)
plt.figure()
plt.title('Random samples')
plt.scatter(samples_x[:, 0], samples_x[:, 1])
plt.grid(True)
plt.xlabel('$X_1$')
plt.ylabel('$X_2$')
plt.show()
nataf_obj1.run(samples_x=samples_x, jacobian=True)

plt.figure()
plt.title('Random samples')
plt.scatter(nataf_obj1.samples_z[:, 0], nataf_obj1.samples_z[:, 1])
plt.grid(True)
plt.xlabel('$X_1$')
plt.ylabel('$X_2$')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1820388349514563, 'fraction_numerical': 0.046723300970873786, 'mean_word_length': 6.059957173447537, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '295369', 'license': 'MIT', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1457, 'n_words': 273, 'path': 'example/Transformations/Nataf-Example1.ipynb', 'repo_name': 'AniketSanjayDesai/UQpy', 'size': '3307'}