Skip to content

Commit f0cc1b5

Browse files
authored
Refactor ego module (#169)
* Move solver impl in solver sub-module * Renaming solver files * Make clippy happy * Add solver structs visibility * Refactor organizing egobox-ego with sub-modules * Expose regression and correlation specs * Use web-time instead of deprecated instant * Fix instant in doc examples
1 parent 89fafae commit f0cc1b5

22 files changed

+653
-593
lines changed

ego/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ nlopt = { version = "0.7.0", optional = true }
4141

4242
rand_xoshiro = { version = "0.6", features = ["serde1"] }
4343
argmin = { version = "0.10.0", features = ["serde1", "ctrlc"] }
44-
instant = "0.1"
44+
web-time = "1.1.0"
4545
libm = "0.2.6"
4646
finitediff = { version = "0.1", features = ["ndarray"] }
4747
# sort-axis

ego/src/criteria/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
pub mod ei;
2-
pub mod wb2;
1+
//! Available infill criteria to be used by Egor solver
2+
mod ei;
3+
mod wb2;
34

45
pub use ei::{ExpectedImprovement, EI};
56
pub use wb2::{WB2Criterion, WB2, WB2S};

ego/src/egor.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@
9090
//! ```
9191
//!
9292
use crate::egor_config::*;
93-
use crate::egor_solver::*;
9493
use crate::errors::Result;
95-
use crate::mixint::*;
94+
use crate::gpmix::mixint::*;
9695
use crate::types::*;
96+
use crate::{to_xtypes, EgorSolver};
9797

9898
use egobox_moe::GpMixtureParams;
9999
use log::info;
@@ -237,6 +237,8 @@ mod tests {
237237
use serial_test::serial;
238238
use std::time::Instant;
239239

240+
use crate::{gpmix::spec::*, DOE_FILE, DOE_INITIAL_FILE};
241+
240242
#[cfg(not(feature = "blas"))]
241243
use linfa_linalg::norm::*;
242244
#[cfg(feature = "blas")]

ego/src/mixint.rs renamed to ego/src/gpmix/mixint.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
//! This library implements continuous relaxation functions,
2-
//! it is a port of [SMT mixed integer module](https://smt.readthedocs.io/en/latest/_src_docs/applications/mixed_integer.html)
1+
//! Mixed-integer mixture of Gaussian processes
2+
//!
3+
//! This module exposes a GP mixture model featuring continuous relaxation to handle mixed-interger variables
34
45
#![allow(dead_code)]
56
use crate::errors::{EgoError, Result};

ego/src/gpmix/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//! Mixture of Gaussian process models used by the Egor solver
2+
3+
pub mod mixint;
4+
pub mod spec;

ego/src/gpmix/spec.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//! GP mixture model specification used by the Egor solver
2+
3+
/// Flags for regression model selection
4+
pub use egobox_moe::RegressionSpec;
5+
6+
/// Flags for correlation model selection
7+
pub use egobox_moe::CorrelationSpec;

ego/src/lib.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,27 +175,22 @@
175175
//! integer-valued variables in Bayesian Optimization with Gaussian processes.
176176
//!
177177
//!
178-
mod criteria;
178+
pub mod criteria;
179+
pub mod gpmix;
180+
179181
mod egor;
180182
mod egor_config;
181-
mod egor_service;
182-
mod egor_solver;
183-
mod egor_state;
184183
mod errors;
185-
mod mixint;
184+
mod solver;
186185
mod types;
187186

188-
mod lhs_optimizer;
189-
mod optimizer;
190-
mod sort_axis;
191-
mod utils;
192-
193-
pub use crate::criteria::*;
194187
pub use crate::egor::*;
195188
pub use crate::egor_config::*;
196-
pub use crate::egor_service::*;
197-
pub use crate::egor_solver::*;
198-
pub use crate::egor_state::*;
199189
pub use crate::errors::*;
200-
pub use crate::mixint::*;
190+
pub use crate::gpmix::spec::{CorrelationSpec, RegressionSpec};
191+
pub use crate::solver::*;
201192
pub use crate::types::*;
193+
pub use crate::utils::find_best_result_index;
194+
195+
mod optimizers;
196+
mod utils;
File renamed without changes.

ego/src/optimizers/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//! Optimizers used internally to optimize the infill criterion
2+
3+
mod lhs_optimizer;
4+
mod optimizer;
5+
6+
pub(crate) use lhs_optimizer::*;
7+
pub(crate) use optimizer::*;

ego/src/optimizer.rs renamed to ego/src/optimizers/optimizer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::lhs_optimizer::LhsOptimizer;
1+
use crate::optimizers::LhsOptimizer;
22
use crate::ObjData;
33
use ndarray::{arr1, Array1, Array2, ArrayView1};
44

ego/src/egor_service.rs renamed to ego/src/solver/egor_service.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
//! ```
4141
//!
4242
use crate::egor_config::*;
43-
use crate::egor_solver::*;
44-
use crate::mixint::*;
43+
use crate::gpmix::mixint::*;
4544
use crate::types::*;
45+
use crate::{to_xtypes, EgorSolver};
4646

4747
use egobox_moe::GpMixtureParams;
4848
use ndarray::{Array2, ArrayBase, Data, Ix2};
@@ -140,6 +140,7 @@ impl<SB: SurrogateBuilder> EgorService<SB> {
140140
#[cfg(test)]
141141
mod tests {
142142
use super::*;
143+
use crate::gpmix::spec::*;
143144
use approx::assert_abs_diff_eq;
144145
use ndarray::{array, concatenate, ArrayView2, Axis};
145146

0 commit comments

Comments
 (0)