diff --git a/src/sampler/tpe/multivariate.rs b/src/sampler/tpe/multivariate.rs index 502125f..cb9c4e3 100644 --- a/src/sampler/tpe/multivariate.rs +++ b/src/sampler/tpe/multivariate.rs @@ -205,7 +205,7 @@ pub enum ConstantLiarStrategy { /// let y = FloatParam::new(-5.0, 5.0); /// /// study -/// .optimize(30, |trial: &mut optimizer::Trial| { +/// .optimize(50, |trial: &mut optimizer::Trial| { /// let xv = x.suggest(trial)?; /// let yv = y.suggest(trial)?; /// Ok::<_, optimizer::Error>(xv * xv + yv * yv) diff --git a/src/study.rs b/src/study.rs index 2fcba0e..0769f83 100644 --- a/src/study.rs +++ b/src/study.rs @@ -1517,12 +1517,12 @@ where // Collect all parameter IDs across trials. let all_param_ids: BTreeSet<_> = complete.iter().flat_map(|t| t.params.keys()).collect(); - let mut scores: Vec<(String, f64)> = Vec::new(); + let mut scores: Vec<(String, f64)> = Vec::with_capacity(all_param_ids.len()); for ¶m_id in &all_param_ids { // Collect (param_value_f64, objective_f64) for trials that have this param. - let mut param_vals = Vec::new(); - let mut obj_vals = Vec::new(); + let mut param_vals = Vec::with_capacity(complete.len()); + let mut obj_vals = Vec::with_capacity(complete.len()); for trial in &complete { if let Some(pv) = trial.params.get(param_id) { @@ -1645,8 +1645,8 @@ where } // Build feature matrix (only trials that have all parameters). - let mut data = Vec::new(); - let mut targets = Vec::new(); + let mut data = Vec::with_capacity(complete.len()); + let mut targets = Vec::with_capacity(complete.len()); for trial in &complete { let mut row = Vec::with_capacity(all_param_ids.len());