# samplers¶

Created on 16 aug. 2011

This module contains various classes that can be used for specifying different types of samplers. These different samplers implement basic sampling techniques including Full Factorial sampling, Latin Hypercube sampling, and Monte Carlo sampling.

Code author: jhkwakkel <j.h.kwakkel (at) tudelft (dot) nl>

class samplers.LHSSampler

generates a Latin Hypercube sample for each of the uncertainties in case of categorical uncertainties, it handles the transform as well

sample(distribution, params, size)

generate a Latin Hypercupe Sample.

Parameters: distribution – the distribution to sample from params – the parameters specifying the distribution size – the number of samples to generate
class samplers.MonteCarloSampler

generates a Monte Carlo sample for each of the uncertainties. In case of a Categorical Uncertainty it also handles the transform

sample(distribution, params, size)

generate a Monte Carlo Sample.

Parameters: distribution – the distribution to sample from params – the parameters specifying the distribution size – the number of samples to generate
class samplers.FullFactorialSampler

generates a full factorial sample. If the uncertainty is non categorical, resolution is used to set the samples. If the uncertainty is an integer, their wont be duplicates in the sample. So, samples is equal to or smaller then the specified resolution

deterimine_nr_of_designs(sampled_uncertainties)

Helper function for determining the number of experiments that will be generated given the sampled uncertainties.

Parameters: sampled_uncertainties – a list of sampled uncertainties, as the values return by generate_samples
generate_designs(sampled_uncertainties)

This method provides an alternative implementation to the default implementation provided by Sampler. This version returns a full factorial design across the uncertainties.

Parameters: sampled_uncertainties – a list of sampled uncertainties, as the values return by generate_samples a generator object that yields the designs resulting from combining the uncertainties
generate_samples(uncertainties, size)

The main method of :class: ~sampler.Sampler and its children. This will call the sample method for each of the uncertainties and return the resulting samples

Parameters: uncertainties – a collection of ParameterUncertainty and CategoricalUncertainty instances. size – the number of samples to generate. dict with the uncertainty.name as key, and the sample as value
class samplers.Sampler

base class from which different samplers can be derived

deterimine_nr_of_designs(sampled_uncertainties)

Helper function for determining the number of experiments that will be generated given the sampled uncertainties.

Parameters: sampled_uncertainties – a list of sampled uncertainties, as the values return by generate_samples
distributions = {'integer': <scipy.stats.distributions.randint_gen object at 0x04EC6390>, 'uniform': <scipy.stats.distributions.uniform_gen object at 0x04E26A10>}

types of distributions known by the sampler. by default it knows the uniform continuous distribution for sampling floats, and the uniform discrete distribution for sampling integers.

generate_designs(sampled_uncertainties)

This method provides an alternative implementation to the default implementation provided by Sampler. This version returns a full factorial design across the uncertainties.

Parameters: sampled_uncertainties – a list of sampled uncertainties, as the values return by generate_samples a generator object that yields the designs resulting from combining the uncertainties
generate_samples(uncertainties, size)

The main method of :class: ~sampler.Sampler and its children. This will call the sample method for each of the uncertainties and return the resulting designs.

Parameters: uncertainties – a collection of ParameterUncertainty and CategoricalUncertainty instances. size – the number of samples to generate. dict with the uncertainty.name as key, and the sample as value
sample(distribution, params, size)

method for sampling a number of samples from a particular distribution. The various samplers differ with respect to their implementation of this method.

Parameters: distribution – the distribution to sample from params – the parameters specifying the distribution size – the number of samples to generate