EGObox
GitHub

Python API🔗

This page summarizes the Python API signatures from python/egobox/egobox.pyi for:

  • Egor constructor and Egor.minimize(...)
  • Belfegor constructor and Belfegor.minimize(...) (multi-objective)
  • Gpx.builder(...)
  • Gpx instance and static methods

Default values are copied from the stub.

Egor constructor🔗

Signature:

Egor(
    xspecs,
    gp_config=GpConfig(),
    n_cstr=0,
    cstr_specs=None,
    infill_n_start=20,
    n_doe=0,
    x_doe=None,
    y_doe=None,
    infill_strategy=InfillStrategy.LOG_EI,
    feasible_infill_strategy=FeasibleInfillStrategy.NONE,
    cstr_infill=False,
    cstr_strategy=ConstraintStrategy.MC,
    qei_config=QEiConfig(),
    infill_optimizer=InfillOptimizer.COBYLA,
    trego=None,
    coego_n_coop=0,
    target=-1.7976931348623157e+308,
    failsafe_strategy=FailsafeStrategy.REJECTION,
    seed=None,
    verbose=None,
)
NameTypeDefault valueDescription
xspecs[XSpec]requiredInput variable specifications (XSpec list-like), one per dimension. The simplest form is [[lower1, upper1], [lower2, upper2], …] which supposes a continuous range for each dimension. Otherwise see XSpecs for more details.
gp_configGpConfigGpConfig()GP configuration used by the optimizer.
n_cstrint0Number of surrogate-modeled constraints returned by fun.
cstr_specsOptional[Sequence[CstrSpec]]NoneOptional constraint semantics for surrogate constraints. Possible values per item: CstrSpec.leq(bound), CstrSpec.geq(bound), CstrSpec.eq(value), CstrSpec.between(lower, upper), each with an optional tol, the absolute feasibility tolerance (default 1e-4). When given, n_cstr is inferred.
infill_n_startint20Number of multistart runs for infill optimization.
n_doeint0Initial DOE size (auto-computed when 0, if DOE not provided).
x_doeOptional[NDArray[float64]]NoneInitial DOE inputs (ns, nx), evaluated when y_doe is not given.
y_doeOptional[NDArray[float64]]NoneInitial DOE outputs (ns, 1 + n_cstr) corresponding to x_doe.
infill_strategyInfillStrategyInfillStrategy.LOG_EIInfill criterion. Possible values: InfillStrategy.LOG_EI, InfillStrategy.EI, InfillStrategy.WB2, InfillStrategy.WB2S.
feasible_infill_strategyFeasibleInfillStrategyFeasibleInfillStrategy.NONEFeasibility-aware infill mode. Possible values: FeasibleInfillStrategy.NONE, FeasibleInfillStrategy.EFI_P (alias EFI_PROBABILITY), FeasibleInfillStrategy.EFI_FE (alias EFI_FEASIBILITY_ENHANCED).
cstr_infillboolFalseEnables constrained infill with probability-of-feasibility factor. Possible values: True, False.
cstr_strategyConstraintStrategyConstraintStrategy.MCConstraint handling strategy. Possible values: ConstraintStrategy.MC (alias MEAN_CONSTRAINT), ConstraintStrategy.UTB (alias UPPER_TRUST_BOUND).
qei_configQEiConfigQEiConfig()Parallel/qEI batch configuration. See QEiConfig for details.
infill_optimizerInfillOptimizerInfillOptimizer.COBYLAInternal optimizer for infill criterion. Possible values: InfillOptimizer.COBYLA, InfillOptimizer.SLSQP.
tregoOptional[Any]NoneTREGO toggle/config. Possible values: None, False, True (uses TregoConfig() defaults), TregoConfig(...), or a dict with keys n_global_local_steps, radius_bounds, alpha, beta, sigma0.
coego_n_coopint0Number of cooperative groups for CoEGO (high-dimensional mode).
targetfloat-1.7976931348623157e+308Known optimum target used as stopping criterion.
failsafe_strategyFailsafeStrategyFailsafeStrategy.REJECTIONFailure handling for NaN objective values. Possible values: FailsafeStrategy.REJECTION, FailsafeStrategy.IMPUTATION, FailsafeStrategy.VIABILITY.
seedOptional[int]NoneDefault RNG seed of minimize() and suggest(), overridden by their own seed.
verboseOptional[Any]NoneDefault logging verbosity of minimize() and suggest(), overridden by the minimize() verbose.

GpConfig🔗

