saealib.LocalSurrogateManager#

class saealib.LocalSurrogateManager(surrogate, training_set=None, accuracy_evaluator=None)[source]#

Bases: SurrogateManager

Surrogate 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 when refit=True and stores them in last_accuracy. Accuracy is estimated by fitting a local model for each archive point via the same training_set and comparing the prediction against the true value.

Methods

__init__

contract

Return the local-manager contract.

fit

Compute accuracy metrics from the archive (no global model is fitted).

on_generation_end

End-of-generation hook; override to update internal state.

predict

Fit a local model per candidate and predict each individually.

with_on_generation_end

Return a copy of this manager with fn appended to the hook.

Method Details

LocalSurrogateManager.__init__(surrogate, training_set=None, accuracy_evaluator=None)[source]#
Parameters:
LocalSurrogateManager.contract()[source]#

Return the local-manager contract.

Return type:

ComponentContract

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 inside predict(). However, calling fit() explicitly (as GenerationBasedStrategy does before its inner loop) still triggers accuracy evaluation so that last_accuracy is 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=True and an accuracy_evaluator is 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 in last_accuracy.

Because the holdout point is excluded from training, the effective training-set size is n_neighbors - 1 when an accuracy evaluator is active. Without an accuracy evaluator the full n_neighbors points 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 batched SurrogatePrediction covering every row of candidates_x, matching the base class contract.

Parameters:
  • candidates_x (np.ndarray)

  • archive (Archive)

  • ctx (OptimizationState | None)

  • refit (bool)

Return type:

SurrogatePrediction

LocalSurrogateManager.with_on_generation_end(fn)#

Return a copy of this manager with fn appended to the hook.

Parameters:

fn (callable) – fn(gen, archive, ctx) -> None

Returns:

Shallow copy with the hook registered.

Return type:

SurrogateManager