Model-guided sampling over one candidate's search space.
Where search_space decides what may be searched, this module decides where to look next inside that space. It is the piece that turns AutoML's inner loop from uniform random sampling into Bayesian optimization, and it does so with TuiML's own surrogate machinery: GaussianProcess and AcquisitionFunction are used directly, rather than a second implementation being written here.
Those two classes are deliberately independent of BayesianSearchCV, which is what makes the reuse possible: BayesianSearchCV owns its own cross-validation loop and refits, whereas AutoML must keep control of evaluation so that every trial shares one set of splits and contributes its fitted model to the ensemble pool. Borrowing the surrogate without the estimator gets both.
Overview
-
ParameterEncodermaps a parameter dict to a fixed-length numeric
-
SurrogateSamplerrecords every(params, score)observed, fits
- Until a few observations exist there is nothing to condition on, so the
Notes
'linear' is nearer 'poly' than 'rbf', which is not true of an unordered set.Classes
Encode parameter dicts as fixed-length numeric vectors for a GP.
__init__( self, param_distributions: Dict[str, Any], )
Parameters
param_distributions
ParameterDistribution: each value is a list of choices, or a (low, high) / (low, high, 'log') / (low, high, 'int') range tuple.
Attributes
columns_
(name, kind, payload) entry per encoded column group, in encoding order. kind is "numeric" or "choice".
n_features_
>>> from tuiml.automl.surrogate import ParameterEncoder
>>> encoder = ParameterEncoder({'C': (0.01, 100.0, 'log'),
... 'kernel': ['linear', 'rbf']})
>>> encoder.n_features_
3
>>> encoder.encode({'C': 1.0, 'kernel': 'rbf'}).round(3).tolist()
[0.5, 0.0, 1.0]
Methods
encode
(self, params: Dict[str, Any]) -> np.ndarray
encode
(self, params: Dict[str, Any]) -> np.ndarray
Encode one parameter dict as a numeric vector.
Parameters
params
Returns
vector
Suggest the next configuration for one candidate, GP-guided.
MIN_OBSERVATIONS suggestions are plain random draws, so early behaviour is identical to random search and the surrogate only takes over once it has something to learn from.__init__( self, space: ParameterDistribution, acquisition: str = 'ei', n_candidates: int = N_ACQUISITION_CANDIDATES, )
Parameters
space
search_space_for.
acquisition
AcquisitionFunction: 'ei', 'pi' or 'ucb'.
n_candidates
Attributes
observations_
(params, score) pairs recorded so far.
n_guided_
>>> from tuiml.automl.search_space import search_space_for
>>> from tuiml.automl.surrogate import SurrogateSampler
>>> from tuiml.registry import registry
>>> import numpy as np
>>> sampler = SurrogateSampler(search_space_for(registry.get('SVC')))
>>> rng = np.random.RandomState(0)
>>> params = sampler.suggest(rng)
>>> sorted(params)
['C', 'degree', 'kernel', 'tol']
>>> sampler.observe(params, 0.9)
>>> len(sampler.observations_)
1
Methods
observe
(self, params: Dict[str, Any], score: Optional[float]) -> None
observe
(self, params: Dict[str, Any], score: Optional[float]) -> None
Record the score a configuration achieved.
Parameters
params
score
None (a failed trial) is ignored rather than treated as a bad score, since a crash says nothing about where the optimum lies.
suggest
(self, rng: np.random.RandomState) -> Dict[str, Any]
suggest
(self, rng: np.random.RandomState) -> Dict[str, Any]
Propose the next configuration to evaluate.
Parameters
rng
Returns
params