Skip to content

Commit

Permalink
fix: Initialize residuals when initializing simplex in Nelder-Mead
Browse files Browse the repository at this point in the history
  • Loading branch information
pnevyk committed Apr 28, 2023
1 parent 141305a commit 5b758a2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/solver/nelder_mead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,16 @@ where

// It is important to return early on error before the point is
// added to the simplex.
let mut error_best = f.apply(x)?;
let mut error_best = f.apply_eval(x, fx)?;
fx_best.copy_from(fx);
errors.push(error_best);
simplex.push(x.clone_owned());

for j in 0..n {
let mut xi = x.clone_owned();
xi[j] = dom.vars()[j].clamp(xi[j] + scale[j]);

let error = match f.apply(&xi) {
let error = match f.apply_eval(&xi, fx) {
Ok(error) => error,
// Do not fail when invalid value is encountered during
// building the simplex. Instead, treat it as infinity so
Expand Down

0 comments on commit 5b758a2

Please sign in to comment.