diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/result/outlier/OrderingFromRelation.java')
-rw-r--r-- | src/de/lmu/ifi/dbs/elki/result/outlier/OrderingFromRelation.java | 52 |
1 files changed, 17 insertions, 35 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/result/outlier/OrderingFromRelation.java b/src/de/lmu/ifi/dbs/elki/result/outlier/OrderingFromRelation.java index 2950a2f8..013be8f9 100644 --- a/src/de/lmu/ifi/dbs/elki/result/outlier/OrderingFromRelation.java +++ b/src/de/lmu/ifi/dbs/elki/result/outlier/OrderingFromRelation.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.result.outlier; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -23,13 +23,11 @@ package de.lmu.ifi.dbs.elki.result.outlier; along with this program. If not, see <http://www.gnu.org/licenses/>. */ -import java.util.Comparator; - import de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs; -import de.lmu.ifi.dbs.elki.database.ids.DBIDRef; import de.lmu.ifi.dbs.elki.database.ids.DBIDUtil; import de.lmu.ifi.dbs.elki.database.ids.DBIDs; -import de.lmu.ifi.dbs.elki.database.relation.Relation; +import de.lmu.ifi.dbs.elki.database.relation.DoubleRelation; +import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; import de.lmu.ifi.dbs.elki.result.OrderingResult; /** @@ -37,38 +35,38 @@ import de.lmu.ifi.dbs.elki.result.OrderingResult; * * @author Erich Schubert * - * @apiviz.uses Relation + * @apiviz.uses DoubleRelation */ public class OrderingFromRelation implements OrderingResult { /** * Outlier scores. */ - protected Relation<Double> scores; + protected DoubleRelation scores; /** * Factor for ascending (+1) and descending (-1) ordering. */ - protected int ascending = +1; - + protected boolean ascending = false; + /** * Constructor for outlier orderings * * @param scores outlier score result * @param ascending Ascending when {@code true}, descending otherwise */ - public OrderingFromRelation(Relation<Double> scores, boolean ascending) { + public OrderingFromRelation(DoubleRelation scores, boolean ascending) { super(); this.scores = scores; - this.ascending = ascending ? +1 : -1; + this.ascending = ascending; } - + /** * Ascending constructor. * * @param scores */ - public OrderingFromRelation(Relation<Double> scores) { - this(scores, true); + public OrderingFromRelation(DoubleRelation scores) { + this(scores, false); } @Override @@ -79,35 +77,19 @@ public class OrderingFromRelation implements OrderingResult { @Override public ArrayModifiableDBIDs iter(DBIDs ids) { ArrayModifiableDBIDs sorted = DBIDUtil.newArray(ids); - sorted.sort(new ImpliedComparator()); + sorted.sort(ascending ? // + new RelationUtil.AscendingByDoubleRelation(scores) // + : new RelationUtil.DescendingByDoubleRelation(scores)); return sorted; } @Override public String getLongName() { - return scores.getLongName()+" Order"; + return scores.getLongName() + " Order"; } @Override public String getShortName() { - return scores.getShortName()+"_order"; - } - - /** - * Internal comparator, accessing the map to sort objects - * - * @author Erich Schubert - * - * @apiviz.exclude - */ - protected final class ImpliedComparator implements Comparator<DBIDRef> { - @Override - public int compare(DBIDRef id1, DBIDRef id2) { - Double k1 = scores.get(id1); - Double k2 = scores.get(id2); - assert (k1 != null); - assert (k2 != null); - return ascending * k2.compareTo(k1); - } + return scores.getShortName() + "_order"; } } |