You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2020/03/07 19:45:04 UTC
[commons-math] branch master updated (4d5983a -> d64d4c9)
This is an automated email from the ASF dual-hosted git repository.
erans pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git.
from 4d5983a Update userguide code examples.
new 16c8f3b MATH-1516: Interface for ranking a list of clusters.
new 69b9223 Unused methods.
new d64d4c9 Track changes.
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/changes/changes.xml | 3 ++
.../{Clusterable.java => ClusterRanking.java} | 21 +++++++----
.../clustering/MultiKMeansPlusPlusClusterer.java | 44 ++++------------------
.../evaluation/SumOfClusterVariances.java | 9 ++++-
4 files changed, 33 insertions(+), 44 deletions(-)
copy src/main/java/org/apache/commons/math4/ml/clustering/{Clusterable.java => ClusterRanking.java} (65%)
[commons-math] 02/03: Unused methods.
Posted by er...@apache.org.
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 69b92235a090e77e1a62c89c6ce0d8b68a72b3b7
Author: Gilles <gi...@harfang.homelinux.org>
AuthorDate: Sat Mar 7 20:38:09 2020 +0100
Unused methods.
---
.../clustering/MultiKMeansPlusPlusClusterer.java | 25 ----------------------
1 file changed, 25 deletions(-)
diff --git a/src/main/java/org/apache/commons/math4/ml/clustering/MultiKMeansPlusPlusClusterer.java b/src/main/java/org/apache/commons/math4/ml/clustering/MultiKMeansPlusPlusClusterer.java
index e1af3af..32b358c 100644
--- a/src/main/java/org/apache/commons/math4/ml/clustering/MultiKMeansPlusPlusClusterer.java
+++ b/src/main/java/org/apache/commons/math4/ml/clustering/MultiKMeansPlusPlusClusterer.java
@@ -67,31 +67,6 @@ public class MultiKMeansPlusPlusClusterer<T extends Clusterable> extends Cluster
}
/**
- * Returns the embedded k-means clusterer used by this instance.
- * @return the embedded clusterer
- */
- public KMeansPlusPlusClusterer<T> getClusterer() {
- return clusterer;
- }
-
- /**
- * Returns the number of trials this instance will do.
- * @return the number of trials
- */
- public int getNumTrials() {
- return numTrials;
- }
-
- /**
- * Returns the {@link ClusterEvaluator} used to determine the "best" clustering.
- * @return the used {@link ClusterEvaluator}
- * @since 3.3
- */
- public ClusterEvaluator<T> getClusterEvaluator() {
- return evaluator;
- }
-
- /**
* Runs the K-means++ clustering algorithm.
*
* @param points the points to cluster
[commons-math] 01/03: MATH-1516: Interface for ranking a list of
clusters.
Posted by er...@apache.org.
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 16c8f3b49623ab0a325d152e80f843a740da57dd
Author: Gilles <gi...@harfang.homelinux.org>
AuthorDate: Sat Mar 7 20:32:07 2020 +0100
MATH-1516: Interface for ranking a list of clusters.
"MultiKMeansPlusPlusClusterer" updated to use the interface.
---
.../math4/ml/clustering/ClusterRanking.java | 39 ++++++++++++++++++++++
.../clustering/MultiKMeansPlusPlusClusterer.java | 19 +++++------
.../evaluation/SumOfClusterVariances.java | 9 ++++-
3 files changed, 55 insertions(+), 12 deletions(-)
diff --git a/src/main/java/org/apache/commons/math4/ml/clustering/ClusterRanking.java b/src/main/java/org/apache/commons/math4/ml/clustering/ClusterRanking.java
new file mode 100644
index 0000000..a6c87d7
--- /dev/null
+++ b/src/main/java/org/apache/commons/math4/ml/clustering/ClusterRanking.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.math4.ml.clustering;
+
+import java.util.List;
+
+/**
+ * Evaluates the quality of a set of clusters.
+ * It is assumed that
+ * <ul>
+ * <li>rank is positive,</li>
+ * <li>higher rank means better clustering.</li>
+ * </ul>
+ */
+@FunctionalInterface
+public interface ClusterRanking<T extends Clusterable> {
+ /**
+ * Computes the rank (higher is better).
+ *
+ * @param clusters Clusters to be evaluated.
+ * @return the rank of the provided {@code clusters}.
+ */
+ double compute(List<? extends Cluster<T>> clusters);
+}
diff --git a/src/main/java/org/apache/commons/math4/ml/clustering/MultiKMeansPlusPlusClusterer.java b/src/main/java/org/apache/commons/math4/ml/clustering/MultiKMeansPlusPlusClusterer.java
index 61606c8..e1af3af 100644
--- a/src/main/java/org/apache/commons/math4/ml/clustering/MultiKMeansPlusPlusClusterer.java
+++ b/src/main/java/org/apache/commons/math4/ml/clustering/MultiKMeansPlusPlusClusterer.java
@@ -40,7 +40,7 @@ public class MultiKMeansPlusPlusClusterer<T extends Clusterable> extends Cluster
private final int numTrials;
/** The cluster evaluator to use. */
- private final ClusterEvaluator<T> evaluator;
+ private final ClusterRanking<T> evaluator;
/** Build a clusterer.
* @param clusterer the k-means clusterer to use
@@ -59,7 +59,7 @@ public class MultiKMeansPlusPlusClusterer<T extends Clusterable> extends Cluster
*/
public MultiKMeansPlusPlusClusterer(final KMeansPlusPlusClusterer<T> clusterer,
final int numTrials,
- final ClusterEvaluator<T> evaluator) {
+ final ClusterRanking<T> evaluator) {
super(clusterer.getDistanceMeasure());
this.clusterer = clusterer;
this.numTrials = numTrials;
@@ -108,7 +108,7 @@ public class MultiKMeansPlusPlusClusterer<T extends Clusterable> extends Cluster
// at first, we have not found any clusters list yet
List<CentroidCluster<T>> best = null;
- double bestVarianceSum = Double.POSITIVE_INFINITY;
+ double bestRank = Double.NEGATIVE_INFINITY;
// do several clustering trials
for (int i = 0; i < numTrials; ++i) {
@@ -116,20 +116,17 @@ public class MultiKMeansPlusPlusClusterer<T extends Clusterable> extends Cluster
// compute a clusters list
List<CentroidCluster<T>> clusters = clusterer.cluster(points);
- // compute the variance of the current list
- final double varianceSum = evaluator.score(clusters);
+ // compute the rank of the current list
+ final double rank = evaluator.compute(clusters);
- if (evaluator.isBetterScore(varianceSum, bestVarianceSum)) {
+ if (rank > bestRank) {
// this one is the best we have found so far, remember it
- best = clusters;
- bestVarianceSum = varianceSum;
+ best = clusters;
+ bestRank = rank;
}
-
}
// return the best clusters list found
return best;
-
}
-
}
diff --git a/src/main/java/org/apache/commons/math4/ml/clustering/evaluation/SumOfClusterVariances.java b/src/main/java/org/apache/commons/math4/ml/clustering/evaluation/SumOfClusterVariances.java
index 0e3d0e5..14a82b7 100644
--- a/src/main/java/org/apache/commons/math4/ml/clustering/evaluation/SumOfClusterVariances.java
+++ b/src/main/java/org/apache/commons/math4/ml/clustering/evaluation/SumOfClusterVariances.java
@@ -21,6 +21,7 @@ import java.util.List;
import org.apache.commons.math4.ml.clustering.Cluster;
import org.apache.commons.math4.ml.clustering.Clusterable;
+import org.apache.commons.math4.ml.clustering.ClusterRanking;
import org.apache.commons.math4.ml.distance.DistanceMeasure;
import org.apache.commons.math4.stat.descriptive.moment.Variance;
@@ -35,7 +36,8 @@ import org.apache.commons.math4.stat.descriptive.moment.Variance;
* @param <T> the type of the clustered points
* @since 3.3
*/
-public class SumOfClusterVariances<T extends Clusterable> extends ClusterEvaluator<T> {
+public class SumOfClusterVariances<T extends Clusterable> extends ClusterEvaluator<T>
+ implements ClusterRanking<T> {
/**
*
@@ -66,4 +68,9 @@ public class SumOfClusterVariances<T extends Clusterable> extends ClusterEvaluat
return varianceSum;
}
+ /** {@inheritDoc} */
+ @Override
+ public double compute(List<? extends Cluster<T>> clusters) {
+ return 1d / score(clusters);
+ }
}
[commons-math] 03/03: Track changes.
Posted by er...@apache.org.
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 d64d4c9c02ae487e90e23d40f945cf78991ff1e0
Author: Gilles <gi...@harfang.homelinux.org>
AuthorDate: Sat Mar 7 20:42:25 2020 +0100
Track changes.
---
src/changes/changes.xml | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index cd27ece..d8ff913 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -54,6 +54,9 @@ If the output is not quite correct, check for invisible trailing spaces!
</release>
<release version="4.0" date="XXXX-XX-XX" description="">
+ <action dev="erans" type="add" issue="MATH-1516">
+ Interface for ranking a list of clusters.
+ </action>
<action dev="kinow" type="update" issue="MATH-1408">
Do not use exceptions for control flow
</action>