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]¶ 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: - NO_DEFAULT_VALUE
cardinality
Return the number of all the possible values from Categorical
Dimension
default_value
Return the default value for this dimensions
get_prior
Return the priors
name
See
Dimension
attributes.prior_name
Return the name of the prior
shape
Return the shape of dimension.
type
See
Dimension
attributes.
Methods
cast
(point)Cast a point to some category get_cardinality
(categories)Return the number of all the possible points based and shape and categories get_prior_string
()Build the string corresponding to current prior get_string
()Build the string corresponding to current dimension interval
([alpha])Return a tuple of possible values that this categorical dimension can take. sample
([n_samples, seed])Draw random samples from prior. validate
()Validate dimension arguments -
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
(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
(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 get_string
()Build the string corresponding to current dimension 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: - NO_DEFAULT_VALUE
cardinality
Return the number of all the possible points from Integer
Dimension
default_value
Return the default value for this dimensions
name
See
Dimension
attributes.prior_name
Return the name of the prior
shape
Return the shape of dimension.
type
See
Dimension
attributes.
Methods
cast
(point)Cast a point to int get_cardinality
(interval)Return the number of all the possible points based and shape and interval 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 -
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
(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: - NO_DEFAULT_VALUE
cardinality
Return the number of all the possible points from Integer
Dimension
default_value
Return the default value for this dimensions
name
See
Dimension
attributes.prior_name
Return the name of the prior
shape
Return the shape of dimension.
type
See
Dimension
attributes.
Methods
cast
(point)Cast a point to float get_cardinality
(interval)Return the number of all the possible points based and shape and interval 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 -
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
(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
clear
()contains
alias of Dimension
copy
()fromkeys
(iterable[, value])Create a new dictionary with keys from iterable and values set to value. get
(key[, default])Return the value for key if key is in the dictionary, else default. interval
([alpha])Return a list with the intervals for each contained dimension. items
()Return items sorted according to keys keys
()Return sorted keys pop
(k[,d])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
(dimension)Register a new dimension to Space
.sample
([n_samples, seed])Draw random samples from this space. setdefault
(key[, default])Insert key with a value of default if key is not in the dictionary. update
([E, ]**F)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
()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