Hi. 2020-03-18 15:10 UTC+01:00, chentao...@qq.com <chentao...@qq.com>: > Hi, > I have created a PR to show my aim: > https://github.com/apache/commons-math/pull/126/files
Am I correct that the implementations of "ClustersPointExtractor" modify the argument of the "extract" method? If so, that seems quite unsafe. I would not expect this behaviour in a public API. Unless I missed some point, I'd ask again that the API be reviewed *before* implementing several features (such as those "extractors") on top of something that does not look right. Best regards, Gilles > >>Hello. >> >>Le mer. 11 mars 2020 à 07:28, chentao...@qq.com <chentao...@qq.com> a écrit >> : >>> >>> 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 can't say either; please provide more context/explanation >>about the excerpts below. >> >>> 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); >>> } >> >>What is a "Breeder"? >>This seems to further complicates the matter; what is a "center" (if there >>can be old and new ones). > > I mean a method to create a new Cluster from exists clusters. > >> >>Regards, >>Gilles >> >>> ... >>> // 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 --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org