Hi all,
The "EmptyClusterStrategy" in KMeansPlusPlusClusterer can be reused
MiniBatchKMeansClusterer and other cluster altorithm.
So I think the "EmptyClusterStrategy" should move out from
KMeansPlusPlusClusterer(JIRA issue #MATH-1525).
I am not sure if my design is good or not. I think here should be a
interface:
Solution 1: Explicit indicate the usage by class name and function name.
```java
@FunctionalInterface
public interface ClusterBreeder {
<T extends Clusterable> T newCenterPoint((final
Collection<CentroidCluster<T extends Clusterable>> clusters);
}
...
// Implementations
public LargestVarianceClusterPointBreeder implements ClusterBreeder{...}
public MostPopularClusterPointBreeder implements ClusterBreeder{...}
public FarthestPointBreeder implements ClusterBreeder{...}
...
// Usage
// KMeansPlusPlusClusterer.java
public class KMeansPlusPlusClusterer<T extends Clusterable> extends
Clusterer<T> {
...
private final ClusterBreeder clusterBreeder;
public KMeansPlusPlusClusterer(final int k, final int maxIterations,
final DistanceMeasure measure,
final UniformRandomProvider random,
final ClusterBreeder clusterBreeder) {
...
this.clusterBreeder=clusterBreeder;
}
...
public List<CentroidCluster<T>> cluster(final Collection<T> points) {
...
if (cluster.getPoints().isEmpty()) {
if (clusterBreeder == null) {
throw new
ConvergenceException(LocalizedFormats.EMPTY_CLUSTER_IN_K_MEANS);
} else {
newCenter = clusterBreeder.newCenterPoint(clusters);
}
}
...
}
}
```
Solution2: Declare a more generic interface:
```java
@FunctionalInterface
public interface ClustersPointFinder {
<T extends Clusterable> T find((final Collection<CentroidCluster<T extends
Clusterable>> clusters);
}
...
// Implementations
public LargestVarianceClusterPointFinder implements ClustersPointFinder {...}
public MostPopularClusterPointFinder implements ClustersPointFinder {...}
public FarthestPointFinder implements ClustersPointFinder {...}
```
Thanks,
-CT