btb.tuning.hyperparams.numerical module

Package where the NumericalHyperParam class and it’s childs are defined.

class btb.tuning.hyperparams.numerical.FloatHyperParam(min=None, max=None, default=None, include_min=True, include_max=True)[source]

Bases: btb.tuning.hyperparams.numerical.NumericalHyperParam

FloatHyperParam class.

The FloatHyperParam class represents a single hyperparameter within a range of float numbers, where min and max can take as value any float number within that range, having min to be smaller than max.

Hyperparameter space:

\(h_1, h_2,... h_n\) where \(h_i = i * (max - min) + min\)

Search space:

\(s_1, s_2,... s_n\) where \(s_i = (i - min) / (max - min)\)

Parameters
  • min (float) – Float number to represent the minimum value that this hyperparameter can take, by default is None which will take the system’s minimum float value possible.

  • max (float) – Float number to represent the maximum value that this hyperparameter can take, by default is None which will take the system’s maximum float value possible.

  • default (float) – Float number that represents the default value for the hyperparameter. Defaults to self.min

  • include_min (bool) – Either or not to include the minimum value in the search space.

  • include_max (bool) – Either or not to include the maximum value in the search space.

cardinality = inf
sample(n_samples)[source]

Generate sample values in the hyperparameter search space \({0, 1}\).

Parameters

n_samples (int) – Number of values to sample.

Returns

2D array with shape of (n_samples, 1) with normalized values inside the search space \({0, 1}\).

Return type

numpy.ndarray

Example

The example below shows simple usage case where a FloatHyperParam is being created with a range that goes from 0.1 to 0.9 and it’s sample method is being called with a number of samples to be obtained. A numpy.ndarray with values from the search space is being returned.

>>> instance = FloatHyperParam(min=0.1, max=0.9)
>>> instance.sample(2)
array([[0.52058728],
       [0.00582452]])
class btb.tuning.hyperparams.numerical.IntHyperParam(min=None, max=None, default=None, include_min=True, include_max=True, step=1)[source]

Bases: btb.tuning.hyperparams.numerical.NumericalHyperParam

IntHyperParam class.

The IntHyperParam class represents a single hyperparameter within an range of int numbers, where min and max can take as value any int number that compose this range having min to be smaller than max.

Hyperparameter space:

\(h_1, h_2,... h_n\) where \(h_i = min + (i - 1) * step\)

Search space:

\(s_1, s_2,... s_n\) where \(s_i = \frac{interval}{2} + (i - 1) * interval\)

Parameters
  • min (int) – Integer number to represent the minimum value that this hyperparameter can take, by default is None which will take the system’s minimum int value possible.

  • max (int) – Integer number to represent the maximum value that this hyperparameter can take, by default is None which will take the system’s maximum int value possible.

  • default (int) – Integer number that represents the default value for the hyperparameter. Defaults to self.min.

  • step (int) – Increase amount to take for each sample. Defaults to 1.

  • include_min (bool) – Either or not to include the minimum value in the search space.

  • include_max (bool) – Either or not to include the maximum value in the search space.

dimensions = 1
sample(n_samples)[source]

Generate sample values in the hyperparameter search space of [0, 1).

Parameters

n_samples (int) – Number of values to sample.

Returns

2D array with shape of (n_samples, 1) with normalized values inside the search space \({0, 1}\).

Return type

numpy.ndarray

Example

The example below shows simple usage case where a IntHyperParam is being created with a range that goes from 1 to 4 and it’s sample method is being called with a number of samples to be obtained. A numpy.ndarray with values from the search space is being returned.

>>> instance = IntHyperParam(min=1, max=4)
>>> instance.sample(2)
array([[0.625],
       [0.375]])
class btb.tuning.hyperparams.numerical.NumericalHyperParam[source]

Bases: btb.tuning.hyperparams.base.BaseHyperParam

NumericalHyperParam class.

The NumericalHyperParam class defines an abstraction to hyperparameters which ranges are defined by a numerical value and can take any number within that range.

dimensions = 1