btb.tuning.hyperparams package

Module contents

Top level where all the hyperparameters are imported.

class btb.tuning.hyperparams.BooleanHyperParam(default=False)[source]

Bases: btb.tuning.hyperparams.base.BaseHyperParam

BooleanHyperParam class.

The BooleanHyperParam class is responsible for the transformation of boolean values in to normalized search space of \([0, 1]\), providing the ability to sample values of those and to inverse transform from the search space into the hyperparameter space.

Hyperparameter space:

{True, False}

Parameters

default (bool) – Default boolean value for the hyperparameter. Defaults to False.

cardinality = 2
dimensions = 1
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 BooleanHyperParam is being created and it’s sample method is being called with a number of samples to be obtained.

>>> instance = BooleanHyperParam()
>>> instance.sample(2)
array([[1],
       [1]])
class btb.tuning.hyperparams.CategoricalHyperParam(choices, default=<object object>)[source]

Bases: btb.tuning.hyperparams.base.BaseHyperParam

CategoricalHyperParam Class.

The CategoricalHyperParam class is responsible for the transform of categorical values in to normalized search space and provides the inverse transform from search space to hyperparameter space. Also provides a method that generates samples of those.

Hyperparameter space:

\(h_1, h_2,... h_K\) where K is the number of categories.

Search Space:

\(\{ 0, 1 \}^K\) where K is the number of categories.

Parameters
  • choices (list) – List of values that the hyperparameter can be.

  • default (str or None) – Default value for the hyperparameter to take. Defaults to the first item in choices

NO_DEFAULT = <object object>
sample(n_samples)[source]

Generate sample values in the hyperparameter search space of [0, 1]^K.

Parameters

n_samples (int) – Number of values to sample.

Returns

2D array with shape of (n_samples, self.dimensions) with normalized values inside the search space \([0, 1]^K\).

Return type

numpy.ndarray

Example

The example below shows simple usage case where a CategoricalHyperParam is being created with three possible values, (Cat, Dog, Tiger), and it’s method sample is being called with a number of samples to be obtained. A numpy.ndarray with values from the search space is being returned.

>>> instance = CategoricalHyperParam(choices=['Cat', 'Dog', 'Tiger'])
>>> instance.sample(2)
array([[1, 0, 0],
       [0, 1, 0]])
class btb.tuning.hyperparams.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.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]])