emukit.quadrature.measures package

Module contents

Integration measures.

class emukit.quadrature.measures.BoxDomain(bounds, name='')

Bases: object

A box domain defined by a hyper-cube.

Parameters:
  • bounds (List[Tuple[float, float]]) – The bounds defining the box. List of \(d\) tuples \([(a_1, b_1), (a_2, b_2), \dots, (a_d, b_d)]\), where \(d\) is the dimensionality of the domain and the tuple \((a_i, b_i)\) contains the lower and upper bound of dimension \(i\) defining the box domain.

  • name (str) – Name of parameter.

property bounds: List[Tuple[float, float]]

The bounds defining the hypercube.

convert_to_list_of_continuous_parameters()

Converts the box bounds into a list of ContinuousParameter objects.

Return type:

List[ContinuousParameter]

Returns:

The continuous parameters (one for each dimension of the box).

class emukit.quadrature.measures.IntegrationMeasure(domain, name)

Bases: object

An abstract class for an integration measure defined by a density.

Parameters:
  • domain (Optional[BoxDomain]) – The domain. None implies \(\mathbb{R}^d\).

  • name (str) – Name of the integration measure

property input_dim

The input dimensionality.

property can_sample: bool

Indicates whether the measure has sampling available.

Returns:

True if sampling is available. False otherwise.

compute_density(x)

Evaluates the density at x.

Parameters:

x (ndarray) – Points at which density is evaluated, shape (n_points, input_dim).

Return type:

ndarray

Returns:

The density at x, shape (n_points, ).

compute_density_gradient(x)

Evaluates the gradient of the density at x.

Parameters:

x (ndarray) – Points at which the gradient is evaluated, shape (n_points, input_dim).

Return type:

ndarray

Returns:

The gradient of the density at x, shape (n_points, input_dim).

reasonable_box()

A reasonable box containing the measure.

Outside this box, the measure should be zero or virtually zero.

Return type:

List[Tuple[float, float]]

Returns:

The reasonable box.

sample(num_samples, context_manager=None)

Samples from the measure.

Parameters:
  • num_samples (int) – The number of samples to be taken.

  • context_manager (Optional[ContextManager]) – The context manager that contains variables to fix and the values to fix them to. If a context is given, this method samples from the conditional distribution.

Return type:

ndarray

Returns:

The samples, shape (num_samples, input_dim).

class emukit.quadrature.measures.GaussianMeasure(mean, variance)

Bases: IntegrationMeasure

The Gaussian measure.

The Gaussian measure has density

\[p(x)=(2\pi)^{-\frac{d}{2}} \left(\prod_{j=1}^d \sigma_j^2\right)^{-\frac{1}{2}} e^{-\frac{1}{2}\sum_{i=1}^d\frac{(x_i-\mu_i)^2}{\sigma_i^2}}\]

where \(\mu_i\) is the \(i\) th element of the mean parameter and \(\sigma_i^2\) is \(i\) th element of the variance parameter.

Parameters:
  • mean (ndarray) – The mean of the Gaussian measure, shape (input_dim, ).

  • variance (Union[float, ndarray]) – The variances of the Gaussian measure, shape (input_dim, ). If a scalar value is given, all dimensions will have same variance.

Raises:
  • TypeError – If mean is not of type ndarray.

  • ValueError – If mean is not of dimension 1.

  • TypeError – If variance is neither of type float nor of type ndarray.

  • ValueError – If variance is of type float but is non-positive.

  • ValueError – If variance is of type ndarray but of other size than mean.

  • ValueError – If variance is of type ndarray and any of its elements is non-positive.

property input_dim

The input dimensionality.

property full_covariance_matrix

The full covariance matrix of the Gaussian measure.

property can_sample: bool

Indicates whether the measure has sampling available.

Returns:

True if sampling is available. False otherwise.

compute_density(x)

Evaluates the density at x.

Parameters:

x (ndarray) – Points at which density is evaluated, shape (n_points, input_dim).

Return type:

ndarray

Returns:

The density at x, shape (n_points, ).

compute_density_gradient(x)

Evaluates the gradient of the density at x.

Parameters:

x (ndarray) – Points at which the gradient is evaluated, shape (n_points, input_dim).

Return type:

ndarray

Returns:

The gradient of the density at x, shape (n_points, input_dim).

reasonable_box()

A reasonable box containing the measure.

Outside this box, the measure should be zero or virtually zero.

Return type:

List[Tuple[float, float]]

Returns:

The reasonable box.

sample(num_samples, context_manager=None)

Samples from the measure.

Parameters:
  • num_samples (int) – The number of samples to be taken.

  • context_manager (Optional[ContextManager]) – The context manager that contains variables to fix and the values to fix them to. If a context is given, this method samples from the conditional distribution.

Return type:

ndarray

Returns:

The samples, shape (num_samples, input_dim).

class emukit.quadrature.measures.LebesgueMeasure(domain, normalized=False)

Bases: IntegrationMeasure

The Lebesgue measure.

The Lebesgue measure has density

\[\begin{split}p(x)=\begin{cases} \hat{p} & x\in\text{domain}\\0 &\text{otherwise}\end{cases}.\end{split}\]

The value \(\hat{p} = 1\) if the parameter normalized is set to False and \(\hat{p} = |\text{domain}|^{-1}\) otherwise, where \(|\text{domain}|\) is the volume (un-normalized Lebesgue measure) of the domain.

Parameters:
  • domain (BoxDomain) – The Box domain.

  • normalized (bool) – Weather the Lebesgue measure is normalized.

Raises:

NumericalPrecisionError – If normalized=True this excetion can be raised if the volume of the domain is so small that it is numerically zero or even negative.

property input_dim

The input dimensionality.

property can_sample: bool

Indicates whether the measure has sampling available.

Returns:

True if sampling is available. False otherwise.

compute_density(x)

Evaluates the density at x.

Parameters:

x (ndarray) – Points at which density is evaluated, shape (n_points, input_dim).

Return type:

ndarray

Returns:

The density at x, shape (n_points, ).

compute_density_gradient(x)

Evaluates the gradient of the density at x.

Parameters:

x (ndarray) – Points at which the gradient is evaluated, shape (n_points, input_dim).

Return type:

ndarray

Returns:

The gradient of the density at x, shape (n_points, input_dim).

reasonable_box()

A reasonable box containing the measure.

Outside this box, the measure should be zero or virtually zero.

Return type:

List[Tuple[float, float]]

Returns:

The reasonable box.

sample(num_samples, context_manager=None)

Samples from the measure.

Parameters:
  • num_samples (int) – The number of samples to be taken.

  • context_manager (Optional[ContextManager]) – The context manager that contains variables to fix and the values to fix them to. If a context is given, this method samples from the conditional distribution.

Return type:

ndarray

Returns:

The samples, shape (num_samples, input_dim).

classmethod from_bounds(bounds, normalized=False)

Creates and instance of this class from integration bounds.

Parameters:
  • bounds (List[Tuple[float, float]]) – List of \(d\) tuples \([(a_1, b_1), (a_2, b_2), \dots, (a_d, b_d)]\), where \(d\) is the dimensionality of the domain and the tuple \((a_i, b_i)\) contains the lower and upper bound of dimension \(i\) defining the box domain.

  • normalized (bool) – Weather the Lebesgue measure is normalized.

Returns:

An instance of LebesgueMeasure.