Utility module#
Data generation#
References
MD McKay, RJ Beckman, and WJ Conover, “A Comparison of Three Methods for Selecting Values of Input Variables in the Analysis of Output from a Computer Code,” Technometrics, vol. 42, no. 1, p. 55-61, 2000.
- class nubo.utils.latin_hypercube.LatinHypercubeSampling(dims: int)[source]#
Bases:
object
Latin hypercube sampling.
Generates a space-filling design. Two options are possible: sampling from a random or a maximin Latin hypercube. To sample \(n\) points, the random Latin hypercube divides each dimension into \(n\) equal parts and places \(n\) points such that for every dimension each equal part contains exactly one point. The maximin Latin hypercube takes a simple approach and draws a large number of random Latin hypercube samples and returns the one with the largest minimal distance between points.
- Attributes:
- dims
int
Number of dimensions
- dims
Methods
maximin
(points[, samples])Draw a maximin Latin hypercube sample.
random
(points)Draw a random Latin hypercube sample.
- maximin(points: int, samples: int | None = 1000) Tensor [source]#
Draw a maximin Latin hypercube sample.
Draws a large number of random Latin hypercube samples and selects the one with the largest minimal distance between points.
- Parameters:
- points
int
Number of points.
- samples
int
Number of random Latin hypercube samples.
- points
- Returns:
torch.Tensor
(size points x dims) Maximin Latin hypercube sample.
- random(points: int) Tensor [source]#
Draw a random Latin hypercube sample.
To sample \(n\) points, the random Latin hypercube divides each dimension into \(n\) equal parts and places \(n\) points such that for every dimension each equal part contains exactly one point.
- Parameters:
- points
int
Number of points.
- points
- Returns:
torch.Tensor
(size points x dims) Random Latin hypercube sample.
- nubo.utils.generate_inputs.gen_inputs(num_points: int, num_dims: int, bounds: Tensor | None = None, num_lhd: int | None = 1000) Tensor [source]#
Generate data inputs from a maximin Latin hypercube design or from a uniform distribution for one data point.
- Parameters:
- num_points
int
Number of points.
- num_dims
int
Number of input dimensions.
- bounds
torch.Tensor
, optional (size 2 x num_dims) Bounds of input space, default is none. If none, bounds are a [0, 1]^`num_dims`.
- num_lhd
int
, optional Number of Latin hypercube designs to consider, default is 1000.
- num_points
- Returns:
torch.Tensor
(size num_points x num_dims) Input data.
Data transformations#
- nubo.utils.transform.standardise(y: Tensor) Tensor [source]#
Standardise data by subtracting the mean and dividing by the standard deviation:
\[\hat{\boldsymbol y} = \frac{\boldsymbol y - \mu}{\sigma},\]where \(\mu\) is the mean and \(\sigma\) is the standard deviation.
- Parameters:
- y
torch.Tensor
(size n) Data.
- y
- Returns:
torch.Tensor
(size n) Standardised data.
- nubo.utils.transform.normalise(x: Tensor, bounds: Tensor) Tensor [source]#
Normalise data to the unit cube \([0, 1]^d\).
\[\hat{\boldsymbol x} = \frac{\boldsymbol x - lb}{ub - lb},\]where \(lb\) are the lower bounds and \(ub\) are the upper bounds.
- Parameters:
- x
torch.Tensor
(size n x d) Data.
- bounds
torch.Tensor
(size 2 x d) Bounds of input space.
- x
- Returns:
torch.Tensor
Normalised data.
- nubo.utils.transform.unnormalise(x: Tensor, bounds: Tensor) Tensor [source]#
Revere normalisation to the provided bounds.
\[\boldsymbol x = \hat{\boldsymbol x} (ub - lb) + lb,\]where \(lb\) are the lower bounds and \(ub\) are the upper bounds.
- Parameters:
- x
torch.Tensor
(size n x d) Normalised data.
- bounds
torch.Tensor
(size 2 x d) Bounds of input space.
- x
- Returns:
torch.Tensor
Data scaled to bounds.