EGObox
Efficient global optimization toolbox in Rust: bayesian optimization, mixture of gaussian processes, sampling methods
Install / Use
/learn @relf/EGOboxREADME
EGObox - Efficient Global Optimization toolbox
Rust toolbox for Efficient Global Optimization method (arguably the most well-known bayesian optimization algorithm) which adresses the gradient-free optimization of expensive objective functions.
The egobox package is twofold:
- for end-users: a Python module, the Python binding of the optimizer named
Egorand the surrogate modelGpx, mixture of Gaussian processes, written in Rust. - for developers: a set of Rust libraries useful to implement bayesian optimization (EGO-like) algorithms,
The Python module
Installation
pip install egobox
Egor optimizer
import numpy as np
import egobox as egx
# Objective function
def f_obj(x: np.ndarray) -> np.ndarray:
return (x - 3.5) * np.sin((x - 3.5) / (np.pi))
# Minimize f_opt in [0, 25]
res = egx.Egor([[0.0, 25.0]], seed=42).minimize(f_obj, max_iters=20)
print(f"Optimization f={res.y_opt} at {res.x_opt}") # Optimization f=[-15.12510323] at [18.93525454]
See also this example written in Rust
Gpx surrogate model
import numpy as np
import matplotlib.pyplot as plt
import egobox as egx
# Training
xtrain = np.array([0.0, 1.0, 2.0, 3.0, 4.0])
ytrain = np.array([0.0, 1.0, 1.5, 0.9, 1.0])
gpx = egx.Gpx.builder().fit(xtrain, ytrain)
# Prediction
xtest = np.linspace(0, 4, 100).reshape((-1, 1))
ytest = gpx.predict(xtest)
# Plot
plt.plot(xtest, ytest)
plt.plot(xtrain, ytrain, "o")
plt.show()
See also this example written in Rust
See the tutorial notebooks and examples folder for more information on the usage of the optimizer and mixture of Gaussian processes surrogate model.
The Rust libraries
egobox Rust libraries consists of the following sub-packages.
| Name | Version | Documentation | Description |
| :----------------------------------------------------------- | :---------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------- |
| doe | |
| sampling methods; contains LHS, FullFactorial, Random methods |
| gp |
|
| gaussian process regression; contains Kriging, PLS dimension reduction and sparse methods |
| moe |
|
| mixture of experts using GP models |
| ego |
|
| efficient global optimization with constraints and mixed integer handling |
Usage
Depending on the sub-packages you want to use, you have to add following declarations to your Cargo.toml
[dependencies]
egobox-doe = { version = "0.x.y" }
egobox-gp = { version = "0.x.y" }
egobox-moe = { version = "0.x.y" }
egobox-ego = { version = "0.x.y" }
Features
The table below presents the various features available depending on the subcrate
| Name | doe | gp | moe | ego | | :----------- | :--- | :--- | :--- | :--- | | serializable | ✔️ | ✔️ | ✔️ | | | persistent | | | ✔️ | ✔️(*) | | blas | | ✔️ | ✔️ | ✔️ | | nlopt | | ✔️ | | ✔️ |
(*) for persistent mixture of gaussian processes with discrete variable available in ego
serializable
When selected, the serialization with serde crate is enabled.
persistent
When selected, the save and load as a json file with serde_json crate is enabled.
blas
When selected, the usage of BLAS/LAPACK backend is possible, see below for more information.
nlopt
When selected, the nlopt crate is used to provide optimizer implementations (ie Cobyla, Slsqp)
Examples
Examples (in examples/ sub-packages folder) are run as follows:
cd doe && cargo run --example samplings --release
cd gp && cargo run --example kriging --release
cd moe && cargo run --example clustering --release
cd ego && cargo run --example ackley --release
BLAS/LAPACK backend (optional)
egobox relies on linfa project for methods like clustering and dimension reduction, but also try to adopt as far as possible the same coding structures.
As for linfa, the linear algebra routines used in gp, moe ad ego are provided by the pure-Rust linfa-linalg crate, the default linear algebra provider.
Otherwise, you can choose an external BLAS/LAPACK backend available through the ndarray-linalg crate. In this case, you have to specify the blas feature and a linfa BLAS/LAPACK backend feature (more information in linfa features).
Thus, for instance, to use gp with the Intel MKL BLAS/LAPACK backend, you could specify in your Cargo.toml the following features:
[dependencies]
egobox-gp = { version = "0.x.y", features = ["blas", "linfa/intel-mkl-static"] }
or you could run the gp example as follows:
cd gp && cargo run --example kriging --release --features blas,linfa/intel-mkl-static
Citation
If you find this project useful for your research, you may cite it as follows:
@article{
Lafage2022,
author = {Rémi Lafage},
title = {egobox, a Rust toolbox for efficient global optimization},
journal = {Journal of Open Source Software}
year = {2022},
doi = {10.21105/joss.04737},
url = {https://doi.org/10.21105/joss.04737},
publisher = {The Open Journal},
volume = {7},
number = {78},
pages = {4737},
}
Additionally, you may consider adding a star to the repository. This positive feedback improves the visibility of the project.
References
Bartoli, N., Lefebvre, T., Dubreuil, S., Olivanti, R., Priem, R., Bons, N., Martins, J. R. R. A., & Morlier, J. (2019). Adaptive modeling strategy for constrained global optimization with application to aerodynamic wing design. Aerospace Science and Technology, 90, 85–102.
Bouhlel, M. A., Bartoli, N., Otsmane, A., & Morlier, J. (2016). Improving kriging surrogates of high-dimensional design models by partial least squares dimension reduction. Structural and Multidisciplinary Optimization, 53(5), 935–952.
Bouhlel, M. A., Hwang, J. T., Bartoli, N., Lafage, R., Morlier, J., & Martins, J. R. R. A. (2019). A python surrogate modeling framework with derivatives. Advances in Engineering Software, 102662.
Dubreuil, S., Bartoli, N., Gogu, C., & Lefebvre, T. (2020). Towards an efficient global multi-disciplinary design optimization algorithm Structural and Multidisciplinary Optimization, 62(4), 1739–1765.
Jin, R. and Chen, W. and Sudjianto, A. (2005). An efficient algorithm for constructing optimal design of computer experiments Journal of Statistical Planning and Inference, 134:268-287.
Bettebghor, Dimitri, et al. (2011). Surrogate modeling approximation using a mixture of experts based on EM joint estimation Structural and multidisciplinary optimization 43.2 (2011): 243-259.
Jones, D. R., Schonlau, M., & Welch, W. J. (1998). Efficient global optimization of expensive black-box functions. Journal of Global Optimization, 13(4), 455–492.
Diouane, Yousse