NameTypeDefault valueDescription
regr_specintRegressionSpec.CONSTANT (1)Regression basis bitflags. Possible flag values: RegressionSpec.CONSTANT (1), RegressionSpec.LINEAR (2), RegressionSpec.QUADRATIC (4), bitwise combinations allowed.
corr_specintCorrelationSpec.SQUARED_EXPONENTIAL (1)Correlation kernel bitflags. Possible flag values: CorrelationSpec.SQUARED_EXPONENTIAL (1), CorrelationSpec.ABSOLUTE_EXPONENTIAL (2), CorrelationSpec.MATERN32 (4), CorrelationSpec.MATERN52 (8), bitwise combinations allowed.
kpls_dimOptional[int]NoneNo PLS projection by default.
n_clustersint1Single expert/cluster by default.
recombinationRecombinationRecombination.HARDExpert recombination mode. Possible values: Recombination.HARD, Recombination.SMOOTH.
theta_initOptional[Sequence[float]]NoneUses internal default initialization.
theta_boundsOptional[Sequence[Sequence[float]]]NoneUses internal default bounds.
theta_n_startint10GP hyperparameter optimization multistart.
theta_max_evalint50Max likelihood evaluations for hyperparameter optimization.

QEiConfig🔗

NameTypeDefault valueDescription
batchint1One point per iteration (sequential EGO).
strategyQEiStrategyQEiStrategy.KBqEI strategy. Possible values: QEiStrategy.KB, QEiStrategy.KBLB, QEiStrategy.KBUB, QEiStrategy.CLMIN (long name aliases KRIGING_BELIEVER, KRIGING_BELIEVER_LOWER_BOUND, KRIGING_BELIEVER_UPPER_BOUND, CONSTANT_LIAR_MINIMUM).
optim_everyint1Re-optimize hyperparameters every point.

TregoConfig🔗

When trego=True in Egor(...), the Python binding activates TREGO with TregoConfig() defaults.

NameTypeDefault valueDescription
n_global_local_stepstuple[int, int](1, 4)Number of global and local steps (n_global_steps, n_local_steps).
radius_boundstuple[float, float](1e-6, 1.0)Trust-region radius bounds (dmin, dmax).
alphafloat1.0Acceptance threshold coefficient in rho(sigma) = alpha * sigma^2.
betafloat0.9Trust-region contraction factor.
sigma0float0.1Initial trust-region radius.

Egor.minimize🔗

Signature:

Egor.minimize(
    fun,
    fcstrs=[],
    fcstr_specs=[],
    max_iters=20,
    run_info=None,
    outdir=None,
    warm_start=False,
    hot_start=None,
    seed=None,
    timeout=None,
    verbose=None,
)
NameTypeDefault valueDescription
funtyping.AnyrequiredObjective/constraint callable evaluated by the optimizer. fun: callable with signature fun(x: np.ndarray) -> np.ndarray where x is a 2D array of shape (n_points, n_variables) and return value is a 2D array with shape (n_points, 1 + n_constraints) containing [obj, cstr1, cstr2, …] evaluations.
fcstrsSequence[typing.Any][]Optional function constraints g(x) <= 0 (cheap constraints, not surrogate-modeled). Possible values per item: (g, grad_g), {"fun": g, "jac": grad_g}, or g(x, return_grad). The gradient is only used with InfillOptimizer.SLSQP.
fcstr_specsSequence[CstrSpec][]Optional semantics for fcstrs constraints. Possible values per item: CstrSpec.leq(bound), CstrSpec.geq(bound), CstrSpec.eq(value), CstrSpec.between(lower, upper).
max_itersint20Iteration budget.
run_infoOptional[Any]NoneOptional run metadata (RunInfo) for checkpoint naming/tracking.
outdirOptional[str]NoneDirectory for history/checkpoint artifacts and warm start lookup.
warm_startboolFalseLoads initial DOE from outdir. Possible values: True, False.
hot_startOptional[Any]NoneResume from checkpoint and optionally extend iteration budget. Possible values: None, True (interpreted as 0), or non-negative integer.
seedOptional[int]NoneRNG seed for reproducibility. Defaults to the Egor(seed=...) value.
timeoutOptional[float]NoneOptional time limit in seconds.
verboseOptional[Any]NoneLogging verbosity. Possible values: None, integer level, or Verbose enum (ERROR, WARNING, INFO, DEBUG, TRACE). Defaults to the Egor(verbose=...) value.

