Active Learning Sampler
ActiveLearningSampler
ActiveLearningSampler(
bounds,
budget,
parameters,
query_strategy,
n_candidates,
**kwargs,
)
Bases: Sampler
Overview
ActiveLearningSampler provides an active-learning driven sampler that proposes parameter configurations for evaluation using a surrogate regressor and a pool-based query strategy.
[!Note] This sampler requires the
activelearningoptional dependency to function. See installation guide for more details.
Purpose
- Maintain a pool of candidate parameter vectors and an internal dataset of observed (parameter, objective) pairs.
- During a warmup period or when no observations exist, produce random samples within provided bounds.
- After warmup, fit a surrogate regression model to observations and use a specified pool-based query strategy to select the most informative candidates to evaluate next.
Key behavior
- Samples continuous parameter spaces; each parameter has an independent [low, high] bound.
- Produces samples in batches (controlled by batch_size).
- Tracks how many samples have been generated via self.submitted and stops at self.budget if enforced externally.
- Uses a surrogate regressor (default:
NICKernelRegressorwrapped inBaggingRegressorandSklearnRegressor) to estimate objective values and uncertainties. - Uses a pool-based query strategy (loaded dynamically from a module) to select candidates from the current candidate pool.
Configuration / Inputs
- bounds (list of (low, high) tuples): per-parameter sampling ranges.
- budget (int): total number of samples allowed.
- parameters (list of str): names of parameters; order must match bounds.
- query_strategy (str): import path or name used by
cached_import_externalto load a pool query strategy fromskactiveml.pool. - Optional kwargs:
- batch_size (int): number of samples returned per call (defaults to budget).
Outputs
get_next_samples()returns a list of dicts mapping parameter names to sampled values for the next batch.register_future(future)accepts either(params_dict, y)or{"params": params_dict, "y": y}and appends the observation to the internal dataset.
Implementation notes
- Candidates are sampled once at initialization from uniform distributions over bounds; batch selection is done from this pool.
- Warmup behavior: while
self.submitted < self.warmupor no observations exist,get_next_samples()returns random fallback samples. - The surrogate model and query strategy are dynamically instantiated; these should be made configurable (for example via external config) if different regressors or ensemble parameters are required.
Initializes the ActiveLearningSampler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
list[tuple[float, float]]
|
Lower and upper bounds for each parameter. |
required |
budget
|
int
|
Total number of samples that can be generated. |
required |
parameters
|
list[str]
|
Names of the parameters to be sampled. The order must correspond to the order of bounds. |
required |
query_strategy
|
str
|
Import path or name used by
|
required |
n_candidates
|
int
|
Number of candidate parameter vectors to maintain in the pool. |
required |
batch_size
|
int
|
Number of samples returned per call to
|
required |
Source code in src/enchanted_surrogates/samplers/active_learning_sampler.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
get_fallback_samples
get_fallback_samples()
Generate random samples within bounds.
Used during warmup phase or when no observations are available.
Returns
list[dict[str, float]] Random parameter configurations.
Source code in src/enchanted_surrogates/samplers/active_learning_sampler.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
get_next_samples
get_next_samples()
Select the next batch of samples.
If insufficient observations are available (warmup phase), random samples are returned.
Otherwise, the surrogate model is trained and the query strategy selects the most informative candidates.
Returns
list[dict[str, float]] A batch of parameter dictionaries.
Source code in src/enchanted_surrogates/samplers/active_learning_sampler.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
register_future
register_future(future)
Register a completed evaluation.
Parameters
future : a PD dataframe with output and params
Adds the observation to the internal dataset.
Source code in src/enchanted_surrogates/samplers/active_learning_sampler.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |