Space search

Search space of optimization problems

Classes for representing the search space of an optimization problem.

There are 3 classes representing possible parameter types. All of them subclass the base class Dimension:

These are instantiated to declare a problem’s parameter space. Oríon registers them in a ordered dictionary, Space, which describes how the parameters should be in order for orion.algo.base.AbstractAlgorithm implementations to communicate with orion.core.

Parameter values recorded in orion.core.worker.trial.Trial objects must be and are in concordance with orion.algo.space objects. These objects will be defined by orion.core using the user script’s configuration file.

Prior distributions, contained in Dimension classes, are based on scipy.statsdistributions and should be configured as noted in the scipy documentation for each specific implentation of a random variable type, unless noted otherwise!

class orion.algo.space.Categorical(name, categories, **kwargs)[source]

Search space dimension that can take on categorical values.

Parameters
namestr

See Parameters of Dimension.__init__().

categoriesdict or other iterable

A dictionary would associate categories to probabilities, else it assumes to be drawn uniformly from the iterable.

kwargsdict

See Parameters of Dimension.__init__() for general.

Attributes
cardinality

Return the number of all the possible values from Categorical Dimension

get_prior

Return the priors

prior_name

Return the name of the prior

Methods

cast(point)

Cast a point to some category

get_cardinality(shape, categories)

Return the number of all the possible points based and shape and categories

get_prior_string()

Build the string corresponding to current prior

interval([alpha])

Return a tuple of possible values that this categorical dimension can take.

sample([n_samples, seed])

Draw random samples from prior.

property cardinality

Return the number of all the possible values from Categorical Dimension

cast(point)[source]

Cast a point to some category

Casted point will stay a list or a numpy array depending on the given point’s type.

Raises
ValueError

If one of the category in point is not present in current Categorical Dimension.

static get_cardinality(shape, categories)[source]

Return the number of all the possible points based and shape and categories

property get_prior

Return the priors

get_prior_string()[source]

Build the string corresponding to current prior

interval(alpha=1.0)[source]

Return a tuple of possible values that this categorical dimension can take.

property prior_name

Return the name of the prior

sample(n_samples=1, seed=None)[source]

Draw random samples from prior.

See also

Dimension.sample

class orion.algo.space.Dimension(name, prior, *args, **kwargs)[source]

Base class for search space dimensions.

Attributes
namestr

See Dimension attributes.

typestr

See Dimension attributes.

priorscipy.stats.distributions.rv_generic

A distribution over the original dimension.

shapetuple

Return the shape of dimension.

Methods

cast(point)

Cast a point to dimension’s type

get_prior_string()

Build the string corresponding to current prior

get_string()

Build the string corresponding to current dimension

interval([alpha])

Return a tuple containing lower and upper bound for parameters.

sample([n_samples, seed])

Draw random samples from prior.

validate()

Validate dimension arguments

property cardinality

Return the number of all the possible points from Dimension. The default value is numpy.inf.

cast(point)[source]

Cast a point to dimension’s type

If casted point will stay a list or a numpy array depending on the given point’s type.

property default_value

Return the default value for this dimensions

get_prior_string()[source]

Build the string corresponding to current prior

get_string()[source]

Build the string corresponding to current dimension

interval(alpha=1.0)[source]

Return a tuple containing lower and upper bound for parameters.

If parameters are drawn from an ‘open’ supported random variable, then it will be attempted to calculate the interval from which a variable is alpha-likely to be drawn from.

property name

See Dimension attributes.

property prior_name

Return the name of the prior

sample(n_samples=1, seed=None)[source]

Draw random samples from prior.

Parameters
n_samplesint, optional

The number of samples to be drawn. Default is 1 sample.

seedNone | int | numpy.random.RandomState instance, optional

This parameter defines the RandomState object to use for drawing random variates. If None (or np.random), the global np.random state is used. If integer, it is used to seed a RandomState instance just for the call of this function. Default is None.

Set random state to something other than None for reproducible results.

.. warning:: Setting `seed` with an integer will cause the same ndarray

to be sampled if n_samples > 0. Set seed with a numpy.random.RandomState to carry on the changes in random state across many samples.

property shape

Return the shape of dimension.

property type

See Dimension attributes.

validate()[source]

Validate dimension arguments

class orion.algo.space.Fidelity(name, low, high, base=2)[source]

Fidelity Dimension for representing multi-fidelity.

Fidelity dimensions are not optimized by the algorithms. If it supports multi-fidelity, the algorithm will select a fidelity level for which it will sample hyper-parameter values to explore a low fidelity space. This class is used as a place-holder so that algorithms can discern fidelity dimensions from hyper-parameter dimensions.

Parameters
namestr

Name of the dimension

low: int

Mininum of the fidelity interval.

high: int

Maximum of the fidelity interval.

base: int

Base logarithm of the fidelity dimension.

Attributes
namestr

See Dimension attributes.

default_value: int

Maximum of the fidelity interval.

Methods

cast([point])

Do not do anything.

get_cardinality(shape, interval)

Return cardinality of Fidelity dimension, leave it to 1 as Fidelity dimension does not contribute to cardinality in a fixed way now.

