Space search¶
orion.algo.space
– Objects describing a problem’s domain¶
There are 3 classes representing possible parameter types. All of them subclass the base class Dimension:
- Real
- Integer
- Categorical
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.stats.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]¶ Subclass of
Dimension
for representing categorical parameters.Attributes: Methods
cast
(self, point)Cast a point to some category get_prior_string
(self)Build the string corresponding to current prior get_string
(self)Build the string corresponding to current dimension interval
(self[, alpha])Return a tuple of possible values that this categorical dimension can take. sample
(self[, n_samples, seed])Draw random samples from prior. validate
(self)Validate dimension arguments -
cast
(self, 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.
-
interval
(self, alpha=1.0)[source]¶ Return a tuple of possible values that this categorical dimension can take.
Warning
This method makes no sense for categorical variables. Use
self.categories
instead.
-
-
class
orion.algo.space.
Dimension
(name, prior, *args, **kwargs)[source]¶ Base class for search space dimensions.
Attributes: Methods
cast
(self, point)Cast a point to dimension’s type get_prior_string
(self)Build the string corresponding to current prior get_string
(self)Build the string corresponding to current dimension interval
(self[, alpha])Return a tuple containing lower and upper bound for parameters. sample
(self[, n_samples, seed])Draw random samples from prior. validate
(self)Validate dimension arguments -
cast
(self, 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
(self, 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
Lower bound is inclusive, upper bound is exclusive.
-
sample
(self, 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
(self[, point])Do not do anything. get_prior_string
(self)Build the string corresponding to current prior get_string
(self)Build the string corresponding to current dimension interval
(self[, alpha])Do not do anything. sample
(self[, n_samples, seed])Do not do anything. validate
(self)Do not do anything. -
default_value
¶ Return high
-
class
orion.algo.space.
Integer
(name, prior, *args, **kwargs)[source]¶ Subclass of
Dimension
for representing integer parameters.Attributes: Methods
cast
(self, point)Cast a point to int get_prior_string
(self)Build the string corresponding to current prior get_string
(self)Build the string corresponding to current dimension interval
(self[, alpha])Return a tuple containing lower and upper bound for parameters. sample
(self[, n_samples, seed])Draw random samples from prior. validate
(self)Validate dimension arguments
-
class
orion.algo.space.
Real
(name, prior, *args, **kwargs)[source]¶ Subclass of
Dimension
for representing real parameters.Attributes: name
: strSee
Dimension
attributes.type
: strSee
Dimension
attributes.- prior : scipy.stats.distributions.rv_generic
shape
: tupleReturn the shape of dimension.
- low : float
Constrain with a lower bound (inclusive), default
-numpy.inf
.- high : float
Constrain with an upper bound (exclusive), default
numpy.inf
.
Methods
cast
(self, point)Cast a point to float get_prior_string
(self)Build the string corresponding to current prior get_string
(self)Build the string corresponding to current dimension interval
(self[, alpha])Return a tuple containing lower and upper bound for parameters. sample
(self[, n_samples, seed])Draw random samples from prior. validate
(self)Validate dimension arguments -
cast
(self, 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.
-
interval
(self, 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
Lower bound is inclusive, upper bound is exclusive.
-
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.Methods
clear
()contains
alias of Dimension
copy
()fromkeys
(iterable[, value])Create a new dictionary with keys from iterable and values set to value. get
(self, key[, default])Return the value for key if key is in the dictionary, else default. interval
(self[, alpha])Return a list with the intervals for each contained dimension. items
(self)Return items sorted according to keys keys
(self)Return sorted keys pop
()If key is not found, d is returned if given, otherwise KeyError is raised popitem
()2-tuple; but raise KeyError if D is empty. register
(self, dimension)Register a new dimension to Space
.sample
(self[, n_samples, seed])Draw random samples from this space. setdefault
(self, key[, default])Insert key with a value of default if key is not in the dictionary. update
()If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k] values
(self)Return values sorted according to keys -
interval
(self, alpha=1.0)[source]¶ Return a list with the intervals for each contained dimension.
Note
Lower bound is inclusive, upper bound is exclusive.
-
sample
(self, 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