commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [commons-math] 12/12: Class can be "static" (improves encapsulation).
Date Sun, 22 Mar 2020 15:11:15 GMT
This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git

commit 6b0395898e9469fda20f011ded8dce3f9d0df907
Author: Gilles Sadowski <gilleseran@gmail.com>
AuthorDate: Sun Mar 22 16:09:41 2020 +0100

    Class can be "static" (improves encapsulation).
---
 .../ml/clustering/MiniBatchKMeansClusterer.java      | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/math4/ml/clustering/MiniBatchKMeansClusterer.java
b/src/main/java/org/apache/commons/math4/ml/clustering/MiniBatchKMeansClusterer.java
index d2210f1..701392b 100644
--- a/src/main/java/org/apache/commons/math4/ml/clustering/MiniBatchKMeansClusterer.java
+++ b/src/main/java/org/apache/commons/math4/ml/clustering/MiniBatchKMeansClusterer.java
@@ -119,7 +119,8 @@ public class MiniBatchKMeansClusterer<T extends Clusterable>
         final List<T> pointList = new ArrayList<>(points);
         List<CentroidCluster<T>> clusters = initialCenters(pointList);
 
-        final MiniBatchImprovementEvaluator evaluator = new MiniBatchImprovementEvaluator();
+        final ImprovementEvaluator evaluator = new ImprovementEvaluator(batchSize,
+                                                                        maxNoImprovementTimes);
         for (int i = 0; i < max; i++) {
             clearClustersPoints(clusters);
             final List<T> batchPoints = ListSampler.sample(getRandomGenerator(), pointList,
batchSize);
@@ -238,7 +239,11 @@ public class MiniBatchKMeansClusterer<T extends Clusterable>
      * The evaluator checks whether improvement occurred during the
      * {@link #maxNoImprovementTimes allowed number of successive iterations}.
      */
-    private class MiniBatchImprovementEvaluator {
+    private static class ImprovementEvaluator {
+        /** Batch size. */
+        private final int batchSize;
+        /** Maximum number of iterations during which no improvement is occuring. */
+        private final int maxNoImprovementTimes;
         /** Missing doc. */
         private double ewaInertia = Double.NaN;
         /** Missing doc. */
@@ -247,6 +252,17 @@ public class MiniBatchKMeansClusterer<T extends Clusterable>
         private int noImprovementTimes = 0;
 
         /**
+         * @param batchSize Number of elements for each batch iteration.
+         * @param maxNoImprovementTimes Maximum number of iterations during
+         * which no improvement is occuring.
+         */
+        private ImprovementEvaluator(int batchSize,
+                                     int maxNoImprovementTimes) {
+            this.batchSize = batchSize;
+            this.maxNoImprovementTimes = maxNoImprovementTimes;
+        }
+
+        /**
          * Stopping criterion.
          *
          * @param squareDistance Total square distance from the batch points


Mime
View raw message