def test_samples_z2(): dist1 = Uniform(loc=0.0, scale=5.0) dist2 = Uniform(loc=0.0, scale=3.0) ntf_obj = Nataf(distributions=[dist1, dist2]) samples_z = np.array([[0.3, 1.2], [0.2, 2.4]]).T ntf_obj.run(samples_z=samples_z, jacobian=True) g = [] for i in range(2): if i == 0: g.append((ntf_obj.samples_x[i] == np.array( [3.089557110944763, 1.737779128317309])).all()) elif i == 1: g.append((ntf_obj.samples_x[i] == np.array( [4.424651648891459, 2.9754073922262116])).all()) assert np.all(g)
def test_samples_x1(): dist1 = Uniform(loc=0.0, scale=5.0) dist2 = Uniform(loc=0.0, scale=3.0) ntf_obj = Nataf(distributions=[dist1, dist2]) samples_x = np.array([[0.3, 1.2, 3.5], [0.2, 2.4, 0.9]]).T ntf_obj.run(samples_x=samples_x, jacobian=True) g = [] for i in range(3): if i == 0: g.append((ntf_obj.samples_z[i] == np.array( [-1.5547735945968535, -1.501085946044025])).all()) elif i == 1: g.append((ntf_obj.samples_z[i] == np.array( [-0.7063025628400874, 0.841621233572914])).all()) else: g.append((ntf_obj.samples_z[i] == np.array( [0.5244005127080407, -0.5244005127080409])).all()) assert np.all(g)
def test_samples_z_jzx2(): dist1 = Uniform(loc=0.0, scale=5.0) dist2 = Uniform(loc=0.0, scale=3.0) ntf_obj = Nataf(distributions=[dist1, dist2]) samples_z = np.array([[0.3, 1.2], [0.2, 2.4]]).T ntf_obj.run(samples_z=samples_z, jacobian=True) g = [] for i in range(2): if i == 0: g.append( (ntf_obj.jzx[i] == np.array([[0.524400601939789, 0.0], [0.0, 0.8524218415758338]])).all()) else: g.append( (ntf_obj.jzx[i] == np.array([[1.0299400748281828, 0.0], [0.0, 14.884586948005541]])).all()) assert np.all(g)
def test_samples_x_jxz2(): dist1 = Uniform(loc=0.0, scale=5.0) dist2 = Uniform(loc=0.0, scale=3.0) ntf_obj = Nataf(distributions=[dist1, dist2]) samples_x = np.array([[0.3, 1.2, 3.5], [0.2, 2.4, 0.9]]).T ntf_obj.run(samples_x=samples_x, jacobian=True) g = [] for i in range(3): if i == 0: g.append((ntf_obj.jxz[i] == np.array([[1.6789373877365803, 0.0], [0.0, 2.577850090371836]])).all()) elif i == 1: g.append( (ntf_obj.jxz[i] == np.array([[0.6433491348614259, 0.0], [0.0, 1.1906381155257868]])).all()) else: g.append((ntf_obj.jxz[i] == np.array([[0.5752207318528584, 0.0], [0.0, 0.958701219754764]])).all()) assert np.all(g)
plt.scatter(samples_x[:, 0], samples_x[:, 1]) plt.grid(True) plt.xlabel('$X_1$') plt.ylabel('$X_2$') plt.show() # %% md # # We can invoke the :code:`run` method of the :code:`nataf_obj` object to transform the non-Gaussian random variables # from space :code:`X`to the correlated standard normal space :code:`Z`. Here, we provide as :code:`boolean (True)` an # optional attribute :code:`jacobian` to calculate the Jacobian of the transformation. The distorted correlation matrix # can be accessed in the attribute :code:`corr_z` # %% nataf_obj.run(samples_x=samples_x, jacobian=True) print(nataf_obj.corr_z) # %% md # # We can visualize the correlated (standard normal) samples by plotting them on axes of each distribution's range. # %% 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()
def test_samples_z_jzx1(): dist1 = Normal(loc=0.0, scale=5.0) ntf_obj = Nataf(distributions=[dist1]) samples_z = np.array([0.3, 1.2, 3.5]) ntf_obj.run(samples_z=samples_z, jacobian=False) assert ntf_obj.jzx is None
def test_samples_z_shape(): dist1 = Normal(loc=0.0, scale=5.0) ntf_obj = Nataf(distributions=[dist1]) samples_z = np.array([0.3, 1.2, 3.5]) ntf_obj.run(samples_z) assert ntf_obj.samples_z.shape == (3, 1)