diff options
author | Erich Schubert <erich@debian.org> | 2012-06-02 17:47:03 +0200 |
---|---|---|
committer | Andrej Shadura <andrewsh@debian.org> | 2019-03-09 22:30:32 +0000 |
commit | 593eae6c91717eb9f4ff5088ba460dd4210509c0 (patch) | |
tree | d97e8cefb48773a382542e9e9d4a6796202a044a /src/de/lmu/ifi/dbs/elki/evaluation/clustering/pairsegments/Segment.java | |
parent | e580e42664ca92fbf8792bc39b8d59383db829fe (diff) | |
parent | c36aa2a8fd31ca5e225ff30278e910070cd2c8c1 (diff) |
Import Debian changes 0.5.0~beta2-1
elki (0.5.0~beta2-1) unstable; urgency=low
* New upstream beta release.
* Needs GNU Trove 3, in NEW.
* Build with OpenJDK7, as OpenJDK6 complains.
elki (0.5.0~beta1-1) unstable; urgency=low
* New upstream beta release.
* Needs GNU Trove 3, not yet in Debian (private package)
* Build with OpenJDK7, as OpenJDK6 complains.
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/evaluation/clustering/pairsegments/Segment.java')
-rw-r--r-- | src/de/lmu/ifi/dbs/elki/evaluation/clustering/pairsegments/Segment.java | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/clustering/pairsegments/Segment.java b/src/de/lmu/ifi/dbs/elki/evaluation/clustering/pairsegments/Segment.java new file mode 100644 index 00000000..8ce8fd4a --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/evaluation/clustering/pairsegments/Segment.java @@ -0,0 +1,149 @@ +package de.lmu.ifi.dbs.elki.evaluation.clustering.pairsegments; + +import java.util.Arrays; + +import de.lmu.ifi.dbs.elki.database.ids.DBIDs; + +/** + * A segment represents a set of pairs that share the same clustering + * properties. + * + * As such, for each ring (= clustering), a cluster number (or the constant + * {@link #UNCLUSTERED}) is stored. + */ +public class Segment implements Comparable<Segment> { + /** + * Object is not clustered + */ + public static final int UNCLUSTERED = -1; + + /** + * IDs in segment, for object segments. + */ + protected DBIDs objIDs = null; + + /** + * Size of cluster, in pairs. + */ + protected long pairsize = 0; + + /** + * The cluster numbers in each ring + */ + protected int[] clusterIds; + + public Segment(int clusterings) { + clusterIds = new int[clusterings]; + } + + public long getPairCount() { + return pairsize; + } + + /** + * Constructor. + * + * @param clone Clone of cluster ids + */ + public Segment(int[] clone) { + clusterIds = clone; + } + + /** + * Get cluster number for index idx. + * + * @param idx Index + * @return Cluster number + */ + public int get(int idx) { + return clusterIds[idx]; + } + + /** + * Checks if the segment has a cluster with unpaired objects. Unpaired + * clusters are represented by "0" (0 = all). + * + * @return true when unclustered in at least one dimension. + */ + public boolean isUnpaired() { + for(int id : clusterIds) { + if(id == UNCLUSTERED) { + return true; + } + } + return false; + } + + /** + * Check if this segment contains the pairs that are never clustered by any of + * the clusterings (all 0). + * + * @return true when unclustered everywhere + */ + public boolean isNone() { + for(int id : clusterIds) { + if(id != UNCLUSTERED) { + return false; + } + } + return true; + } + + /** + * Returns the index of the first clustering having an unpaired cluster, or -1 + * no unpaired cluster exists. + * + * @return clustering id or -1 + */ + public int getUnpairedClusteringIndex() { + for(int index = 0; index < clusterIds.length; index++) { + if(clusterIds[index] == UNCLUSTERED) { + return index; + } + } + return -1; + } + + /** + * Get the DBIDs of objects contained in this segment. + * + * @return the segment IDs + */ + public DBIDs getDBIDs() { + return objIDs; + } + + @Override + public boolean equals(Object obj) { + if(!(Segment.class.isInstance(obj))) { + return false; + } + Segment other = (Segment) obj; + return Arrays.equals(clusterIds, other.clusterIds); + } + + @Override + public int hashCode() { + return Arrays.hashCode(clusterIds); + } + + @Override + public int compareTo(Segment sid) { + for(int i = 0; i < clusterIds.length; i++) { + final int a = this.clusterIds[i]; + final int b = sid.clusterIds[i]; + if(a != b) { + if(a * b > 0) { + // Regular comparison + return (a < b) ? -1 : +1; + // return (a < b) ? +1 : -1; + } + else { + // Inverse, to sort negative last + return (a < b) ? +1 : -1; + } + } + } + return 0; + } +}
\ No newline at end of file |