diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/NelderMeadTransform.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/NelderMeadTransform.java index 7cace7b92..e94261d7f 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/NelderMeadTransform.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/NelderMeadTransform.java @@ -75,7 +75,7 @@ public class NelderMeadTransform @Override public UnaryOperator create(final MultivariateFunction evaluationFunction, final Comparator comparator, - final DoublePredicate unused) { + final DoublePredicate sa) { return original -> { // The simplex has n + 1 points if dimension is n. final int n = original.getDimension(); @@ -105,7 +105,9 @@ public class NelderMeadTransform -gamma, xWorst, evaluationFunction); - if (comparator.compare(expanded, reflected) < 0) { + if (comparator.compare(expanded, reflected) < 0 || + (sa != null && + sa.test(expanded.getValue() - reflected.getValue()))) { return original.replaceLast(expanded); } else { return original.replaceLast(reflected);