blackboxopt.sampling module

Sampling strategies for the optimization algorithms.

class blackboxopt.sampling.Mitchel91Sampler(n: int, strategy: SamplingStrategy = SamplingStrategy.MITCHEL91, *, maxCand: int | None = None, scale: float = 2.0) None

Bases: Sampler

Sampler based from [1] that fills gaps in the search space.

Parameters:
  • maxCand (Optional[int]) – The maximum number of random candidates from which each sample points is selected. If None it receives the value 10*n instead. Stored in maxCand. (default: None)

  • scale (float) – A scaling factor proportional to the number of candidates used to select each sample point. Stored in scale. (default: 2.0)

maxCand

The maximum number of random candidates from which each sample points is selected. Used by get_mitchel91_sample().

scale

A scaling factor proportional to the number of candidates used to select each sample point. Used by get_mitchel91_sample().

References

get_mitchel91_sample(bounds, *, iindex: tuple[int, ...] = (), current_sample=()) ndarray

Generate a sample that aims to fill gaps in the search space.

This algorithm generates a sample that fills gaps in the search space. In each iteration, it generates a pool of candidates, and selects the point that is farthest from current sample points to integrate the new sample. This algorithm was proposed by Mitchel (1991).

Parameters:
  • bounds (sequence) – List with the limits [x_min,x_max] of each direction x in the space.

  • iindex (tuple[int, ...]) – Indices of the input space that are integer. (default: ())

  • current_sample – Sample points already drawn. (default: ())

Return type:

ndarray

Returns:

Matrix with a sample point per line.

get_sample(bounds, *, iindex: tuple[int, ...] = (), **kwargs) ndarray

Generates a sample.

Parameters:
  • bounds (sequence) – List with the limits [x_min,x_max] of each direction x in the space.

  • iindex (tuple[int, ...]) – Indices of the input space that are integer. (default: ())

  • current_sample – Sample points already drawn. Used by SamplingStrategy.MITCHEL91.

Return type:

ndarray

Returns:

Matrix with a sample point per line.

class blackboxopt.sampling.NormalSampler(n: int, sigma: float, *, sigma_min: float = 0, sigma_max: float = 0.25, strategy: SamplingStrategy = SamplingStrategy.NORMAL) None

Bases: Sampler

Sampler that generates sample points from a truncated normal distribution.

Parameters:

sigma (float) – Standard deviation of the truncated normal distribution,

relative to a unitary interval. Stored in sigma. :type sigma_min: float :param sigma_min: Minimum limit for the standard deviation, relative to

a unitary interval. Stored in sigma_min. (default: 0)

Parameters:

sigma_max (float) – Maximum limit for the standard deviation, relative to a unitary interval. Stored in sigma_max. (default: 0.25)

sigma

Standard deviation of the truncated normal distribution, relative to a unitary interval. Used by get_normal_sample() and get_dds_sample().

sigma_min

Minimum standard deviation of the truncated normal distribution, relative to a unitary interval.

sigma_max

Maximum standard deviation of the truncated normal distribution, relative to a unitary interval.

get_dds_sample(bounds, mu, probability: float, *, iindex: tuple[int, ...] = (), coord=()) ndarray

Generate a sample based on the Dynamically Dimensioned Search (DDS) algorithm described in [2].

This algorithm generated a sample by perturbing a subset of the coordinates of mu. The set of coordinates perturbed varies for each sample point and is determined probabilistically. When a perturbation occurs, it is guided by a normal distribution with mean zero and standard deviation sigma.

Parameters:
  • bounds (sequence) – List with the limits [x_min,x_max] of each direction x in the space.

  • mu – Point around which the sample will be generated.

  • probability (float) – Perturbation probability.

  • iindex (tuple[int, ...]) – Indices of the input space that are integer. (default: ())

  • coord – Coordinates of the input space that will vary. If (), all coordinates will vary. (default: ())

Return type:

ndarray

