Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log Egor configuration #159

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ego/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ serde_json = "1"
typetag = { version = "0.2" }
dyn-clonable = { version = "0.9" }

derive_more = "0.99"

[dev-dependencies]
criterion = "0.5"
approx = "0.4"
Expand Down
4 changes: 4 additions & 0 deletions ego/src/criteria/ei.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ pub struct ExpectedImprovement;

#[typetag::serde]
impl InfillCriterion for ExpectedImprovement {
fn name(&self) -> &'static str {
"EI"
}

/// Compute EI infill criterion at given `x` point using the surrogate model `obj_model`
/// and the current minimum of the objective function.
fn value(
Expand Down
9 changes: 9 additions & 0 deletions ego/src/criteria/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use ndarray::{Array1, ArrayView2};
#[clonable]
#[typetag::serde(tag = "type")]
pub trait InfillCriterion: Clone + Sync {
/// Name of the infill criterion
fn name(&self) -> &'static str;

/// Criterion value at given point x with regards to given
/// surrogate of the objectove function, the current found min
/// and an optional acaling factor
Expand All @@ -37,3 +40,9 @@ pub trait InfillCriterion: Clone + Sync {
/// Scaling factor computation
fn scaling(&self, x: &ArrayView2<f64>, obj_model: &dyn MixtureGpSurrogate, f_min: f64) -> f64;
}

impl std::fmt::Debug for dyn InfillCriterion {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.name())
}
}
9 changes: 9 additions & 0 deletions ego/src/criteria/wb2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ pub struct WB2Criterion(pub Option<f64>);

#[typetag::serde]
impl InfillCriterion for WB2Criterion {
fn name(&self) -> &'static str {
if self.0.is_some() {
"WB2S"
} else {
"WB2"
}
}

/// Compute WBS2 infill criterion at given `x` point using the surrogate model `obj_model`
/// and the current minimum of the objective function.
fn value(
Expand Down Expand Up @@ -63,6 +71,7 @@ pub(crate) fn compute_wb2s_scale(
) -> f64 {
let ratio = 100.; // TODO: make it a parameter
let ei_x = x.map_axis(Axis(1), |xi| {
let xi = xi.as_standard_layout();
let ei = EI.value(xi.as_slice().unwrap(), obj_model, f_min, None);
ei
});
Expand Down
1 change: 1 addition & 0 deletions ego/src/egor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ impl<O: GroupFunc, SB: SurrogateBuilder> Egor<O, SB> {
/// Runs the (constrained) optimization of the objective function.
pub fn run(&self) -> Result<OptimResult<f64>> {
let xtypes = self.solver.config.xtypes.clone();
info!("{:?}", self.solver.config);

let result = Executor::new(self.fobj.clone(), self.solver.clone()).run()?;
info!("{}", result);
Expand Down
2 changes: 1 addition & 1 deletion ego/src/egor_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ndarray::Array2;
use serde::{Deserialize, Serialize};

/// Egor optimizer configuration
#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct EgorConfig {
/// 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)
Expand Down
13 changes: 8 additions & 5 deletions ego/src/egor_solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ where
fobj: &mut Problem<O>,
state: EgorState<f64>,
) -> std::result::Result<(EgorState<f64>, Option<KV>), argmin::core::Error> {
info!(
debug!(
"********* Start iteration {}/{}",
state.get_iter() + 1,
state.get_max_iters()
Expand Down Expand Up @@ -695,7 +695,7 @@ where
});

let (obj_model, cstr_models) = models.split_first().unwrap();
info!("... surrogates trained");
debug!("... surrogates trained");

match self.find_best_point(
x_data,
Expand Down Expand Up @@ -746,16 +746,19 @@ where
f_min: f64,
) -> (f64, Array1<f64>, f64) {
let npts = (100 * self.xlimits.nrows()).min(1000);
info!("Use {npts} to evaluate scalers");
debug!("Use {npts} points to evaluate scalings");
let scaling_points = sampling.sample(npts);
let scale_infill_obj =
self.compute_infill_obj_scale(&scaling_points.view(), obj_model, f_min);
info!("Infill criterion scaler is updated to {}", scale_infill_obj);
info!(
"Infill criterion scaling is updated to {}",
scale_infill_obj
);
let scale_cstr = if cstr_models.is_empty() {
Array1::zeros((0,))
} else {
let scale_cstr = compute_cstr_scales(&scaling_points.view(), cstr_models);
info!("Constraints scaler is updated to {}", scale_cstr);
info!("Constraints scalings is updated to {}", scale_cstr);
scale_cstr
};
let scale_ic =
Expand Down
Loading