High-Level API¶
- saealib.minimize(func, algorithm='GA', *, dim=None, lb=None, ub=None, n_obj=1, surrogate='rbf', strategy='ib', max_fe=None, pop_size=None, n_neighbors=50, seed=None, verbose=True)[source]¶
Run surrogate-assisted minimization.
- Parameters:
func (callable or Problem) – Objective function
f(x) -> float | array, or a fully configuredProbleminstance (in which casedim,lb,ub, andn_objare ignored).algorithm (str or Algorithm) –
'GA','PSO', or anAlgorithminstance. Default:'GA'.dim (int, optional) – Number of design variables. Required when func is a callable.
lb (array-like, optional) – Lower bounds of length dim. Required when func is a callable.
ub (array-like, optional) – Upper bounds of length dim. Required when func is a callable.
n_obj (int) – Number of objectives. Ignored when func is a
Problem. Default: 1.surrogate (str, Surrogate, SurrogateManager, or None) –
'rbf', aSurrogate, or aSurrogateManager. Default:'rbf'.strategy (str or OptimizationStrategy) –
'ib','gb','ps', or anOptimizationStrategy. Default:'ib'.max_fe (int or None) – Maximum true function evaluations. Default:
200 * dim.pop_size (int or None) – Population size. Default:
4 * dim.n_neighbors (int) – Nearest neighbours for
LocalSurrogateManager. Default: 50.seed (int or None) – Random seed for
LHSInitializer.verbose (bool) – If
False, suppress per-generation log output. Default:True.
- Return type:
Examples
>>> from saealib import minimize >>> import numpy as np >>> result = minimize(lambda x: np.sum(x**2), dim=5, lb=[-5]*5, ub=[5]*5, ... max_fe=500, seed=0, verbose=False) >>> result.X, result.F
- saealib.maximize(func, algorithm='GA', *, dim=None, lb=None, ub=None, n_obj=1, surrogate='rbf', strategy='ib', max_fe=None, pop_size=None, n_neighbors=50, seed=None, verbose=True)[source]¶
Run surrogate-assisted maximization.
Identical to
minimize()except that all objectives are maximized (weight = +1).- Parameters:
func (callable or Problem) – Objective function
f(x) -> float | array, or a fully configuredProbleminstance.algorithm (str or Algorithm) –
'GA','PSO', or anAlgorithminstance. Default:'GA'.dim (int, optional) – Number of design variables. Required when func is a callable.
lb (array-like, optional) – Lower bounds of length dim. Required when func is a callable.
ub (array-like, optional) – Upper bounds of length dim. Required when func is a callable.
n_obj (int) – Number of objectives. Ignored when func is a
Problem. Default: 1.surrogate (str, Surrogate, SurrogateManager, or None) –
'rbf', aSurrogate, or aSurrogateManager. Default:'rbf'.strategy (str or OptimizationStrategy) –
'ib','gb','ps', or anOptimizationStrategy. Default:'ib'.max_fe (int or None) – Maximum true function evaluations. Default:
200 * dim.pop_size (int or None) – Population size. Default:
4 * dim.n_neighbors (int) – Nearest neighbours for
LocalSurrogateManager. Default: 50.seed (int or None) – Random seed for
LHSInitializer.verbose (bool) – If
False, suppress per-generation log output. Default:True.
- Return type:
Examples
>>> from saealib import maximize >>> import numpy as np >>> result = maximize(lambda x: -np.sum(x**2) + 10, dim=5, lb=[-5]*5, ub=[5]*5, ... max_fe=500, seed=0, verbose=False) >>> result.X, result.F
Optimization result returned by |