Parameter Spaces#

Parameter spaces define the search domains for hyperparameter optimization.

hyperoptax.spaces.log_transform(x, base)[source]#
Parameters:
Return type:

float

class hyperoptax.spaces.Space[source]#

Bases: ABC

Abstract base class for hyperparameter search spaces.

abstract sample(key)[source]#
Parameters:

key (PRNGKey)

Return type:

Array

transform(value)[source]#
__init__()#
Return type:

None

class hyperoptax.spaces.LinearSpace(lower_bound, upper_bound)[source]#

Bases: Space

Uniform continuous space over [lower_bound, upper_bound].

Parameters:
lower_bound#

Inclusive lower bound of the interval.

Type:

float

upper_bound#

Exclusive upper bound of the interval.

Type:

float

lower_bound: float#
upper_bound: float#
sample(key)[source]#
Parameters:

key (PRNGKey)

Return type:

float

__init__(lower_bound, upper_bound)#
Parameters:
Return type:

None

class hyperoptax.spaces.DiscreteSpace(values)[source]#

Bases: Space

Discrete space over a fixed set of values.

Samples uniformly from values. transform snaps any continuous value to the nearest element, which is useful when discrete candidates are generated via continuous optimization (e.g. in BayesianSearch).

Parameters:

values (tuple)

values#

Tuple of candidate values to sample from.

Type:

tuple

values: tuple#
property lower_bound: float#
property upper_bound: float#
sample(key)[source]#
Parameters:

key (PRNGKey)

Return type:

float

transform(value)[source]#
Return type:

Array

__init__(values)#
Parameters:

values (tuple)

Return type:

None

class hyperoptax.spaces.LogSpace(lower_bound, upper_bound, base=10)[source]#

Bases: LinearSpace

Log-uniform continuous space over [lower_bound, upper_bound].

Samples uniformly in log space so that each order of magnitude receives equal probability mass. Useful for learning rates and other scale parameters that span several orders of magnitude.

Parameters:
lower_bound#

Inclusive lower bound (in original scale, e.g. 1e-5).

Type:

float

upper_bound#

Exclusive upper bound (in original scale, e.g. 1e-1).

Type:

float

base#

Logarithm base (default 10). Must be greater than 1.

Type:

float

base: float = 10#
sample(key)[source]#
Parameters:

key (PRNGKey)

Return type:

Array

__init__(lower_bound, upper_bound, base=10)#
Parameters:
Return type:

None

lower_bound: float#
upper_bound: float#
class hyperoptax.spaces.QLinearSpace(lower_bound, upper_bound, datatype=<class 'jax.numpy.int32'>)[source]#

Bases: LinearSpace

Quantized (integer) variant of LinearSpace.

Samples uniformly from [lower_bound, upper_bound] and rounds to the nearest integer. Use this for discrete integer hyperparameters with a uniform prior (e.g. number of layers, batch size).

Parameters:
lower_bound#

Inclusive lower bound.

Type:

float

upper_bound#

Exclusive upper bound.

Type:

float

datatype#

Integer dtype used after rounding (default jnp.int32).

Type:

type

datatype#

alias of int32

transform(value)[source]#
Return type:

Array

__init__(lower_bound, upper_bound, datatype=<class 'jax.numpy.int32'>)#
Parameters:
Return type:

None

class hyperoptax.spaces.QLogSpace(lower_bound, upper_bound, base=10, datatype=<class 'jax.numpy.int32'>)[source]#

Bases: LogSpace

Quantized (integer) variant of LogSpace.

Samples in log space and rounds to the nearest integer. Use this for integer hyperparameters whose scale spans orders of magnitude (e.g. number of hidden units, number of warmup steps).

Parameters:
datatype#

alias of int32

transform(value)[source]#
Return type:

Array

__init__(lower_bound, upper_bound, base=10, datatype=<class 'jax.numpy.int32'>)#
Parameters:
Return type:

None

Examples#

Creating a Linear Space#

from hyperoptax import LinearSpace

dropout_space = LinearSpace(0.0, 0.5)

Creating a Logarithmic Space#

from hyperoptax import LogSpace

lr_space = LogSpace(1e-5, 1e-1)

Creating a Discrete Space#

from hyperoptax import DiscreteSpace

optimizer_space = DiscreteSpace(["adam", "sgd", "rmsprop"])
lr_space = DiscreteSpace([1e-4, 1e-3, 1e-2])