Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bee1a1f

Browse files
committedJan 4, 2025·
Add readme specific to python egobox binding
1 parent cef2f80 commit bee1a1f

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
 

‎python/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition.workspace = true
77
homepage.workspace = true
88
description = "A python binding for egobox crates"
99
repository = "https://github.com/relf/egobox/python"
10+
readme = "README.md"
1011

1112
[lib]
1213
name = "egobox"

‎python/README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# EGObox - Efficient Global Optimization toolbox
2+
3+
[![pytests](https://github.com/relf/egobox/workflows/pytest/badge.svg)](https://github.com/relf/egobox/actions?query=workflow%3Apytest)
4+
[![DOI](https://joss.theoj.org/papers/10.21105/joss.04737/status.svg)](https://doi.org/10.21105/joss.04737)
5+
6+
`egobox` package is the Python binding of the optimizer named `Egor` and the surrogate model `Gpx`, mixture of Gaussian processes, from the [EGObox libraries](https://github.com/relf/egobox?tab=readme-ov-file#egobox---efficient-global-optimization-toolbox) written in Rust.
7+
8+
## Installation
9+
10+
```bash
11+
pip install egobox
12+
```
13+
14+
### Egor optimizer
15+
16+
```python
17+
import numpy as np
18+
import egobox as egx
19+
20+
# Objective function
21+
def f_obj(x: np.ndarray) -> np.ndarray:
22+
return (x - 3.5) * np.sin((x - 3.5) / (np.pi))
23+
24+
# Minimize f_opt in [0, 25]
25+
res = egx.Egor(egx.to_specs([[0.0, 25.0]]), seed=42).minimize(f_obj, max_iters=20)
26+
print(f"Optimization f={res.y_opt} at {res.x_opt}") # Optimization f=[-15.12510323] at [18.93525454]
27+
```
28+
29+
### Gpx surrogate model
30+
31+
```python
32+
import numpy as np
33+
import egobox as egx
34+
35+
# Training
36+
xtrain = np.array([0.0, 1.0, 2.0, 3.0, 4.0])
37+
ytrain = np.array([0.0, 1.0, 1.5, 0.9, 1.0])
38+
gpx = egx.Gpx.builder().fit(xtrain, ytrain)
39+
40+
# Prediction
41+
xtest = np.linspace(0, 4, 20).reshape((-1, 1))
42+
ytest = gpx.predict(xtest)
43+
```
44+
45+
See the [tutorial notebooks](https://github.com/relf/egobox/tree/master/doc/README.md) and [examples folder](https://github.com/relf/egobox/tree/d9db0248199558f23d966796737d7ffa8f5de589/python/egobox/examples) for more information on the usage of the optimizer and mixture of Gaussian processes surrogate model.

0 commit comments

Comments
 (0)
Please sign in to comment.