From 66a775c9feb7dcf00c28a16b7a365af4372886f8 Mon Sep 17 00:00:00 2001 From: Gilles Date: Sat, 11 Jun 2016 20:08:32 +0200 Subject: [PATCH 1/3] MATH-1376 Fixed incorrect iteration number (variable was not updated). Thanks to Thomas Weise for the report and fix. --- .../math4/optim/nonlinear/scalar/noderiv/SimplexOptimizer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/SimplexOptimizer.java b/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/SimplexOptimizer.java index c5bd08bb4..cd1ca1dd2 100644 --- a/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/SimplexOptimizer.java +++ b/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/SimplexOptimizer.java @@ -159,7 +159,8 @@ public class SimplexOptimizer extends MultivariateOptimizer { int iteration = 0; final ConvergenceChecker checker = getConvergenceChecker(); while (true) { - if (getIterations() > 0) { + iteration = getIterations(); + if (iteration > 0) { boolean converged = true; for (int i = 0; i < simplex.getSize(); i++) { PointValuePair prev = previous[i]; From a6a48cfd370b226955a531e678016db414ebeed9 Mon Sep 17 00:00:00 2001 From: Gilles Date: Sat, 11 Jun 2016 20:31:44 +0200 Subject: [PATCH 2/3] MATH-1377 Short-circuit unnecessary computations. --- .../optim/nonlinear/scalar/noderiv/SimplexOptimizer.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/SimplexOptimizer.java b/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/SimplexOptimizer.java index cd1ca1dd2..9658944a1 100644 --- a/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/SimplexOptimizer.java +++ b/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/SimplexOptimizer.java @@ -166,6 +166,11 @@ public class SimplexOptimizer extends MultivariateOptimizer { PointValuePair prev = previous[i]; converged = converged && checker.converged(iteration, prev, simplex.getPoint(i)); + + if (!converged) { + // Short circuit, since "converged" will stay "false". + break; + } } if (converged) { // We have found an optimum. From 65efb3d3dbd6d38ed9cf23ec7a3749d865ec8517 Mon Sep 17 00:00:00 2001 From: Gilles Date: Sat, 11 Jun 2016 20:34:47 +0200 Subject: [PATCH 3/3] Update "changes.xml". --- src/changes/changes.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 42ba8d524..e8dfc2bbb 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -54,6 +54,12 @@ If the output is not quite correct, check for invisible trailing spaces! + + "SimplexOptimizer": Slight performance improvement. + + + "SimplexOptimizer": Wrong value of iteration number was passed to the convergence checker. + Major refactoring of package "o.a.c.m.random".