<jupyter_start><jupyter_text>Voronoi Stratified Sampling - Example - Author: <NAME>- Date: July 02, 2020 In this example, the stratified sampling method is employed to generate samples from an exponential distribution using Voronoi stratification. The method illustrates various aspects of the UQpy.SampleMethods.VoronoiSTS class. Import the necessary libraries. Here we import standard libraries such as numpy and matplotlib, but also need to import the VoronoiSTS class from UQpy.SampleMethods.<jupyter_code>from UQpy.SampleMethods import VoronoiStrata, VoronoiSTS
from UQpy.Distributions import Exponential
import numpy as np
import matplotlib.pyplot as plt
import time
from scipy.stats import expon
from scipy.spatial import Voronoi, voronoi_plot_2d<jupyter_output><empty_output><jupyter_text>Run STS for 25 samples.- 2 dimensions- Five strata in each dimension- Exponential distribution with location parameter = 1 and scale parameter = 1.Create a distribution object.<jupyter_code>marginals = [Exponential(loc=1., scale=1.), Exponential(loc=1., scale=1.)]<jupyter_output><empty_output><jupyter_text>Equal number of samples in each stratum  Create strata object using VoronoiStrata class.<jupyter_code>strata_obj = VoronoiStrata(nseeds=8, dimension=2, random_state=3)<jupyter_output><empty_output><jupyter_text>Figure shows the stratification of domain using randomly generated seed points<jupyter_code>voronoi_plot_2d(strata_obj.voronoi)
plt.title('Stratified Sample - U(0,1)')
plt.xlim([0, 1])
plt.ylim([0, 1])
plt.show()<jupyter_output><empty_output><jupyter_text>Run stratified sampling<jupyter_code>sts_vor_obj = VoronoiSTS(dist_object=marginals, strata_object=strata_obj)
sts_vor_obj.run(nsamples_per_stratum=3)<jupyter_output><empty_output><jupyter_text>Plot the resulting stratified samples and the boundaries of the strata in the U(0,1) space.<jupyter_code>voronoi_plot_2d(strata_obj.voronoi)
plt.title('Stratified Sample - U(0,1)')
plt.plot(sts_vor_obj.samplesU01[:, 0], sts_vor_obj.samplesU01[:, 1], 'dm')
plt.xlim([0, 1])
plt.ylim([0, 1])
plt.show()
sts_vor_obj.weights<jupyter_output><empty_output><jupyter_text>Proportional Sampling  VoronoiSTS class can generate samples proportional to volume of each strarum.<jupyter_code>sts_vor_obj1 = VoronoiSTS(dist_object=marginals, strata_object=strata_obj)
sts_vor_obj1.run(nsamples=10)<jupyter_output><empty_output><jupyter_text>It can be noticed that new sample in each stratum is proportional to volume<jupyter_code>print('Volume: ', sts_vor_obj1.strata_object.volume)
print('Number of samples in each stratum: ', sts_vor_obj1.nsamples_per_stratum)
voronoi_plot_2d(strata_obj.voronoi)
plt.title('Stratified Sample - U(0,1)')
plt.plot(sts_vor_obj.samplesU01[:, 0], sts_vor_obj.samplesU01[:, 1], 'dm')
plt.xlim([0, 1])
plt.ylim([0, 1])
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09897851356111306, 'fraction_numerical': 0.021486438886932017, 'mean_word_length': 8.281045751633988, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 34, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '204972', 'license': 'MIT', 'n_tokens_mistral': 1040, 'n_tokens_neox': 974, 'n_words': 233, 'path': 'example/SampleMethods/STS/STS_Example2.ipynb', 'repo_name': 'GuoQiang-Fu/UQpy', 'size': '2851'}