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
test distributions 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: - name : str
See Parameters of Dimension.__init__().
- categories : dict or other iterable
A dictionary would associate categories to probabilities, else it assumes to be drawn uniformly from the iterable.
- kwargs : dict
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. -
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
-
get_prior
¶ Return the priors
-
interval
(alpha=1.0)[source]¶ Return a tuple of possible values that this categorical dimension can take.
-
prior_name
¶ Return the name of the prior
-
class
orion.algo.space.
Dimension
(name, prior, *args, **kwargs)[source]¶ Base class for search space dimensions.
Attributes: 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 -
cardinality
¶ Return the number of all the possible points from
Dimension
. The default value isnumpy.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.
-
default_value
¶ Return the default value for this dimensions
-
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.
-
prior_name
¶ Return the name of the prior
-
sample
(n_samples=1, seed=None)[source]¶ Draw random samples from prior.
Parameters: - n_samples : int, optional
The number of samples to be drawn. Default is 1 sample.
- seed : None | 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 anumpy.random.RandomState
to carry on the changes in random state across many samples.
-
shape
¶ Return the shape of dimension.
-
-
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: - name : str
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: name
: strSee
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. -
cardinality
¶ Return cardinality of Fidelity dimension, leave it to 1 as Fidelity dimension does not contribute to cardinality in a fixed way now.
-
default_value
¶ Return high
-
class
orion.algo.space.
Integer
(name, prior, *args, **kwargs)[source]¶ Search space dimension representing integer values.
Parameters: - name : str
- prior : str
See Parameters of Dimension.__init__().
- args : list
- kwargs : dict
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 -
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
-
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: - name : str
- prior : str
See Parameters of Dimension.__init__().
- args : list
- kwargs : dict
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. -
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.
-
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 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 -
cardinality
¶ Return the number of all all possible sets of samples in the space
-
configuration
¶ Return a dictionary of priors.
-
sample
(n_samples=1, seed=None)[source]¶ Draw random samples from this space.
Parameters: - n_samples : int, optional
The number of samples to be drawn. Default is 1 sample.
- seed : None | 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: - points : list 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
.
-
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.