soogo.sampling module

Sampling strategies for the optimization algorithms.

class soogo.sampling.Mitchel91Sampler(n: int, strategy: SamplingStrategy = SamplingStrategy.MITCHEL91, *, maxCand: int = 10000, scale: float = 10) None

Bases: Sampler

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

Parameters:
  • maxCand (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: 10000)

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

maxCand

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

scale

Scaling factor that controls the number of candidates in the pool used to select a sample point. The pool has size scale * [# current points]. 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 soogo.sampling.NormalSampler(n: int, sigma: float, *, 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.

sigma

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

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_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 soogo.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_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 soogo.sampling.SamplingStrategy(*values)

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