Choose and swap built-in components#
The prerequisite is using the high-level API or an Optimizer execution path.
What you’ll be able to do
By the end of this page, you’ll be able to choose the built-in component for the responsibility you want to change and pass it to the appropriate swap point.
See the optimization components index; if you need a custom component, see Custom components.
The Canonical Imports page summarizes import choices.
Choose by responsibility#
Components are swap points for choosing another implementation of the same operation.
AcquisitionFunction and SurrogateManager are independent swap points; neither contains the other.
What to change |
Component to swap |
Where to look |
|---|---|---|
Search method that generates candidates |
|
|
Crossover, mutation, and selection |
|
|
Prediction model |
|
|
Training data and prediction process |
|
|
Rule that converts predictions into candidate scores |
|
|
Fraction or order of surrogate candidates sent for true evaluation |
|
|
Solution ranking |
|
Swap through the high-level API#
The high-level API accepts strings or instances for algorithm, surrogate, and strategy.
The available strings are "GA" and "PSO" for algorithms, "rbf" for Surrogate, and "ib", "gb", and "ps" for Strategy.
import numpy as np
from saealib import minimize
def objective(x):
return np.sum(x**2)
result = minimize(
objective,
dim=3,
lb=[-5.0] * 3,
ub=[5.0] * 3,
algorithm="PSO",
strategy="ib",
max_fe=100,
seed=0,
verbose=False,
)
A standalone Surrogate instance is wrapped in a LocalSurrogateManager internally.
Use Optimizer when configuring a Manager or AcquisitionFunction separately.
Configure independent swap points with Optimizer#
Optimizer.set_*() is a builder for configuring components independently.
For example, set_surrogate_manager() and set_acquisition() are separate calls.
import numpy as np
from saealib import MeanPrediction, Optimizer, Problem
from saealib.surrogate import GaussianKernel, GlobalSurrogateManager, RBFSurrogate
def objective(x):
return np.sum(x**2)
problem = Problem(
objective,
dim=3,
n_obj=1,
direction=np.array([-1.0]),
lb=[-5.0] * 3,
ub=[5.0] * 3,
)
manager = GlobalSurrogateManager(RBFSurrogate(kernel=GaussianKernel()))
optimizer = (
Optimizer(problem, seed=0)
.set_surrogate_manager(manager)
.set_acquisition(MeanPrediction())
)
Other components required by Optimizer can be resolved from defaults.
Components configured with set_*() and omitted components are validated after run() or iterate() resolves the defaults.
When every required component is explicit, you can also call validate() directly before running.
Continue to Implement custom components only when built-in components cannot meet the responsibility.