TPE Algorithm

Tree-structured Parzen Estimator Approach

class orion.algo.tpe.CategoricalSampler(tpe, observations, choices)[source]

Categorical Sampler for discrete integer and categorical choices

Parameters
tpe: `TPE` algorithm

The tpe algorithm object which this sampler will be part of.

observations: list

Observed values in the dimension

choices: list

Candidate values for the dimension

Methods

get_loglikelis(points)

Return the log likelihood for the points

sample([num])

Sample required number of points

get_loglikelis(points)[source]

Return the log likelihood for the points

sample(num=1)[source]

Sample required number of points

class orion.algo.tpe.GMMSampler(tpe, mus, sigmas, low, high, weights=None, base_attempts=10, attempts_factor=10, max_attempts=10000)[source]

Gaussian Mixture Model Sampler for TPE algorithm

Parameters
tpe: `TPE` algorithm

The tpe algorithm object which this sampler will be part of.

mus: list

mus for each Gaussian components in the GMM. Default: None

sigmas: list

sigmas for each Gaussian components in the GMM.

low: real

Lower bound of the sampled points.

high: real

Upper bound of the sampled points.

weights: list

Weights for each Gaussian components in the GMM Default: None

base_attempts: int, optional

Base number of attempts to sample points within low and high bounds. Defaults to 10.

attempts_factor: int, optional

If sampling always falls out of bound try again with attempts * attempts_factor. Defaults to 10.

max_attempts: int, optional

If sampling always falls out of bound try again with attempts * attempts_factor up to max_attempts (inclusive). Defaults to 10000.

Methods

get_loglikelis(points)

Return the log likelihood for the points

sample([num, attempts])

Sample required number of points

get_loglikelis(points)[source]

Return the log likelihood for the points

sample(num=1, attempts=None)[source]

Sample required number of points

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, max_retry=100)[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, optional

Seed to sample initial points and candidates points. Default: None

n_initial_points: int, optional

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, optional

Number of candidates points sampled for ei compute. Larger numbers will lead to more exploitation and lower numbers will lead to more exploration. Be carefull with categorical dimension as TPE tend to severily exploit these if n_ei_candidates is larger than 1. Default: 24

gamma: real, optional

Ratio to split the observed trials into good and bad distributions. Lower numbers will load to more exploitation and larger numbers will lead to more exploration. Default: 0.25

equal_weight: bool, optional

True to set equal weights for observed points. Default: False

prior_weight: int, optional

The weight given to the prior point of the input space. Default: 1.0

full_weight_num: int, optional

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.

max_retry: int, optional

Number of attempts to sample new points if the sampled points were already suggested. Default: 100

Attributes
requires_type
space

Return transformed space of TPE

state_dict

Return a state dict that can be used to reset the state of the algorithm.

Methods

observe(points, results)

Observe evaluation results corresponding to list of points in space.

sample_one_dimension(dimension, shape_size, ...)

Sample values for a dimension

seed_rng(seed)

Seed the state of the random number generator.

set_state(state_dict)

Reset the state of the algorithm based on the given state_dict

split_trials()

Split the observed trials into good and bad ones based on the ratio gamma`

suggest([num])

Suggest a num of new sets of parameters.

observe(points, results)[source]

Observe evaluation results corresponding to list of points in space.

A simple random sampler though does not take anything into account.

sample_one_dimension(dimension, shape_size, below_points, above_points, sampler)[source]

Sample values for a dimension

Parameters
  • dimension – Dimension.

  • shape_size – 1D Shape Size of the Real Dimension.

  • below_points – good points with shape (m, n), m=shape_size.

  • above_points – bad points with shape (m, n), m=shape_size.

  • sampler – method to sample one value for upon the dimension.

seed_rng(seed)[source]

Seed the state of the random number generator.

Parameters

seed – Integer seed for the random number generator.

set_state(state_dict)[source]

Reset the state of the algorithm based on the given state_dict

Parameters

state_dict – Dictionary representing state of an algorithm

property space

Return transformed space of TPE

split_trials()[source]

Split the observed trials into good and bad ones based on the ratio gamma`

property state_dict

Return a state dict that can be used to reset the state of the algorithm.

suggest(num=None)[source]

Suggest a num of new sets of parameters. Randomly draw samples from the import space and return them.

Parameters
num: int, optional

Number of points to sample. If None, TPE will sample all random points at once, or a single point if it is at the Bayesian Optimization stage.

:param num: how many sets to be suggested.
.. note:: New parameters must be compliant with the problem’s domain

orion.algo.space.Space.

orion.algo.tpe.adaptive_parzen_estimator(mus, low, high, prior_weight=1.0, equal_weight=False, flat_num=25)[source]

Return the sorted mus, the corresponding sigmas and weights with adaptive kernel estimator.

This adaptive parzen window estimator is based on the original papers and also refer the use of prior mean in this implementation.

Parameters
  • mus – list of real values for observed mus.

  • low – real value for lower bound of points.

  • high – real value for upper bound of points.

  • prior_weight – real value for the weight of the prior mean.

  • equal_weight – bool value indicating if all points with equal weights.

  • flat_num – int value indicating 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.

orion.algo.tpe.compute_max_ei_point(points, below_likelis, above_likelis)[source]

Compute ei among points based on their log likelihood and return the point with max ei.

Parameters
  • points – list of point with real values.

  • below_likelis – list of log likelihood for each point in the good GMM.

  • above_likelis – list of log likelihood for each point in the bad GMM.

orion.algo.tpe.ramp_up_weights(total_num, flat_num, equal_weight)[source]

Adjust weights of observed trials.

Parameters
  • total_num – total number of observed trials.

  • flat_num – 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.

  • equal_weight – whether all the observed trails share the same weights.