Skip to content

Commit

Permalink
Class can be "static" (improves encapsulation).
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilles Sadowski committed Mar 22, 2020
1 parent 7741ddb commit 6b03958
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ public List<CentroidCluster<T>> cluster(final Collection<T> points) {
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);
Expand Down Expand Up @@ -238,14 +239,29 @@ private double addToNearestCentroidCluster(final T point,
* 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. */
private double ewaInertiaMin = Double.POSITIVE_INFINITY;
/** Missing doc. */
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.
*
Expand Down

0 comments on commit 6b03958

Please sign in to comment.