Algorithms¶
Default algorithm is a random search based on the probability distribution given to a search parameter’s definition.
Selecting and Configuring¶
In a Oríon configuration YAML, define:
experiment:
algorithms:
gradient_descent:
learning_rate: 0.1
In this particular example, the name of the algorithm extension class to be
imported and instantiated is Gradient_Descent
, so the lower-case identifier
corresponds to it.
All algorithms have default arguments that should work reasonably well in general.
To tune the algorithm for a specific problem, you can set those arguments in the
yaml file as shown above with learning_rate
.
Included Algorithms¶
Random Search¶
Random search is the most simple algorithm. It samples from given priors. That’s it.
Configuration¶
experiment:
algorithms:
random:
seed: null
- class orion.algo.random.Random(space, seed=None)[source]
An algorithm that samples randomly from the problem’s space.
- Parameters
- space: `orion.algo.space.Space`
Optimisation space with priors for each dimension.
- seed: None, int or sequence of int
Seed for the random number generator used to sample new trials. Default:
None
Grid Search¶
Grid search is one of the simplest algorithm. It can work reasonably well for small search spaces of one or two dimensions but should be avoided for larger search spaces. The search space can be configured in three different ways.
Default for the lazy. You can set a very large
n_values
(ex: 100) and the grid will be adjusted so that it results in less thanmax_trials
as defined in the experiment configuration.You can set
n_values
to the number of points desired by dimension. Note that if this leads to too many trials the grid will be shrunken down to fit belowmax_trials
.You can pass a dictionary to
n_values
specifying the number of points for each dimensions. Ex:n_values: {'dim1': 3, 'dim2': 4}
.
Note
For categorical dimensions (choices()
) all values are used to build the grid. This means
n_values
will not be honored. A warning is printed when this happens. Accordingly,
if too many options are provided for the categorical dimensions the grid may lead to more trials
than max_trials
. A ValueError
will be raised in such scenario.
Configuration¶
experiment:
algorithms:
gridsearch:
n_values: 100
- class orion.algo.gridsearch.GridSearch(space, n_values=100, seed=None)[source]
Grid Search algorithm
- Parameters
- n_values: int or dict
Number of points for each dimensions, or dictionary specifying number of points for each dimension independently (name, n_values). For categorical dimensions, n_values will not be used, and all categories will be used to build the grid.
Hyperband¶
Hyperband extends the SuccessiveHalving algorithm by providing a way to exploit a
fixed budget with different number of configurations for SuccessiveHalving
algorithm to
evaluate. Each run of SuccessiveHalving
will be defined as a bracket
in Hyperband.
Hyperband requires two inputs (1) R
, the maximum amount of resource that can be allocated
to a single configuration, and (2) eta
, an input that controls the proportion of
configurations discarded in each round of SuccessiveHalving.
To use Hyperband in Oríon, you must specify one parameter with fidelity(low, high, base)
as the prior, low
will be ignored, high
will be taken as the maximum resource R
and base
will be taken as the reduction factor eta
.
Number of epochs usually can be used as the resource but the algorithm is generic and can be
applied to any multi-fidelity setting. That is, you can use training time, specifying the
fidelity with --epochs~fidelity(low=1, high=81, base=3)
(assuming your script takes this argument in commandline),
but you could also use other fidelity
such as dataset size --dataset-size~fidelity(low=500, high=50000)
(assuming your script takes this argument and adapt dataset size accordingly).
Note
Current implementation does not support more than one fidelity dimension.
Configuration¶
experiment:
algorithms:
hyperband:
seed: null
repetitions: 1
strategy: StubParallelStrategy
Note
Notice the additional strategy
in configuration which is not mandatory for most other
algorithms. See StubParallelStrategy for more information.
- class orion.algo.hyperband.Hyperband(space, seed=None, repetitions=inf)[source]
Hyperband formulates hyperparameter optimization as a pure-exploration non-stochastic infinite-armed bandit problem where a predefined resource like iterations, data samples, or features is allocated to randomly sampled configurations.`
For more information on the algorithm, see original paper at http://jmlr.org/papers/v18/16-558.html.
Li, Lisha et al. “Hyperband: A Novel Bandit-Based Approach to Hyperparameter Optimization” Journal of Machine Learning Research, 18:1-52, 2018.
- Parameters
- space: `orion.algo.space.Space`
Optimisation space with priors for each dimension.
- seed: None, int or sequence of int
Seed for the random number generator used to sample new trials. Default:
None
- repetitions: int
Number of executions for Hyperband. A single execution of Hyperband takes a finite budget of
(log(R)/log(eta) + 1) * (log(R)/log(eta) + 1) * R
, andrepetitions
allows you to run multiple executions of Hyperband. Default isnumpy.inf
which means to run Hyperband until no new trials can be suggested.
ASHA¶
Asynchronous Successive Halving Algorithm, the asynchronous version of Hyperband, can be roughly interpreted as a sophisticated random search that leverages partial information of the trial execution to concentrate resources on the most promising ones.
The main idea of the algorithm is the following. Given a fidelity dimension, such as the number of epochs to train or the size of the dataset, ASHA samples trials with low-fidelity and promotes the most promising ones to the next fidelity level. This makes it possible to only execute one trial with full fidelity, leading to very optimal resource usage.
The most common way of using ASHA is to reduce the number of epochs,
but the algorithm is generic and can be applied to any multi-fidelity setting.
That is, you can use training time, specifying the fidelity with
--epochs~fidelity(low=1, high=100)
(assuming your script takes this argument in commandline),
but you could also use other fidelity
such as dataset size --dataset-size~fidelity(low=500, high=50000)
(assuming your script takes this argument and
adapt dataset size accordingly). The placeholder fidelity(low, high)
is a special prior for
multi-fidelity algorithms.
Note
Current implementation does not support more than one fidelity dimension.
Configuration¶
experiment:
algorithms:
asha:
seed: null
num_rungs: null
num_brackets: 1
repetitions: 1
strategy: StubParallelStrategy
Note
Notice the additional strategy
in configuration which is not mandatory for most other
algorithms. See StubParallelStrategy for more information.
- class orion.algo.asha.ASHA(space, seed=None, num_rungs=None, num_brackets=1, repetitions=inf)[source]
Asynchronous Successive Halving Algorithm
A simple and robust hyperparameter tuning algorithm with solid theoretical underpinnings that exploits parallelism and aggressive early-stopping.
For more information on the algorithm, see original paper at https://arxiv.org/abs/1810.05934.
Li, Liam, et al. “Massively parallel hyperparameter tuning.” arXiv preprint arXiv:1810.05934 (2018)
- Parameters
- space: `orion.algo.space.Space`
Optimisation space with priors for each dimension.
- seed: None, int or sequence of int
Seed for the random number generator used to sample new trials. Default:
None
- num_rungs: int, optional
Number of rungs for the largest bracket. If not defined, it will be equal to
(base + 1)
of the fidelity dimension. In the original paper,num_rungs == log(fidelity.high/fidelity.low) / log(fidelity.base) + 1
. Default:log(fidelity.high/fidelity.low) / log(fidelity.base) + 1
- num_brackets: int
Using a grace period that is too small may bias ASHA too strongly towards fast converging trials that do not lead to best results at convergence (stagglers). To overcome this, you can increase the number of brackets, which increases the amount of resource required for optimisation but decreases the bias towards stragglers. Default: 1
- repetitions: int
Number of execution of ASHA. Default is numpy.inf which means to run ASHA until no new trials can be suggested.
TPE¶
Tree-structured Parzen Estimator (TPE) algorithm is one of Sequential Model-Based Global Optimization (SMBO) algorithms, which will build models to propose new points based on the historical observed trials.
Instead of modeling p(y|x) like other SMBO algorithms, TPE models p(x|y) and p(y), and p(x|y) is modeled by transforming that generative process, replacing the distributions of the configuration prior with non-parametric densities.
The TPE defines p(x|y) using two such densities l(x) and g(x) where l(x) is distribution of good points and g(x) is the distribution of bad points. Good and bad points are split from observed points so far with a parameter gamma which defines the ratio of good points. New point candidates will be sampled with l(x) and Expected Improvement (EI) optimization scheme will be used to find the most promising point among the candidates.
Note
Current implementation only supports uniform, loguniform, uniform discrete and choices as prior. As for choices prior, the probabilities if any given will be ignored.
Configuration¶
experiment:
algorithms:
tpe:
seed: null
n_initial_points: 20
n_ei_candidates: 25
gamma: 0.25
equal_weight: False
prior_weight: 1.0
full_weight_num: 25
- class orion.algo.tpe.TPE(space, seed=None, n_initial_points=20, n_ei_candidates=24, gamma=0.25, equal_weight=False, prior_weight=1.0, full_weight_num=25)[source]
Tree-structured Parzen Estimator (TPE) algorithm is one of Sequential Model-Based Global Optimization (SMBO) algorithms, which will build models to propose new points based on the historical observed trials.
Instead of modeling p(y|x) like other SMBO algorithms, TPE models p(x|y) and p(y), and p(x|y) is modeled by transforming that generative process, replacing the distributions of the configuration prior with non-parametric densities.
The TPE defines p(x|y) using two such densities l(x) and g(x) while l(x) is distribution of good points and g(x) is the distribution of bad points. New point candidates will be sampled with l(x) and Expected Improvement (EI) optimization scheme will be used to find the most promising point among the candidates.
For more information on the algorithm, see original papers at:
- Parameters
- space: `orion.algo.space.Space`
Optimisation space with priors for each dimension.
- seed: None, int or sequence of int
Seed to sample initial points and candidates points. Default:
None
- n_initial_points: int
Number of initial points randomly sampled. If new points are requested and less than n_initial_points are observed, the next points will also be sampled randomly instead of being sampled from the parzen estimators. Default:
20
- n_ei_candidates: int
Number of candidates points sampled for ei compute. Default:
24
- gamma: real
Ratio to split the observed trials into good and bad distributions. Default:
0.25
- equal_weight: bool
True to set equal weights for observed points. Default:
False
- prior_weight: int
The weight given to the prior point of the input space. Default:
1.0
- full_weight_num: int
The number of the most recent trials which get the full weight where the others will be applied with a linear ramp from 0 to 1.0. It will only take effect if equal_weight is False.
Evolution-ES¶
Evolution-ES, the evolution algorithm with early stop version. Here is an implementation of Evolution-ES. In the evolution algorithm, we follow the tournament selection algorithm as Large-Scale-Evolution. Tournament selection evolutionary hyper-parameter search is conducted by first defining a gene encoding that describes a hyper-parameter combination, and then creating the initial population by randomly sampling from the space of gene encodings to create individuals, which are trained and assigned fitnesses. The population is then repeatedly sampled from to produce groups, and the parent is selected by the individual with the highest fitness. Selected parents have their gene encodings mutated to produce child models. Individual in the group with the lowest fitness is killed, while the newly evaluated child model is added to the population, taking the killed individual’s place. This process is repeated and results in a population with high fitness individuals can represent the good hyper-parameter combination. Evolution-ES also formulated a method to dynamically allocate resources to more promising individual according to their fitness, which is referred to as Progressive Dynamic Hurdles (PDH), allows individuals that are consistently performing well to train for more steps. It can be roughly interpreted as a sophisticated random search that leverages partial information of the trial execution to concentrate resources on the most promising ones.
The implementation follows the process and use way of Hyperband.
Additionally, The fidelity base in Evolution-ES can be
extended to support fidelity(low, high, base=1)
,
which is the same as linspace(low, high)
.
Configuration¶
experiment:
algorithms:
EvolutionES:
seed: null
repetitions: 1
nums_population: 20
mutate:
function: orion.algo.mutate_functions.default_mutate
multiply_factor: 3.0
add_factor: 1
strategy: StubParallelStrategy
- class orion.algo.evolution_es.EvolutionES(space, seed=None, repetitions=inf, nums_population=20, mutate=None, max_retries=1000)[source]
EvolutionES formulates hyperparameter optimization as an evolution.
For more information on the algorithm, see original paper at https://arxiv.org/pdf/1703.01041.pdf and https://arxiv.org/pdf/1901.11117.pdf
Real et al. “Large-Scale Evolution of Image Classifiers” So et all. “The Evolved Transformer”
- Parameters
- space: `orion.algo.space.Space`
Optimisation space with priors for each dimension.
- seed: None, int or sequence of int
Seed for the random number generator used to sample new trials. Default:
None
- repetitions: int
Number of execution of Hyperband. Default is numpy.inf which means to run Hyperband until no new trials can be suggested.
- nums_population: int
Number of population for EvolutionES. Larger number of population often gets better performance but causes more computation. So there is a trade-off according to the search space and required budget of your problems. Default: 20
- mutate: str or None, optional
In the mutate part, one can define the customized mutate function with its mutate factors, such as multiply factor (times/divides by a multiply factor) and add factor (add/subtract by a multiply factor). The function must be defined by an importable string. If None, default mutate function is used:
orion.algo.mutate_functions.default_mutate
.
Algorithm Plugins¶
Plugins documentation is hosted separately. See short documentations below to find links to full plugins documentation.
Scikit-Optimize¶
This package is a plugin providing a wrapper for skopt optimizers.
For more information, you can find the documentation at orionalgoskopt.readthedocs.io.
Robust Bayesian Optimization¶
This package is a plugin providing a wrapper for RoBO optimizers.
You will find in this plugin many models for Bayesian Optimization: Gaussian Process, Gaussian Process with MCMC, Random Forest, DNGO and BOHAMIANN.
For more information, you can find the documentation at epistimio.github.io/orion.algo.robo.
Parallel Strategies¶
A parallel strategy is a method to improve parallel optimization for sequential algorithms. Such algorithms can only observe trials that are completed and have a corresponding objective. To get around this, parallel strategies produces lies, noncompleted trials with fake objectives, which are then passed to a temporary copy of the algorithm that will suggest a new point. The temporary algorithm is then discarded. The original algorithm never obverses lies, and the temporary copy always observes lies that are based on most up-to-date data. The strategies will differ in how they assign objectives to the lies.
By default, the strategy used is MaxParallelStrategy
NoParallelStrategy¶
Does not return any lie. This is useful to benchmark parallel strategies and measure how they can help compared to no strategy.
StubParallelStrategy¶
Assign to lies an objective of None
so that
non-completed trials are observed and identifiable by algorithms
that can leverage parallel optimization.
The value of the objective is customizable with stub_value
.
experiment:
strategy:
StubParallelStrategy:
stub_value: 'custom value'
MaxParallelStrategy¶
Assigns to lies the best objective observed so far.
The default value assigned to objective when less than 1 trial
is completed is configurable with default_result
. It
is float('inf')
by default.
experiment:
strategy:
MaxParallelStrategy:
default_result: 10000
MeanParallelStrategy¶
Assigns to lies the mean of all objectives observed so far.
The default value assigned to objective when less than 2 trials
are completed is configurable with default_result
. It
is float('inf')
by default.
experiment:
strategy:
MeanParallelStrategy:
default_result: 0.5