LHS

Bases: BaseSampling

Latin Hypercube Sampling (LHS) class.

This class performs the LHS algorithm for some input data.

Attributes:
  • num_dimensions (int) –

    The number of dimensions to use in the LHS algorithm.

  • seed (int) –

    The random seed to use.

  • lhs (LatinHypercube) –

    The Latin Hypercube object.

  • data (DataFrame) –

    The LHS samples dataframe.

Methods:

Name Description
generate

Generate LHS samples.

Notes
  • This class is designed to perform the LHS algorithm.

Examples:

>>> from bluemath_tk.datamining.lhs import LHS
>>> dimensions_names = ['CM', 'SS', 'Qb']
>>> lower_bounds = [0.5, -0.2, 1]
>>> upper_bounds = [5.3, 1.5, 200]
>>> lhs = LHS(num_dimensions=3, seed=0)
>>> lhs_sampled_df = lhs.generate(
...     dimensions_names=dimensions_names,
...     lower_bounds=lower_bounds,
...     upper_bounds=upper_bounds,
...     num_samples=100,
... )

__init__(num_dimensions, seed=1)

Initializes the LHS class.

Parameters:
  • num_dimensions (int) –

    The number of dimensions to use in the LHS algorithm. Must be greater than 0.

  • seed (int, default: 1 ) –

    The random seed to use. Must be greater or equal to 0. Default to 1.

Raises:
  • ValueError

    If num_dimensions or num_samples is not greater than 0. Or if seed is not greater or equal to 0.

generate(dimensions_names, lower_bounds, upper_bounds, num_samples)

Generate LHS samples.

Parameters:
  • dimensions_names (List[str]) –

    The names of the dimensions.

  • lower_bounds (List[float]) –

    The lower bounds of the dimensions.

  • upper_bounds (List[float]) –

    The upper bounds of the dimensions.

  • num_samples (int) –

    The number of samples to generate. Must be greater than 0.

Returns:
  • self.data : pd.DataFrame

    The LHS samples.

LHSError

Bases: Exception

Custom exception for LHS class.