import numpy as np import pytest from beartype.roar import BeartypeCallHintPepParamException from UQpy.distributions import Normal, MultivariateNormal from UQpy.sampling import MonteCarloSampling dist1 = Normal(loc=0., scale=1.) dist2 = Normal(loc=0., scale=1.) x = MonteCarloSampling(distributions=dist1, nsamples=5, random_state=np.random.RandomState(123)) x.transform_u01() y = MonteCarloSampling(distributions=[dist1, dist2]) y.run(nsamples=5, random_state=123) y.transform_u01() # Call run method multiple time, to cover lines where samples are append to existing ones z1 = MonteCarloSampling(distributions=dist1, nsamples=2, random_state=123) z1.run(nsamples=2) z2 = MonteCarloSampling(distributions=[dist1, dist2], nsamples=2, random_state=np.random.RandomState(123)) z2.run(nsamples=2) # Same object as z2, just to cover lines where, random_state is an integer z3 = MonteCarloSampling(distributions=[dist1, dist2], nsamples=2, random_state=123) z4 = MonteCarloSampling(distributions=[MultivariateNormal([0, 0])], nsamples=2, random_state=np.random.RandomState(123)) z4.run(nsamples=2) z4.transform_u01() dist3 = Normal(loc=0., scale=1.) del dist3.rvs z5 = MonteCarloSampling(distributions=[dist3], random_state=np.random.RandomState(123))
# %% mc.run(nsamples=2, random_state=RandomState(23)) mc.samples # %% md # # We can transform the samples onto the unit hypercube via applying the probability integral transformation on the # samples to yield similar samples from the uniform distribution. We call :code:`mc.transform_u01`, from which results # are stored in the :code:`samplesU01` attribute. # %% mc.transform_u01() mc.samplesU01 # %% md # # We can visualize the (untransformed) samples by plotting them on axes of each distribution's range. # %% fig, ax = plt.subplots() plt.title('Samples') plt.scatter(x=mc.samples[:, 0], y=mc.samples[:, 1], marker='o') plt.setp(ax, xlim=(-1.7, 1.7), ylim=(-2.6, 2.6))