saealib.LocalSurrogateManager#
- class saealib.LocalSurrogateManager(surrogate, training_set=None, accuracy_evaluator=None)[source]#
Bases:
SurrogateManagerSurrogate manager that fits a local model per candidate (pre-selection).
For each candidate, retrieves the k nearest neighbors from the archive, fits the surrogate on that local neighborhood, and predicts the candidate’s objective value. This corresponds to the individual-based local modeling strategy common in SAEA literature.
NOTE: The same surrogate instance is reused across candidates (re-fit each iteration). This is not thread-safe. For parallel use, provide a surrogate factory instead (future work).
- Parameters:
surrogate (Surrogate) – Surrogate model instance (re-fit per candidate).
training_set (TrainingSet or None) – Strategy object for building training data per candidate. Defaults to
KNNObjectiveSet(n_neighbors=50).accuracy_evaluator (AccuracyEvaluator or None) – If provided,
predict()computes accuracy metrics whenrefit=Trueand stores them inlast_accuracy. Accuracy is estimated by fitting a local model for each archive point via the sametraining_setand comparing the prediction against the true value.
Methods
Return the local-manager contract. |
|
Compute accuracy metrics from the archive (no global model is fitted). |
|
End-of-generation hook; override to update internal state. |
|
Fit a local model per candidate and predict each individually. |
|
Return a copy of this manager with |
Method Details
- LocalSurrogateManager.__init__(surrogate, training_set=None, accuracy_evaluator=None)[source]#
- Parameters:
surrogate (Surrogate)
training_set (TrainingSet | None)
accuracy_evaluator (AccuracyEvaluator | None)
- LocalSurrogateManager.fit(archive, ctx=None)[source]#
Compute accuracy metrics from the archive (no global model is fitted).
For
LocalSurrogateManager, there is no persistent global surrogate to pre-fit; local models are always built per candidate insidepredict(). However, callingfit()explicitly (asGenerationBasedStrategydoes before its inner loop) still triggers accuracy evaluation so thatlast_accuracyis available regardless of which strategy is used.- Parameters:
archive (Archive)
ctx (OptimizationState | None)
- Return type:
None
- LocalSurrogateManager.on_generation_end(gen, archive, ctx=None)#
End-of-generation hook; override to update internal state.
- Parameters:
gen (int)
archive (Archive)
ctx (OptimizationState | None)
- Return type:
None
- LocalSurrogateManager.predict(candidates_x, archive, ctx=None, *, refit=True)[source]#
Fit a local model per candidate and predict each individually.
When
refit=Trueand anaccuracy_evaluatoris configured, accuracy is estimated inline using a nearest-neighbor holdout method: for each candidate, the closest archive neighbor is reserved as a validation point and excluded from training. Metrics are averaged over all candidates and stored inlast_accuracy.Because the holdout point is excluded from training, the effective training-set size is
n_neighbors - 1when an accuracy evaluator is active. Without an accuracy evaluator the fulln_neighborspoints are always used.A different local model is fit per candidate, but the per-candidate single-row predictions are stacked (see
_stack_predictions()) into one batchedSurrogatePredictioncovering every row ofcandidates_x, matching the base class contract.- Parameters:
candidates_x (np.ndarray)
archive (Archive)
ctx (OptimizationState | None)
refit (bool)
- Return type:
- LocalSurrogateManager.with_on_generation_end(fn)#
Return a copy of this manager with
fnappended to the hook.- Parameters:
fn (callable) –
fn(gen, archive, ctx) -> None- Returns:
Shallow copy with the hook registered.
- Return type: