easyvvuq.sampling.quasirandom

Summary

This module provides classes based on RandomSampler but modified in such a way that the output of the sampler is not random but is meant to be used in place of uniformly random number sequences. Usually this is used to cover the sampling space more "evenly" than a uniform random distribution would. Two methods are implemented:

https://en.wikipedia.org/wiki/Latin_hypercube_sampling https://en.wikipedia.org/wiki/Halton_sequence

 1"""
 2Summary
 3-------
 4This module provides classes based on RandomSampler but modified in such a way
 5that the output of the sampler is not random but is meant to be used in place
 6of uniformly random number sequences. Usually this is used to cover the sampling
 7space more "evenly" than a uniform random distribution would. Two methods are
 8implemented:
 9
10https://en.wikipedia.org/wiki/Latin_hypercube_sampling
11https://en.wikipedia.org/wiki/Halton_sequence
12
13"""
14
15
16from .random import RandomSampler
17
18
19class LHCSampler(RandomSampler, sampler_name='lhc_sampler'):
20    def __next__(self):
21        if self.is_finite():
22            if self.count >= self.max_num:
23                raise StopIteration
24
25        run_dict = {}
26        for param_name, dist in self.vary.get_items():
27            run_dict[param_name] = dist.sample(1, rule='L')[0]
28
29        self.count += 1
30        return run_dict
31
32
33class HaltonSampler(RandomSampler, sampler_name='halton_sampler'):
34    def __next__(self):
35        if self.is_finite():
36            if self.count >= self.max_num:
37                raise StopIteration
38
39        run_dict = {}
40        for param_name, dist in self.vary.get_items():
41            run_dict[param_name] = dist.sample(1, rule='H')[0]
42
43        self.count += 1
44        return run_dict
class LHCSampler(easyvvuq.sampling.random.RandomSampler):
20class LHCSampler(RandomSampler, sampler_name='lhc_sampler'):
21    def __next__(self):
22        if self.is_finite():
23            if self.count >= self.max_num:
24                raise StopIteration
25
26        run_dict = {}
27        for param_name, dist in self.vary.get_items():
28            run_dict[param_name] = dist.sample(1, rule='L')[0]
29
30        self.count += 1
31        return run_dict

Baseclass for all EasyVVUQ sampling elements.

Attributes
  • sampler_name (str): Name of the particular sampler.
sampler_name = 'lhc_sampler'
class HaltonSampler(easyvvuq.sampling.random.RandomSampler):
34class HaltonSampler(RandomSampler, sampler_name='halton_sampler'):
35    def __next__(self):
36        if self.is_finite():
37            if self.count >= self.max_num:
38                raise StopIteration
39
40        run_dict = {}
41        for param_name, dist in self.vary.get_items():
42            run_dict[param_name] = dist.sample(1, rule='H')[0]
43
44        self.count += 1
45        return run_dict

Baseclass for all EasyVVUQ sampling elements.

Attributes
  • sampler_name (str): Name of the particular sampler.
sampler_name = 'halton_sampler'