Returns:

Matrix with a sample point per line.

References

get_diameter(d: int) float

Diameter of the sampling region relative to a d-dimensional cube.

For the normal sampler, the diameter is relative to the std. This implementation considers the region of 95% of the values on each coordinate, which has diameter 4*sigma. This value is also backed up by [3], in their Local MSRS method.

Parameters:

d (int) – Number of dimensions in the space.

Return type:

float

References

get_normal_sample(bounds, mu, *, iindex=(), coord=()) ndarray

Generate a sample from a truncated normal distribution around a given point mu.

Parameters:
  • bounds (sequence) – List with the limits [x_min,x_max] of each direction x in the space.

  • mu – Point around which the sample will be generated.

  • iindex – Indices of the input space that are integer. (default: ())

  • coord (sequence) – Coordinates of the input space that will vary. If (), all coordinates will vary.

Return type:

ndarray

Returns:

Matrix with a sample point per line.

get_sample(bounds, *, iindex: tuple[int, ...] = (), **kwargs) ndarray

Generate a sample.

Parameters:
Return type:

ndarray

Returns:

Matrix with a sample point per line.

class blackboxopt.sampling.Sampler(n: int, strategy: SamplingStrategy = SamplingStrategy.UNIFORM) None

Bases: object

Abstract base class for samplers.

The main goal of a sampler is to draw samples from a d-dimensional box. For that, one should use get_sample() or the specific get_[strategy]_sample(). The former uses the information in strategy to decide which specific sampler to use.

Parameters:
  • n (int) – Number of sample points. Stored in n.

  • strategy (SamplingStrategy) – Sampling strategy. Stored in strategy. (default: <SamplingStrategy.UNIFORM: 3>)

n

Number of sample points returned by get_[strategy]_sample().

strategy

Sampling strategy that will be used by get_sample() and get_[strategy]_sample().

get_diameter(d: int) float

Diameter of the sampling region relative to a d-dimensional cube.

Parameters:

d (int) – Number of dimensions in the space.

Return type:

float

get_sample(bounds, *, iindex: tuple[int, ...] = (), **kwargs) ndarray

Generate a sample based on Sampler.strategy.

Parameters:
  • bounds (sequence) – List with the limits [x_min,x_max] of each direction x in the space.

  • iindex (tuple[int, ...]) – Indices of the input space that are integer. (default: ())

Return type:

ndarray

Returns:

Matrix with a sample point per line.

get_slhd_sample(bounds, *, iindex: tuple[int, ...] = ()) ndarray

Creates a Symmetric Latin Hypercube Design.

Note that, for integer variables, it may not be possible to generate a SLHD. In this case, the algorithm will do its best to try not to repeat values in the integer variables.

Parameters:
  • bounds (sequence) – List with the limits [x_min,x_max] of each direction x in the space.

  • iindex (tuple[int, ...]) – Indices of the input space that are integer. (default: ())

Return type:

ndarray

Returns:

Matrix with a sample point per line.

get_uniform_sample(bounds, *, iindex: tuple[int, ...] = ()) ndarray

Generate a sample from a uniform distribution inside the bounds.

Parameters:
  • bounds (sequence) – List with the limits [x_min,x_max] of each direction x in the space.

  • iindex (tuple[int, ...]) – Indices of the input space that are integer. (default: ())

Return type:

ndarray

Returns:

Matrix with a sample point per line.

class blackboxopt.sampling.SamplingStrategy(value)

Bases: Enum

Sampling strategy tags to be used by get_sample() methods that override Sampler.get_sample().

DDS = 2

DDS sampling. Used in the DYCORS algorithm

DDS_UNIFORM = 4

Sample half via DDS, then half via uniform distribution

MITCHEL91 = 6

Cover empty regions in the search space

NORMAL = 1

Normal distribution

SLHD = 5

Symmetric Latin Hypercube Design

UNIFORM = 3

Uniform distribution