From 97462b1a1b6f64ab10e06db331d5b6762d979aab Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Tue, 24 Aug 2021 01:18:16 +0200 Subject: [PATCH] MATH-1622: Simulated annealing variant of "MultiDirectionalTransform". --- .../noderiv/MultiDirectionalTransform.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/MultiDirectionalTransform.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/MultiDirectionalTransform.java index 28d6c5dad..b6f2a73ee 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/MultiDirectionalTransform.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/MultiDirectionalTransform.java @@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.analysis.MultivariateFunction; import org.apache.commons.math4.legacy.optim.PointValuePair; /** - * Multi-directional search method. + * Multi-directional search method. */ public class MultiDirectionalTransform implements Simplex.TransformFactory { @@ -71,7 +71,7 @@ public class MultiDirectionalTransform @Override public UnaryOperator create(final MultivariateFunction evaluationFunction, final Comparator comparator, - final DoublePredicate unused) { + final DoublePredicate sa) { return original -> { final PointValuePair best = original.get(0); @@ -90,9 +90,19 @@ public class MultiDirectionalTransform evaluationFunction); final PointValuePair expandedBest = expandedSimplex.get(0); - return comparator.compare(reflectedBest, expandedBest) < 0 ? - reflectedSimplex : - expandedSimplex; + if (comparator.compare(expandedBest, reflectedBest) < 0) { + return expandedSimplex; + } else if (sa != null && + sa.test(expandedBest.getValue() - reflectedBest.getValue())) { + // SA hybridation branch (not part of Torczon's algorithm): + // Create a simplex that contains + // * the reflected simplex's best point (since it is the + // best point overall), and + // * the expanded simplex's points (except its best point). + return reflectedSimplex.replaceLast(expandedSimplex.asList(1, expandedSimplex.getSize())); + } else { + return reflectedSimplex; + } } else { // Compute the contracted simplex. return original.shrink(sigma, evaluationFunction);