Class can be "static" (improves encapsulation).
This commit is contained in:
parent
7741ddb814
commit
6b0395898e
|
@ -119,7 +119,8 @@ public class MiniBatchKMeansClusterer<T extends Clusterable>
|
||||||
final List<T> pointList = new ArrayList<>(points);
|
final List<T> pointList = new ArrayList<>(points);
|
||||||
List<CentroidCluster<T>> clusters = initialCenters(pointList);
|
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++) {
|
for (int i = 0; i < max; i++) {
|
||||||
clearClustersPoints(clusters);
|
clearClustersPoints(clusters);
|
||||||
final List<T> batchPoints = ListSampler.sample(getRandomGenerator(), pointList, batchSize);
|
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
|
* The evaluator checks whether improvement occurred during the
|
||||||
* {@link #maxNoImprovementTimes allowed number of successive iterations}.
|
* {@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. */
|
/** Missing doc. */
|
||||||
private double ewaInertia = Double.NaN;
|
private double ewaInertia = Double.NaN;
|
||||||
/** Missing doc. */
|
/** Missing doc. */
|
||||||
|
@ -246,6 +251,17 @@ public class MiniBatchKMeansClusterer<T extends Clusterable>
|
||||||
/** Missing doc. */
|
/** Missing doc. */
|
||||||
private int noImprovementTimes = 0;
|
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.
|
* Stopping criterion.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue