EGObox
GitHub

Python API🔗

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

  • Egor constructor and Egor.minimize(...)
  • 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_tol=None,
    cstr_specs=None,
    n_start=20,
    n_doe=0,
    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,
)
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_tolOptional[Sequence[float]]NonePer-constraint feasibility tolerances.
cstr_specsOptional[Sequence[CstrSpec]]NoneOptional constraint semantics for surrogate constraints. Possible values per item: CstrSpec.leq(bound), CstrSpec.geq(bound), CstrSpec.eq(value), CstrSpec.btw(lower, upper).
n_startint20Number of multistart runs for infill optimization.
n_doeint0Initial DOE size (auto-computed when 0, if DOE not provided).
doeOptional[NDArray[float64]]NoneInitial DOE matrix (x only or concatenated x,y).
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, FeasibleInfillStrategy.EFI_FE.
cstr_infillboolFalseEnables constrained infill with probability-of-feasibility factor. Possible values: True, False.
cstr_strategyConstraintStrategyConstraintStrategy.MCConstraint handling strategy. Possible values: ConstraintStrategy.MC, ConstraintStrategy.UTB.
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_gl_steps, d, 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.

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.
n_startint10GP hyperparameter optimization multistart.
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.
optmodint1Re-optimize hyperparameters every point.

TregoConfig🔗

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

NameTypeDefault valueDescription
n_gl_stepstuple[int, int](1, 4)Number of global and local steps (n_global_steps, n_local_steps).
dtuple[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 (cheap constraints, not surrogate-modeled).
fcstr_specsSequence[CstrSpec][]Optional semantics for fcstrs constraints. Possible values per item: CstrSpec.leq(bound), CstrSpec.geq(bound), CstrSpec.eq(value), CstrSpec.btw(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.
timeoutOptional[float]NoneOptional time limit in seconds.
verboseOptional[Any]NoneLogging verbosity. Possible values: None, integer level, or Verbose enum (ERROR, WARNING, INFO, DEBUG, TRACE).

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,
    n_start=10,
    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.
n_startint10Hyperparameter optimization multistart count.
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]) -> 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]
def training_data(self) -> tuple[NDArray[float64], NDArray[float64]]
def thetas(self) -> NDArray[float64]
def variances(self) -> NDArray[float64]
def likelihoods(self) -> NDArray[float64]

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"]),
]