Delaunay Stratified Sampling

In this example, the stratified sampling method is employed to generate samples from an exponential distribution using Delaunay stratification.

Import the necessary libraries. Here we import standard libraries such as numpy and matplotlib, but also need to import the DelaunayStrata and TrueStratifiedSampling class from UQpy.sampling.

from UQpy.sampling.stratified_sampling.TrueStratifiedSampling import TrueStratifiedSampling
from UQpy.sampling.stratified_sampling.strata import DelaunayStrata
from UQpy.distributions import Exponential
import numpy as np
import matplotlib.pyplot as plt

Run TrueStratifiedSampling for 25 samples.

  • 2 dimensions

  • Five strata in each dimension

  • Exponential distribution with location parameter = 1 and scale parameter = 1.

Create a distribution object.

marginals = [Exponential(loc=1., scale=1.), Exponential(loc=1., scale=1.)]

Equal number of samples in each stratum

Create strata object using VoronoiStrata class.

seeds = np.array([[0, 0], [0.4, 0.8], [1, 0], [1, 1]])
strata_obj = DelaunayStrata(seeds=seeds)
sts_obj = TrueStratifiedSampling(distributions=marginals, strata_object=strata_obj)

Figure shows the stratification of domain using randomly generated seed points. Notice that DelaunayStrata class include the corners of \([0, 1]^{dimension}\) hypercube before constructing Delaunay Triangulation. In this plot, orange points are the seed points and left corner is also included in the delaunay construction

plt.triplot(strata_obj.delaunay.points[:, 0], strata_obj.delaunay.points[:, 1], strata_obj.delaunay.simplices)
plt.plot(seeds[:, 0], seeds[:, 1], 'or')
plt.show()
plot true stratified delaunay

Run stratified sampling

sts_obj = TrueStratifiedSampling(distributions=marginals, strata_object=strata_obj)
sts_obj.run(nsamples_per_stratum=2)

Plot the resulting stratified samples and the boundaries of the strata in the \(U(0,1)\) space.

plt.triplot(strata_obj.delaunay.points[:, 0], strata_obj.delaunay.points[:, 1], strata_obj.delaunay.simplices)
plt.plot(seeds[:, 0], seeds[:, 1], 'or')
plt.plot(sts_obj.samplesU01[:, 0], sts_obj.samplesU01[:, 1], 'dm')
plt.title('Stratified Sample - U(0,1)')
plt.show()

sts_obj.weights
Stratified Sample - U(0,1)
array([0.1 , 0.1 , 0.2 , 0.2 , 0.05, 0.05, 0.15, 0.15])

Proportional Sampling

Delaunay class can generate samples proportional to volume of each stratum.

sts_obj = TrueStratifiedSampling(distributions=marginals, strata_object=strata_obj)
sts_obj.run(nsamples=10)

It can be noticed that new sample in each stratum is proportional to volume

print('Volume: ', sts_obj.strata_object.volume)
print('Number of samples in each stratum: ', sts_obj.nsamples_per_stratum)

plt.triplot(strata_obj.delaunay.points[:, 0], strata_obj.delaunay.points[:, 1], strata_obj.delaunay.simplices)
plt.plot(seeds[:, 0], seeds[:, 1], 'or')
plt.plot(sts_obj.samplesU01[:, 0], sts_obj.samplesU01[:, 1], 'dm')
plt.show()
plot true stratified delaunay
Volume:  [0.2 0.4 0.1 0.3]
Number of samples in each stratum:  [2. 4. 1. 3.]

Total running time of the script: ( 0 minutes 0.129 seconds)

Gallery generated by Sphinx-Gallery