saealib.SurrogateManager#

class saealib.SurrogateManager[source]#

Bases: ABC

Abstract base class for surrogate managers.

A SurrogateManager is narrowed to training and prediction management It coordinates TrainingSet construction, model fitting, and prediction, and returns a SurrogatePrediction for callers.

last_accuracy#

Accuracy metrics computed after the most recent fit() call. None until the first fit or when no evaluator is configured.

Type:

SurrogateAccuracy or None

Methods

__init__

contract

Return the surrogate-manager contract.

fit

Pre-fit the surrogate on the archive.

on_generation_end

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

predict

Predict candidate solutions using the surrogate model.

with_on_generation_end

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

Method Details

SurrogateManager.__init__()#
SurrogateManager.contract()[source]#

Return the surrogate-manager contract.

Return type:

ComponentContract

SurrogateManager.fit(archive, ctx=None)[source]#

Pre-fit the surrogate on the archive.

Call once before a sequence of predict(..., refit=False) calls when the archive does not change between calls (e.g. the surrogate-only inner loop of GenerationBasedStrategy). The default implementation is a no-op; override in managers that maintain a fitted surrogate model.

Parameters:
  • archive (Archive) – Archive of evaluated solutions used for surrogate training.

  • ctx (OptimizationState or None, optional) – Current optimization context.

Return type:

None

SurrogateManager.on_generation_end(gen, archive, ctx=None)[source]#

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

Parameters:
  • gen (int)

  • archive (Archive)

  • ctx (OptimizationState | None)

Return type:

None

abstractmethod SurrogateManager.predict(candidates_x, archive, ctx=None, *, refit=True)[source]#

Predict candidate solutions using the surrogate model.

Parameters:
  • candidates_x (np.ndarray) – Candidate design variable matrix. shape: (n_candidates, dim)

  • archive (Archive) – Archive of evaluated solutions used for surrogate training.

  • ctx (OptimizationState or None, optional) – Current optimization context. Passed to TrainingSet.build for strategies that require comparator or population access.

  • refit (bool, optional) – If True (default), fit the surrogate before predicting. Pass False after an explicit fit() call to skip redundant re-fitting when the archive has not changed.

Returns:

One batched prediction covering every row of candidates_x. Acquisition scoring is not performed here — pass the result to an AcquisitionFunction.

Return type:

SurrogatePrediction

SurrogateManager.with_on_generation_end(fn)[source]#

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