Skip to content

Commit

Permalink
Rename n_iter in max_iters
Browse files Browse the repository at this point in the history
  • Loading branch information
relf committed Nov 19, 2023
1 parent 5f9b401 commit 1ee73df
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions doe/src/lhs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ impl<F: Float, R: Rng + Clone> Lhs<F, R> {
lhs.mapv(F::cast)
}

fn _maximin_lhs(&self, ns: usize, centered: bool, n_iter: usize) -> Array2<F> {
fn _maximin_lhs(&self, ns: usize, centered: bool, max_iters: usize) -> Array2<F> {
let mut max_dist = F::zero();
let mut lhs = self._classic_lhs(ns);
for _ in 0..n_iter {
for _ in 0..max_iters {
if centered {
lhs = self._centered_lhs(ns);
} else {
Expand Down
2 changes: 1 addition & 1 deletion ego/examples/ackley.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() {
.regression_spec(RegressionSpec::CONSTANT)
.correlation_spec(CorrelationSpec::ABSOLUTEEXPONENTIAL)
.infill_strategy(InfillStrategy::WB2S)
.n_iter(200)
.max_iters(200)
.target(5e-1)
})
.min_within(&xlimits)
Expand Down
4 changes: 2 additions & 2 deletions ego/examples/mopta08.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ fn main() -> anyhow::Result<()> {
let dim = args.dim;
let outdir = args.outdir;
let n_doe = 2 * dim;
let n_iter = 2 * dim;
let max_iters = 2 * dim;
const N_CSTR: usize = 68;
let cstr_tol = Array1::from_elem(N_CSTR, 1e-4);
let kpls_dim = 3;
Expand All @@ -269,7 +269,7 @@ fn main() -> anyhow::Result<()> {
.n_clusters(1)
.n_start(50)
.n_doe(n_doe)
.n_iter(n_iter)
.max_iters(max_iters)
.regression_spec(RegressionSpec::CONSTANT)
.correlation_spec(CorrelationSpec::SQUAREDEXPONENTIAL)
.infill_optimizer(InfillOptimizer::Slsqp)
Expand Down
2 changes: 1 addition & 1 deletion ego/examples/rosenbrock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn rosenbrock(x: &ArrayView2<f64>) -> Array2<f64> {
fn main() {
let xlimits = array![[-2., 2.], [-2., 2.]];
let res = EgorBuilder::optimize(rosenbrock)
.configure(|config| config.n_iter(100).target(1e-2))
.configure(|config| config.max_iters(100).target(1e-2))
.min_within(&xlimits)
.run()
.expect("Minimize failure");
Expand Down
36 changes: 18 additions & 18 deletions ego/src/egor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//! .infill_strategy(InfillStrategy::EI)
//! .n_doe(10)
//! .target(1e-1)
//! .n_iter(30))
//! .max_iters(30))
//! .min_within(&xlimits)
//! .run()
//! .expect("Rosenbrock minimization");
Expand Down Expand Up @@ -81,7 +81,7 @@
//! .infill_strategy(InfillStrategy::EI)
//! .infill_optimizer(InfillOptimizer::Cobyla)
//! .doe(&doe)
//! .n_iter(40)
//! .max_iters(40)
//! .target(-5.5080))
//! .min_within(&xlimits)
//! .run()
Expand Down Expand Up @@ -262,7 +262,7 @@ mod tests {
cfg.infill_strategy(InfillStrategy::EI)
.regression_spec(RegressionSpec::QUADRATIC)
.correlation_spec(CorrelationSpec::ALL)
.n_iter(30)
.max_iters(30)
.doe(&initial_doe)
.target(-15.1)
.outdir("target/tests")
Expand All @@ -282,7 +282,7 @@ mod tests {
let res = EgorBuilder::optimize(xsinx)
.configure(|config| {
config
.n_iter(20)
.max_iters(20)
.regression_spec(RegressionSpec::ALL)
.correlation_spec(CorrelationSpec::ALL)
})
Expand All @@ -297,7 +297,7 @@ mod tests {
#[serial]
fn test_xsinx_auto_clustering_egor_builder() {
let res = EgorBuilder::optimize(xsinx)
.configure(|config| config.n_clusters(0).n_iter(20))
.configure(|config| config.n_clusters(0).max_iters(20))
.min_within(&array![[0.0, 25.0]])
.run()
.expect("Egor with auto clustering should minimize xsinx");
Expand All @@ -313,7 +313,7 @@ mod tests {
let res = EgorBuilder::optimize(xsinx)
.configure(|config| {
config
.n_iter(15)
.max_iters(15)
.doe(&doe)
.outdir("target/tests")
.random_seed(42)
Expand All @@ -327,7 +327,7 @@ mod tests {
let res = EgorBuilder::optimize(xsinx)
.configure(|config| {
config
.n_iter(5)
.max_iters(5)
.outdir("target/tests")
.hot_start(true)
.random_seed(42)
Expand Down Expand Up @@ -359,7 +359,7 @@ mod tests {
.configure(|config| {
config
.doe(&doe)
.n_iter(100)
.max_iters(100)
.regression_spec(RegressionSpec::ALL)
.correlation_spec(CorrelationSpec::ALL)
.target(1e-2)
Expand Down Expand Up @@ -408,7 +408,7 @@ mod tests {
.with_rng(Xoshiro256Plus::seed_from_u64(42))
.sample(3);
let res = EgorBuilder::optimize(f_g24)
.configure(|config| config.n_cstr(2).doe(&doe).n_iter(20).random_seed(42))
.configure(|config| config.n_cstr(2).doe(&doe).max_iters(20).random_seed(42))
.min_within(&xlimits)
.run()
.expect("Minimize failure");
Expand All @@ -435,7 +435,7 @@ mod tests {
.qei_strategy(QEiStrategy::KrigingBeliever)
.doe(&doe)
.target(-5.5030)
.n_iter(30)
.max_iters(30)
.random_seed(42)
})
.min_within(&xlimits)
Expand All @@ -459,15 +459,15 @@ mod tests {
#[test]
#[serial]
fn test_mixsinx_ei_mixint_egor_builder() {
let n_iter = 30;
let max_iters = 30;
let doe = array![[0.], [7.], [25.]];
let xtypes = vec![XType::Int(0, 25)];

let res = EgorBuilder::optimize(mixsinx)
.configure(|config| {
config
.doe(&doe)
.n_iter(n_iter)
.max_iters(max_iters)
.target(-15.1)
.infill_strategy(InfillStrategy::EI)
.random_seed(42)
Expand All @@ -481,15 +481,15 @@ mod tests {
#[test]
#[serial]
fn test_mixsinx_reclustering_mixint_egor_builder() {
let n_iter = 30;
let max_iters = 30;
let doe = array![[0.], [7.], [25.]];
let xtypes = vec![XType::Int(0, 25)];

let res = EgorBuilder::optimize(mixsinx)
.configure(|config| {
config
.doe(&doe)
.n_iter(n_iter)
.max_iters(max_iters)
.target(-15.1)
.infill_strategy(InfillStrategy::EI)
.random_seed(42)
Expand All @@ -503,15 +503,15 @@ mod tests {
#[test]
#[serial]
fn test_mixsinx_wb2_mixint_egor_builder() {
let n_iter = 30;
let max_iters = 30;
let xtypes = vec![XType::Int(0, 25)];

let res = EgorBuilder::optimize(mixsinx)
.configure(|config| {
config
.regression_spec(egobox_moe::RegressionSpec::CONSTANT)
.correlation_spec(egobox_moe::CorrelationSpec::SQUAREDEXPONENTIAL)
.n_iter(n_iter)
.max_iters(max_iters)
.random_seed(42)
})
.min_within_mixint_space(&xtypes)
Expand Down Expand Up @@ -549,7 +549,7 @@ mod tests {
let mut builder = env_logger::Builder::from_env(env);
let builder = builder.target(env_logger::Target::Stdout);
builder.try_init().ok();
let n_iter = 10;
let max_iters = 10;
let xtypes = vec![
XType::Cont(-5., 5.),
XType::Enum(3),
Expand All @@ -562,7 +562,7 @@ mod tests {
config
.regression_spec(egobox_moe::RegressionSpec::CONSTANT)
.correlation_spec(egobox_moe::CorrelationSpec::SQUAREDEXPONENTIAL)
.n_iter(n_iter)
.max_iters(max_iters)
.random_seed(42)
})
.min_within_mixint_space(&xtypes)
Expand Down
16 changes: 8 additions & 8 deletions ego/src/egor_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use serde::{Deserialize, Serialize};
/// Egor optimizer configuration
#[derive(Clone, Serialize, Deserialize)]
pub struct EgorConfig {
/// Number of function iterations allocated to find the optimum (aka iteration budget)
/// Note 1 : The number of cost function evaluations is deduced using the following formula (n_doe + n_iter)
/// Note 2 : When q_points > 1, the number of cost function evaluations is (n_doe + n_iter * q_points)
/// Max number of function iterations allocated to find the optimum (aka iteration budget)
/// Note 1 : The number of cost function evaluations is deduced using the following formula (n_doe + max_iters)
/// Note 2 : When q_points > 1, the number of cost function evaluations is (n_doe + max_iters * q_points)
/// is is an upper bounds as some points may be rejected as being to close to previous ones.
pub(crate) n_iter: usize,
pub(crate) max_iters: usize,
/// Number of starts for multistart approach used for hyperparameters optimization
pub(crate) n_start: usize,
/// Number of points returned by EGO iteration (aka qEI Multipoint strategy)
Expand Down Expand Up @@ -64,7 +64,7 @@ pub struct EgorConfig {
impl Default for EgorConfig {
fn default() -> Self {
EgorConfig {
n_iter: 20,
max_iters: 20,
n_start: 20,
q_points: 1,
n_doe: 0,
Expand Down Expand Up @@ -94,9 +94,9 @@ impl EgorConfig {
self
}

/// Sets allowed number of evaluation of the function under optimization
pub fn n_iter(mut self, n_iter: usize) -> Self {
self.n_iter = n_iter;
/// Sets max number of iterations to optimize the objective function
pub fn max_iters(mut self, max_iters: usize) -> Self {
self.max_iters = max_iters;
self
}

Expand Down
2 changes: 1 addition & 1 deletion ego/src/egor_solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ where
.clusterings(clusterings)
.sampling(sampling);
initial_state.doe_size = doe.nrows();
initial_state.max_iters = self.config.n_iter as u64;
initial_state.max_iters = self.config.max_iters as u64;
initial_state.added = doe.nrows();
initial_state.no_point_added_retries = no_point_added_retries;
initial_state.cstr_tol = self
Expand Down
6 changes: 3 additions & 3 deletions ego/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
//!
//! // We ask for 10 evaluations of the objective function to get the result
//! let res = EgorBuilder::optimize(xsinx)
//! .configure(|config| config.n_iter(10))
//! .configure(|config| config.max_iters(10))
//! .min_within(&array![[0.0, 25.0]])
//! .run()
//! .expect("xsinx minimized");
Expand Down Expand Up @@ -64,7 +64,7 @@
//! }
//! }
//!
//! let n_iter = 10;
//! let max_iters = 10;
//! let doe = array![[0.], [7.], [25.]]; // the initial doe
//!
//! // We define input as being integer
Expand All @@ -73,7 +73,7 @@
//! let res = EgorBuilder::optimize(mixsinx)
//! .configure(|config|
//! config.doe(&doe) // we pass the initial doe
//! .n_iter(n_iter)
//! .max_iters(max_iters)
//! .infill_strategy(InfillStrategy::EI)
//! .random_seed(42))
//! .min_within_mixint_space(&xtypes) // We build a mixed-integer optimizer
Expand Down
10 changes: 5 additions & 5 deletions src/egor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,16 @@ impl Egor {
/// This function finds the minimum of a given function `fun`
///
/// # Parameters
/// n_iter:
/// the iteration budget, number of fun calls is n_doe + q_points * n_iter.
/// max_iters:
/// the iteration budget, number of fun calls is n_doe + q_points * max_iters.
///
/// # Returns
/// optimization result
/// x_opt (array[1, nx]): x value where fun is at its minimum subject to constraint
/// y_opt (array[1, nx]): fun(x_opt)
///
#[pyo3(signature = (n_iter = 20))]
fn minimize(&self, py: Python, n_iter: usize) -> PyResult<OptimResult> {
#[pyo3(signature = (max_iters = 20))]
fn minimize(&self, py: Python, max_iters: usize) -> PyResult<OptimResult> {
let fun = self.fun.to_object(py);
let obj = move |x: &ArrayView2<f64>| -> Array2<f64> {
Python::with_gil(|py| {
Expand Down Expand Up @@ -309,7 +309,7 @@ impl Egor {
.configure(|config| {
let mut config = config
.n_cstr(self.n_cstr)
.n_iter(n_iter)
.max_iters(max_iters)
.n_start(self.n_start)
.n_doe(self.n_doe)
.cstr_tol(&cstr_tol)
Expand Down

0 comments on commit 1ee73df

Please sign in to comment.