It returns an EgorOptim with result (an OptimResult holding x_opt, y_opt, x_doe, y_doe) and status. The result fields are also available directly on the returned object, which can be unpacked as (x_opt, y_opt):

res = egor.minimize(fun, max_iters=20)
res.x_opt, res.y_opt  # same as res.result.x_opt, res.result.y_opt
x_opt, y_opt = egor.minimize(fun, max_iters=20)

Egor.best_result(x_doe, y_doe) and Egor.best_index(y_doe) give the best point of a given DOE.

Belfegor (multi-objective, experimental)🔗

Belfegor approximates the Pareto front of several objectives, all minimized: fun(x) returns [obj_1, ..., obj_n_obj, cstr_1, ... cstr_k] columns (ny = n_obj + n_cstr). It shares the Egor options which apply to several objectives (trego, coego_n_coop and target are not available).

Signature:

Belfegor(
    xspecs,
    n_obj=2,
    moo_config=None,
    gp_config=None,
    n_cstr=0,
    cstr_specs=None,
    infill_n_start=20,
    n_doe=0,
    x_doe=None,
    y_doe=None,
    infill_strategy=InfillStrategy.LOG_EI,
    feasible_infill_strategy=FeasibleInfillStrategy.NONE,
    cstr_infill=False,
    cstr_strategy=ConstraintStrategy.MC,
    infill_optimizer=InfillOptimizer.COBYLA,
    failsafe_strategy=FailsafeStrategy.REJECTION,
    seed=None,
    verbose=None,
)
ParameterTypeDefaultDescription
n_objint2Number of objectives, the first columns returned by fun.
moo_configOptional[MooConfig | dict]NoneMulti-objective configuration, see MooConfig below.

The other parameters are the Egor ones. infill_strategy and feasible_infill_strategy apply to the scalarized objective of MooStrategy.PAREGO. Batches of points are set with MooConfig(batch=...) (there is no qei_config).

MooConfig🔗

MooConfig(
    strategy=None,
    batch=1,
    eim_aggregation=EimAggregation.EUCLIDEAN,
    hv_stop=None,
    rho=0.05,
    n_divisions=None,
)
ParameterTypeDefaultDescription
strategyOptional[MooStrategy]NonePAREGO (scalarization, single surrogate), EIM (expected improvement matrix), EHVI (expected hypervolume improvement, at most 8 objectives) or QEHVI (batch EHVI, single-cluster surrogates). None gives EHVI for 2 or 3 objectives, PAREGO beyond.
batchint1Number of points evaluated at each iteration. With QEHVI (at most 4 points) the batch points are selected by qEHVI, otherwise by the Kriging believer heuristic (each point maximizes the criterion, the previous points of the batch being added with their predicted values).
eim_aggregationEimAggregationEUCLIDEANAggregation used by EIM: EUCLIDEAN, MAXIMIN or HYPERVOLUME.
hv_stopOptional[tuple[float, int]]None(tol, n_iters): stop when the hypervolume of the feasible front improves by less than tol (relative) over the last n_iters iterations (ExitStatus.SOLVER_CONVERGED).
rhofloat0.05ParEGO augmented Tchebycheff coefficient.
n_divisionsOptional[int]NoneParEGO number of divisions of the weight simplex lattice (10 for 2 objectives, 4 for 3, 3 beyond).

A dict with the same keys is also accepted.

Belfegor.minimize🔗

Belfegor.minimize(fun, fcstrs=None, fcstr_specs=None, max_iters=20, run_info=None, outdir=None, warm_start=False, hot_start=None, seed=None, timeout=None, verbose=None, stop_on_error=False) takes the Egor.minimize parameters and returns a BelfegorOptim with result (a ParetoResult holding x_pareto, y_pareto, x_opt, y_opt, x_doe, y_doe) and status. x_pareto/y_pareto is the (constrained) Pareto front approximation and x_opt/y_opt its compromise point. The result fields are also available directly on the returned object, which can be unpacked as (x_pareto, y_pareto):

res = belfegor.minimize(fun, max_iters=20)
res.x_pareto, res.y_pareto  # same as res.result.x_pareto, res.result.y_pareto
x_pareto, y_pareto = belfegor.minimize(fun, max_iters=20)

Belfegor.suggest(x_doe, y_doe) gives the next points to evaluate (ask-and-tell), and Belfegor.pareto_result(x_doe, y_doe) / Belfegor.pareto_indices(y_doe) give the Pareto front of a given DOE.

Gpx.builder🔗

Signature:

