sampling

Various ways to generate datapoints from the solution space, such that it is well covered. Uses IO_Objects.Descriptor to determine which inputs are valid.

class sampling.adaptive_sampler_lv(P, P_out, n_new, problem, evaluator, reg, test_in, test_out, scaler=None, scaler_out=None, verbose=False)[source]

Represents an adaptive sampler which iteratively picks simulation samples and runs them.

sampling.add_extremes(df: DataFrame, problem: Problem) DataFrame[source]

Adds two datapoints with the minimum and maximum values for each attribute.

Parameters:
  • df – existing data to which the extreme values should be added.

  • problem – the problem defining which values are valid.

Returns:

df with 2 added rows, one with maximal values, one with minimal values.

sampling.dist_sampler(sampler: Callable[[int, int, Any], ndarray], problem: Problem, num_samples: int, *args, **kwargs) DataFrame[source]

uses the sampling function provided to generate num_samples sets of values These values will be valid for the corresponding inputs

Parameters:
  • problem – Problem that the inputs should apply to

  • sampler – a function that is used to produce the distribution of samples

  • num_samples – number of samples to take

  • args – Arguments passed to the sampling function

  • kwargs – Arguments passed to the sampling function

Returns:

pandas DataFrame with one column per parameter, and num_samples rows

sampling.extremes(samples: int, attributes: Optional[int] = None) ndarray[source]

This sampler generates datapoints corresponding to the extremes of a problem.

Parameters:
  • samples – the number of samples. Must be equal to 2 (this argument is available in order to implement the sampler interface) If only one argument is provided, that argument will be assigned to attributes, even though samples is listed first.

  • attributes – the number of attributes for which to generate samples

Returns:

An array containing 2 samples: one with all zeroes, one with all ones. When transformed by a problem, these become minimal and maximal values for that problem.

sampling.full_factorial(samples: int, attributes: int, level: Optional[int] = None) ndarray[source]

MUST BE USED AS AN INPUT TO dist_sampler. Creates every possible combination of variables

Parameters:
  • samples – the number of samples

  • attributes – number of parameters that are to be varied

  • level – [in args/kwargs for dist_sampler]

Returns:

an array of floats between 0 and 1 to be transformed in dist_sampler

sampling.lhs(samples: int, attributes: int, *args, **kwargs) ndarray[source]

MUST BE USED AS AN INPUT TO dist_sampler. Uses latin hypercube sampling to create samples

Parameters:
  • samples – the number of samples

  • attributes – number of parameters that are to be varied

  • args – [in args/kwargs for dist_sampler] Arguments passed to pyDOE2.lhs

  • kwargs – [in args/kwargs for dist_sampler] Arguments passed to pyDOE2.lhs

Returns:

an array of floats between 0 and 1 to be transformed in dist_sampler

sampling.morris_sample(samples: int, attributes: int, problem_dup: ~besos.problem.Problem, steps=None, random_order: bool = False, chooser=<built-in method random of Random object>)[source]

MUST BE USED AS AN INPUT TO dist_sampler. Using a set of starting points (origins), begins a random walk at each one through the parameter space.

Parameters:
  • samples – number of samples that are used as the origins - NOT total number of samples

  • attributes – number of parameters that are to be varied

  • problem_dup – [in args/kwargs for dist_sampler] the problem that is used

  • steps – [in args/kwargs for dist_sampler] how long the random walk should be for each point (the number of times a variable is changed)

  • random_order – [in args/kwargs for dist_sampler] boolean, -> if true: randomizes the order of the variables to be cycled through, and rerandomizes every time all variables are cycled through -> if false: uses the original order

Chooser:

[in args/kwargs for dist_sampler] function, how to choose a random number between 0 and 1. random.random default, so a uniform distribution, must take no arguments

Returns:

an array of floats between 0 and 1 to be transformed in dist_sampler

sampling.neighborhood_sample(samples: int, attributes: int, problem_dup: Problem, subdivisions: int = 2)[source]

MUST BE USED AS AN INPUT TO dist_sampler. Using a set of starting points (origins), varies each parameter one at a time to explore the ‘neighorhood’ of each starting point.

Parameters:
  • samples – number of samples that are used as the origins - NOT total number of samples

  • attributes – number of parameters that are to be varied

  • problem_dup – [in args/kwargs for dist_sampler] the problem that is used

  • subdivisions – [in args/kwargs for dist_sampler] for range parameters, this is the number of subdivisions (>= 2)

Returns:

an array of floats between 0 and 1 to be transformed in dist_sampler

sampling.random()

rand(d0, d1, …, dn)

Random values in a given shape.

Note

This is a convenience function for users porting code from Matlab, and wraps random_sample. That function takes a tuple to specify the size of the output, which is consistent with other NumPy functions like numpy.zeros and numpy.ones.

Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).

Parameters:
  • d0 (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.

  • d1 (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.

  • ... (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.

  • dn (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.

Returns:

out – Random values.

Return type:

ndarray, shape (d0, d1, ..., dn)

See also

random

Examples

>>> np.random.rand(3,2)
array([[ 0.14022471,  0.96360618],  #random
       [ 0.37601032,  0.25528411],  #random
       [ 0.49313049,  0.94909878]]) #random
sampling.seeded_sampler(samples: int, attributes: int, seed=0) ndarray[source]

MUST BE USED AS AN INPUT TO dist_sampler. Creates random samples from a seed

Parameters:
  • samples – the number of samples

  • attributes – number of parameters that are to be varied

  • seed – [in args/kwargs for dist_sampler] seed to be used

Returns:

an array of floats between 0 and 1 to be transformed in dist_sampler