Skip to content

GIVPOptimizer

givp.GIVPOptimizer

Bases: BaseEstimator

Object-oriented wrapper around :func:givp.

Holds configuration and bounds, exposes a run() method that returns an :class:OptimizeResult. The instance also caches the best solution across repeated run() calls (useful for multi-start strategies).

This class inherits from sklearn.base.BaseEstimator, enabling seamless integration with scikit-learn's cross-validation and hyperparameter tuning tools such as GridSearchCV and RandomizedSearchCV.

Example (sklearn integration): >>> from sklearn.model_selection import GridSearchCV >>> from givp import GIVPOptimizer >>> def objective(x): ... return (x[0] - 1)2 + (x[1] - 2)2 >>> opt = GIVPOptimizer(objective, [(-5, 5), (-5, 5)]) >>> grid = GridSearchCV( ... opt, ... param_grid={"config__alpha": [0.1, 0.5]}, ... cv=3 ... )

fit

fit(
    _x: NDArray | None = None, _y: NDArray | None = None
) -> GIVPOptimizer

Fit the optimizer (sklearn-compatible interface).

This method is provided for sklearn compatibility and simply calls :meth:run(), ignoring X and y (since GIVP is an unsupervised, black-box optimizer).

Parameters:

Name Type Description Default
_x NDArray | None

Ignored. Provided for sklearn compatibility.

None
_y NDArray | None

Ignored. Provided for sklearn compatibility.

None

Returns:

Name Type Description
GIVPOptimizer GIVPOptimizer

Returns self to enable method chaining.

Example

opt = GIVPOptimizer(objective, bounds) opt.fit() # Equivalent to opt.run() print(opt.best_fun)

run

run() -> OptimizeResult

Execute one optimization round and update the historical best.

Returns:

Name Type Description
OptimizeResult OptimizeResult

Result of one optimization run, including x,

OptimizeResult

fun, and metadata. Also updates internal best_x,

OptimizeResult

best_fun, and history.