Gpx.builder(
    xspecs=None,
    regr_spec=1,
    corr_spec=1,
    kpls_dim=None,
    n_clusters=1,
    recombination=Recombination.HARD,
    theta_init=None,
    theta_bounds=None,
    theta_n_start=10,
    theta_max_eval=50,
    seed=None,
    verbose=None,
)
NameTypeDefault valueDescription
xspecsOptional[[XSpec]]NoneOptional input variable specification (XSpec-like).
regr_specint1Regression basis bitflags (RegressionSpec). Possible flag values: CONSTANT (1), LINEAR (2), QUADRATIC (4), bitwise combinations allowed.
corr_specint1Correlation kernel bitflags (CorrelationSpec). Possible flag values: SQUARED_EXPONENTIAL (1), ABSOLUTE_EXPONENTIAL (2), MATERN32 (4), MATERN52 (8), bitwise combinations allowed.
kpls_dimOptional[int]NonePLS projection dimension for high-dimensional inputs.
n_clustersint1Number of local experts/clusters in the mixture.
recombinationRecombinationRecombination.HARDExpert recombination policy. Possible values: Recombination.HARD, Recombination.SMOOTH.
theta_initOptional[Sequence[float]]NoneInitial GP hyperparameter guess.
theta_boundsOptional[Sequence[Sequence[float]]]NoneSearch bounds for GP hyperparameter optimization.
theta_n_startint10Hyperparameter optimization multistart count.
theta_max_evalint50Max likelihood evaluations during hyperparameter optimization.
seedOptional[int]NoneRNG seed for reproducibility.
verboseOptional[Any]NoneOptional logging verbosity. Possible values: None, integer level, or Verbose enum (ERROR, WARNING, INFO, DEBUG, TRACE).

Gpx methods🔗

def __repr__(self) -> str
def __str__(self) -> str
def save(self, filename: str) -> bool
@staticmethod
def load(filename: str) -> Gpx
def predict(self, x: NDArray[float64], return_std: bool = False) -> NDArray[float64] | tuple[NDArray[float64], NDArray[float64]]
def predict_var(self, x: NDArray[float64]) -> NDArray[float64]
def predict_gradients(self, x: NDArray[float64]) -> NDArray[float64]
def predict_var_gradients(self, x: NDArray[float64]) -> NDArray[float64]
def sample(self, x: NDArray[float64], n_traj: int) -> NDArray[float64]
def dims(self) -> tuple[int, int]
nx: int  # read-only property, number of inputs
ny: int  # read-only property, number of outputs
def training_data(self) -> tuple[NDArray[float64], NDArray[float64]]
thetas: NDArray[float64]  # read-only property, optimized hyperparameters (n_clusters, nx or kpls_dim)
variances: NDArray[float64]  # read-only property, variance of each expert (n_clusters,)
likelihoods: NDArray[float64]  # read-only property, reduced likelihood of each expert (n_clusters,)

XSpecs🔗

xspecs passed to Egor(...) or Gpx.builder(...) is a sequence of XSpec, one per input dimension (len(xspecs) == nx).

Note: When using continuous variables only, the simplest form is a list of [lower, upper] pairs, e.g. [[0.0, 1.0], [1.0, 10.0], [-5.0, 5.0]]. Otherwise, use XSpec(...) for more complex variable types.

Signature:

XSpec(xtype: XType, xlimits: Sequence[float] = [], tags: Sequence[str] = [])
FieldTypeDescription
xtypeXTypeVariable kind. Possible values: XType.FLOAT, XType.INT, XType.ORD, XType.ENUM.
xlimitsSequence[float]Domain encoding, interpreted from xtype (see table below).
tagsSequence[str]Optional labels for enum categories (documentation labels only; optimization uses category indices).

xlimits meaning by xtype:

XTypexlimits formatExample
FLOAT[lower: float, upper: float]XSpec(XType.FLOAT, [0.0, 1.0])
INT[lower: int, upper: int]XSpec(XType.INT, [1, 10])
ORDordered list of allowed valuesXSpec(XType.ORD, [0.1, 0.5, 1.0])
ENUMeither [n_categories] or explicit tags=[...]XSpec(XType.ENUM, [3]) or XSpec(XType.ENUM, tags=["red", "green", "blue"])

Full mixed-type example:

xspecs = [
    XSpec(XType.FLOAT, [0.0, 1.0]),
    XSpec(XType.INT, [1, 8]),
    XSpec(XType.ORD, [0.2, 0.5, 1.0]),
    XSpec(XType.ENUM, tags=["small", "medium", "large"]),
]