syne_tune.optimizer.schedulers.searchers.bayesopt.tuning_algorithms.base_classes module
- syne_tune.optimizer.schedulers.searchers.bayesopt.tuning_algorithms.base_classes.assign_active_metric(predictor, active_metric)[source]
Checks that active_metric is provided when predictor consists of multiple output predictors. Otherwise, just sets active_metric to the only predictor output name available.
- class syne_tune.optimizer.schedulers.searchers.bayesopt.tuning_algorithms.base_classes.NextCandidatesAlgorithm[source]
Bases:
object
- class syne_tune.optimizer.schedulers.searchers.bayesopt.tuning_algorithms.base_classes.Predictor(state, active_metric=None)[source]
Bases:
object
Base class for probabilistic predictors used in Bayesian optimization. They support marginal predictions feeding into an acquisition function, as well as computing gradients of an acquisition function w.r.t. inputs.
In general, a predictor is created by an estimator. It wraps a posterior state, which allows for probabilistic predictions on arbitrary inputs.
- Parameters:
state (
TuningJobState
) – Tuning job stateactive_metric (
Optional
[str
]) – Name of internal objective
- keys_predict()[source]
Keys of signals returned by
predict()
.Note: In order to work with
AcquisitionFunction
implementations, the following signals are required:“mean”: Predictive mean
“std”: Predictive standard deviation
- Return type:
Set
[str
]- Returns:
Set of keys for
dict
returned bypredict()
- predict(inputs)[source]
Returns signals which are statistics of the predictive distribution at input points
inputs
. By default:“mean”: Predictive means. If the model supports fantasizing with a number
nf
of fantasies, this has shape(n, nf)
, otherwise(n,)
“std”: Predictive stddevs, shape
(n,)
If the hyperparameters of the surrogate model are being optimized (e.g., by empirical Bayes), the returned list has length 1. If its hyperparameters are averaged over by MCMC, the returned list has one entry per MCMC sample.
- Parameters:
inputs (
ndarray
) – Input points, shape(n, d)
- Return type:
List
[Dict
[str
,ndarray
]]- Returns:
List of
dict
with keyskeys_predict()
, of length the number of MCMC samples, or length 1 for empirical Bayes
- hp_ranges_for_prediction()[source]
- Return type:
- Returns:
Feature generator to be used for
inputs
inpredict()
- predict_candidates(candidates)[source]
Convenience variant of
predict()
- Parameters:
candidates (
Iterable
[Dict
[str
,Union
[int
,float
,str
]]]) – List of configurations- Return type:
List
[Dict
[str
,ndarray
]]- Returns:
Same as
predict()
- current_best()[source]
Returns the so-called incumbent, to be used in acquisition functions such as expected improvement. This is the minimum of predictive means (signal with key “mean”) at all current candidate locations (both state.trials_evaluations and state.pending_evaluations). Normally, a scalar is returned, but if the model supports fantasizing and the state contains pending evaluations, there is one incumbent per fantasy sample, so a vector is returned.
If the hyperparameters of the surrogate model are being optimized (e.g., by empirical Bayes), the returned list has length 1. If its hyperparameters are averaged over by MCMC, the returned list has one entry per MCMC sample.
- Return type:
List
[ndarray
]- Returns:
Incumbent, see above
- backward_gradient(input, head_gradients)[source]
Computes the gradient \(\nabla_x f(x)\) for an acquisition function \(f(x)\), where \(x\) is a single input point. This is using reverse mode differentiation, the head gradients are passed by the acquisition function. The head gradients are \(\partial_k f\), where \(k\) runs over the statistics returned by
predict()
for the single input point \(x\). The shape of head gradients is the same as the shape of the statistics.Lists have
> 1
entry if MCMC is used, otherwise they are all size 1.- Parameters:
input (
ndarray
) – Single input point \(x\), shape(d,)
head_gradients (
List
[Dict
[str
,ndarray
]]) – See above
- Return type:
List
[ndarray
]- Returns:
Gradient \(\nabla_x f(x)\) (several if MCMC is used)
- class syne_tune.optimizer.schedulers.searchers.bayesopt.tuning_algorithms.base_classes.ScoringFunction(predictor=None, active_metric=None)[source]
Bases:
object
Class to score candidates. As opposed to acquisition functions, scores do not support gradient computation. Note that scores are always minimized.
- class syne_tune.optimizer.schedulers.searchers.bayesopt.tuning_algorithms.base_classes.AcquisitionFunction(predictor=None, active_metric=None)[source]
Bases:
ScoringFunction
Base class for acquisition functions \(f(x)\).
- Parameters:
- compute_acq(inputs, predictor=None)[source]
Note: If inputs has shape
(d,)
, it is taken to be(1, d)
- compute_acq_with_gradient(input, predictor=None)[source]
For a single input point \(x\), compute acquisition function value \(f(x)\) and gradient \(\nabla_x f(x)\).
- class syne_tune.optimizer.schedulers.searchers.bayesopt.tuning_algorithms.base_classes.LocalOptimizer(hp_ranges, predictor, acquisition_class, active_metric=None)[source]
Bases:
object
Class that tries to find a local candidate with a better score, typically using a local optimization method such as L-BFGS. It would normally encapsulate an acquisition function and predictor.
acquisition_class
contains the type of the acquisition function (subclass ofAcquisitionFunction
). It can also be a tuple of the form(type, kwargs)
, wherekwargs
are extra arguments to the class constructor.- Parameters:
hp_ranges (
HyperparameterRanges
) – Feature generator for configurationspredictor (
Union
[Predictor
,Dict
[str
,Predictor
]]) – Predictor(s) for acquisition functionacquisition_class (
Callable
[[Any
],AcquisitionFunction
]) – See aboveactive_metric (
Optional
[str
]) – Name of internal metric
- class syne_tune.optimizer.schedulers.searchers.bayesopt.tuning_algorithms.base_classes.CandidateGenerator[source]
Bases:
object
Class to generate candidates from which to start the local minimization, typically random candidate or some form of more uniformly spaced variation, such as latin hypercube or Sobol sequence.
- generate_candidates_en_bulk(num_cands, exclusion_list=None)[source]
- Parameters:
num_cands (
int
) – Number of candidates to generateexclusion_list (
Optional
[ExclusionList
]) – If given, these candidates must not be returned
- Return type:
List
[Dict
[str
,Union
[int
,float
,str
]]]- Returns:
List of
num_cands
candidates. Ifexclusion_list
is given, the number of candidates returned can be< num_cands