get_prior_string()

Build the string corresponding to current prior

interval([alpha])

Do not do anything.

sample([n_samples, seed])

Do not do anything.

validate()

Do not do anything.

property cardinality

Return cardinality of Fidelity dimension, leave it to 1 as Fidelity dimension does not contribute to cardinality in a fixed way now.

cast(point=0)[source]

Do not do anything.

property default_value

Return high

static get_cardinality(shape, interval)[source]

Return cardinality of Fidelity dimension, leave it to 1 as Fidelity dimension does not contribute to cardinality in a fixed way now.

get_prior_string()[source]

Build the string corresponding to current prior

interval(alpha=1.0)[source]

Do not do anything.

sample(n_samples=1, seed=None)[source]

Do not do anything.

validate()[source]

Do not do anything.

class orion.algo.space.Integer(name, prior, *args, **kwargs)[source]

Search space dimension representing integer values.

Parameters
namestr
priorstr

See Parameters of Dimension.__init__().

argslist
kwargsdict

See Parameters of Dimension.__init__() for general.

Attributes
cardinality

Return the number of all the possible points from Integer Dimension

prior_name

Return the name of the prior

Methods

cast(point)

Cast a point to int

get_cardinality(shape, interval)

Return the number of all the possible points based and shape and interval

get_prior_string()

Build the string corresponding to current prior

property cardinality

Return the number of all the possible points from Integer Dimension

cast(point)[source]

Cast a point to int

If casted point will stay a list or a numpy array depending on the given point’s type.

static get_cardinality(shape, interval)[source]

Return the number of all the possible points based and shape and interval

get_prior_string()[source]

Build the string corresponding to current prior

property prior_name

Return the name of the prior

class orion.algo.space.Real(name, prior, *args, **kwargs)[source]

Search space dimension that can take on any real value.

Parameters
namestr
priorstr

See Parameters of Dimension.__init__().

argslist
kwargsdict

See Parameters of Dimension.__init__() for general.

Attributes
cardinality

Return the number of all the possible points from Integer Dimension

Methods

cast(point)

Cast a point to float

get_cardinality(shape, interval)

Return the number of all the possible points based and shape and interval

interval([alpha])

Return a tuple containing lower and upper bound for parameters.

sample([n_samples, seed])

Draw random samples from prior.

property cardinality

Return the number of all the possible points from Integer Dimension

cast(point)[source]

Cast a point to float

If casted point will stay a list or a numpy array depending on the given point’s type.

static get_cardinality(shape, interval)[source]

Return the number of all the possible points based and shape and interval

interval(alpha=1.0)[source]

Return a tuple containing lower and upper bound for parameters.

If parameters are drawn from an ‘open’ supported random variable, then it will be attempted to calculate the interval from which a variable is alpha-likely to be drawn from.

Note

Both lower and upper bounds are inclusive.

sample(n_samples=1, seed=None)[source]

Draw random samples from prior.

See also

Dimension.sample

class orion.algo.space.Space[source]

Represents the search space.

It is a sorted dictionary which contains Dimension objects. The dimensions are sorted based on their names.

Attributes
cardinality

Return the number of all all possible sets of samples in the space

configuration

Return a dictionary of priors.

Methods

contains

alias of orion.algo.space.Dimension

interval([alpha])

Return a list with the intervals for each contained dimension.

items()

Return items sorted according to keys

keys()

Return sorted keys

register(dimension)

Register a new dimension to Space.

sample([n_samples, seed])

Draw random samples from this space.

values()

Return values sorted according to keys

property cardinality

Return the number of all all possible sets of samples in the space

property configuration

Return a dictionary of priors.

contains

alias of orion.algo.space.Dimension

interval(alpha=1.0)[source]

Return a list with the intervals for each contained dimension.

items()[source]

Return items sorted according to keys

keys()[source]

Return sorted keys

register(dimension)[source]

Register a new dimension to Space.

sample(n_samples=1, seed=None)[source]

Draw random samples from this space.

Parameters
n_samplesint, optional

The number of samples to be drawn. Default is 1 sample.

seedNone | int | numpy.random.RandomState instance, optional

This parameter defines the RandomState object to use for drawing random variates. If None (or np.random), the global np.random state is used. If integer, it is used to seed a RandomState instance just for the call of this function. Default is None.

Set random state to something other than None for reproducible results.

Returns
pointslist of tuples of array-likes

Each element is a separate sample of this space, a list containing values associated with the corresponding dimension. Values are in the same order as the contained dimensions. Their shape is determined by dimension.shape.

values()[source]

Return values sorted according to keys

orion.algo.space.check_random_state(seed)[source]

Return numpy global rng or RandomState if seed is specified

orion.algo.space.pack_point(point, space)[source]

Take a list of points and pack it appropriately as a point from space.

This function is deprecated and will be removed in v0.2.0. Use orion.core.utils.points.regroup_dims instead.

orion.algo.space.unpack_point(point, space)[source]

Flatten point in space and convert it to a 1D list.

This function is deprecated and will be removed in v0.2.0. Use orion.core.utils.points.flatten_dims instead.