summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/evaluation/scores
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/evaluation/scores')
-rw-r--r--src/de/lmu/ifi/dbs/elki/evaluation/scores/AbstractScoreEvaluation.java55
-rw-r--r--src/de/lmu/ifi/dbs/elki/evaluation/scores/AveragePrecisionEvaluation.java76
-rw-r--r--src/de/lmu/ifi/dbs/elki/evaluation/scores/MaximumF1Evaluation.java76
-rw-r--r--src/de/lmu/ifi/dbs/elki/evaluation/scores/PrecisionAtKEvaluation.java127
-rw-r--r--src/de/lmu/ifi/dbs/elki/evaluation/scores/ROCEvaluation.java147
-rw-r--r--src/de/lmu/ifi/dbs/elki/evaluation/scores/ScoreEvaluation.java114
-rw-r--r--src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/DBIDRefIter.java39
-rw-r--r--src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/DBIDsTest.java59
-rw-r--r--src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/DecreasingVectorIter.java116
-rw-r--r--src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/DistanceResultAdapter.java92
-rw-r--r--src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/FilteredDistanceResultAdapter.java76
-rw-r--r--src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/IncreasingVectorIter.java116
-rw-r--r--src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/OutlierScoreAdapter.java103
-rw-r--r--src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/SimpleAdapter.java89
-rw-r--r--src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/VectorNonZero.java44
-rw-r--r--src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/VectorOverThreshold.java79
-rw-r--r--src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/VectorZero.java71
-rw-r--r--src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/package-info.java26
-rw-r--r--src/de/lmu/ifi/dbs/elki/evaluation/scores/package-info.java28
19 files changed, 1533 insertions, 0 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/scores/AbstractScoreEvaluation.java b/src/de/lmu/ifi/dbs/elki/evaluation/scores/AbstractScoreEvaluation.java
new file mode 100644
index 00000000..43de7ebd
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/evaluation/scores/AbstractScoreEvaluation.java
@@ -0,0 +1,55 @@
+package de.lmu.ifi.dbs.elki.evaluation.scores;
+
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import de.lmu.ifi.dbs.elki.data.Cluster;
+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.ids.DoubleDBIDList;
+import de.lmu.ifi.dbs.elki.evaluation.scores.adapter.DBIDsTest;
+import de.lmu.ifi.dbs.elki.evaluation.scores.adapter.DistanceResultAdapter;
+import de.lmu.ifi.dbs.elki.evaluation.scores.adapter.OutlierScoreAdapter;
+import de.lmu.ifi.dbs.elki.result.outlier.OutlierResult;
+
+/**
+ * Abstract base class for evaluating a scoring result.
+ *
+ * @author Erich Schubert
+ */
+public abstract class AbstractScoreEvaluation implements ScoreEvaluation {
+ @Override
+ public double evaluate(Cluster<?> clus, DoubleDBIDList nei) {
+ return evaluate(new DBIDsTest(DBIDUtil.ensureSet(clus.getIDs())), new DistanceResultAdapter(nei.iter()));
+ }
+
+ @Override
+ public double evaluate(DBIDs ids, DoubleDBIDList nei) {
+ return evaluate(new DBIDsTest(DBIDUtil.ensureSet(ids)), new DistanceResultAdapter(nei.iter()));
+ }
+
+ @Override
+ public double evaluate(DBIDs ids, OutlierResult outlier) {
+ return evaluate(new DBIDsTest(DBIDUtil.ensureSet(ids)), new OutlierScoreAdapter(outlier));
+ }
+}
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/scores/AveragePrecisionEvaluation.java b/src/de/lmu/ifi/dbs/elki/evaluation/scores/AveragePrecisionEvaluation.java
new file mode 100644
index 00000000..bc3d1522
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/evaluation/scores/AveragePrecisionEvaluation.java
@@ -0,0 +1,76 @@
+package de.lmu.ifi.dbs.elki.evaluation.scores;
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer;
+
+/**
+ * Evaluate using average precision.
+ *
+ * @author Erich Schubert
+ */
+public class AveragePrecisionEvaluation extends AbstractScoreEvaluation {
+ /**
+ * Static instance
+ */
+ public static final AveragePrecisionEvaluation STATIC = new AveragePrecisionEvaluation();
+
+ @Override
+ public <I extends ScoreIter> double evaluate(Predicate<? super I> predicate, I iter) {
+ int poscnt = 0, negcnt = 0, pospre = 0;
+ double acc = 0.;
+ while(iter.valid()) {
+ // positive or negative match?
+ do {
+ if(predicate.test(iter)) {
+ ++poscnt;
+ }
+ else {
+ ++negcnt;
+ }
+ iter.advance();
+ } // Loop while tied:
+ while(iter.valid() && iter.tiedToPrevious());
+ // Add a new point.
+ if(poscnt > pospre) {
+ acc += (poscnt / (double) (poscnt + negcnt)) * (poscnt - pospre);
+ pospre = poscnt;
+ }
+ }
+ return (poscnt > 0) ? acc / poscnt : 0.;
+ }
+
+ /**
+ * Parameterization class.
+ *
+ * @author Erich Schubert
+ *
+ * @apiviz.exclude
+ */
+ public static class Parameterizer extends AbstractParameterizer {
+ @Override
+ protected AveragePrecisionEvaluation makeInstance() {
+ return STATIC;
+ }
+ }
+}
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/scores/MaximumF1Evaluation.java b/src/de/lmu/ifi/dbs/elki/evaluation/scores/MaximumF1Evaluation.java
new file mode 100644
index 00000000..bac59b45
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/evaluation/scores/MaximumF1Evaluation.java
@@ -0,0 +1,76 @@
+package de.lmu.ifi.dbs.elki.evaluation.scores;
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer;
+
+/**
+ * Evaluate using the maximum F1 score.
+ *
+ * @author Erich Schubert
+ */
+public class MaximumF1Evaluation extends AbstractScoreEvaluation {
+ /**
+ * Static instance
+ */
+ public static final MaximumF1Evaluation STATIC = new MaximumF1Evaluation();
+
+ @Override
+ public <I extends ScoreIter> double evaluate(Predicate<? super I> predicate, I iter) {
+ final int postot = predicate.numPositive();
+ int poscnt = 0, cnt = 0;
+ double maxf1 = 0.;
+ while(iter.valid()) {
+ // positive or negative match?
+ do {
+ if(predicate.test(iter)) {
+ ++poscnt;
+ }
+ ++cnt;
+ iter.advance();
+ } // Loop while tied:
+ while(iter.valid() && iter.tiedToPrevious());
+ // New F1 value:
+ double p = poscnt / (double) cnt, r = poscnt / (double) postot;
+ double f1 = 2. * p * r / (p + r);
+ if(f1 > maxf1) {
+ maxf1 = f1;
+ }
+ }
+ return maxf1;
+ }
+
+ /**
+ * Parameterization class.
+ *
+ * @author Erich Schubert
+ *
+ * @apiviz.exclude
+ */
+ public static class Parameterizer extends AbstractParameterizer {
+ @Override
+ protected MaximumF1Evaluation makeInstance() {
+ return STATIC;
+ }
+ }
+}
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/scores/PrecisionAtKEvaluation.java b/src/de/lmu/ifi/dbs/elki/evaluation/scores/PrecisionAtKEvaluation.java
new file mode 100644
index 00000000..97ab0abd
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/evaluation/scores/PrecisionAtKEvaluation.java
@@ -0,0 +1,127 @@
+package de.lmu.ifi.dbs.elki.evaluation.scores;
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer;
+import de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID;
+import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.CommonConstraints;
+import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameterization;
+import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.IntParameter;
+
+/**
+ * Evaluate using Precision@k, or R-precision (when {@code k=0}).
+ *
+ * When {@code k=0}, then it is set to the number of positive objects, and the
+ * returned value is the R-precision, or the precision-recall break-even-point
+ * (BEP).
+ *
+ * @author Erich Schubert
+ */
+public class PrecisionAtKEvaluation extends AbstractScoreEvaluation {
+ /**
+ * Static instance
+ */
+ public static final PrecisionAtKEvaluation RPRECISION = new PrecisionAtKEvaluation(0);
+
+ /**
+ * Parameter k.
+ */
+ int k;
+
+ /**
+ * Constructor.
+ *
+ * @param k k to evaluate at. May be 0.
+ */
+ public PrecisionAtKEvaluation(int k) {
+ this.k = k;
+ }
+
+ @Override
+ public <I extends ScoreIter> double evaluate(Predicate<? super I> predicate, I iter) {
+ final int k = (this.k > 0) ? this.k : predicate.numPositive();
+ int total = 0;
+ double score = 0.;
+ while(iter.valid() && total < k) {
+ int posthis = 0, cntthis = 0;
+ // positive or negative match?
+ do {
+ if(predicate.test(iter)) {
+ ++posthis;
+ }
+ ++cntthis;
+ iter.advance();
+ } // Loop while tied:
+ while(iter.valid() && iter.tiedToPrevious());
+ // Special tie computations only when we reach k.
+ if(total + cntthis > k) {
+ // p = posthis / cntthis chance of being positive
+ // n = (k-total) draws.
+ // expected value = n * p
+ score += posthis / (double) cntthis * (k - total);
+ total = k;
+ break;
+ }
+ score += posthis;
+ total += cntthis;
+ }
+ return score / total;
+ }
+
+ /**
+ * Parameterization class.
+ *
+ * @author Erich Schubert
+ *
+ * @apiviz.exclude
+ */
+ public static class Parameterizer extends AbstractParameterizer {
+ /**
+ * Option ID for the k parameter.
+ */
+ public static final OptionID K_ID = new OptionID("precision.k", //
+ "k value for precision@k. Can be set to 0, to get R-precision, or the precision-recall-break-even-point.");
+
+ /**
+ * K parameter
+ */
+ int k;
+
+ @Override
+ protected void makeOptions(Parameterization config) {
+ super.makeOptions(config);
+
+ IntParameter kP = new IntParameter(K_ID) //
+ .setDefaultValue(0) //
+ .addConstraint(CommonConstraints.GREATER_EQUAL_ZERO_INT);
+ if(config.grab(kP)) {
+ k = kP.intValue();
+ }
+ }
+
+ @Override
+ protected PrecisionAtKEvaluation makeInstance() {
+ return k > 0 ? new PrecisionAtKEvaluation(k) : RPRECISION;
+ }
+ }
+}
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/scores/ROCEvaluation.java b/src/de/lmu/ifi/dbs/elki/evaluation/scores/ROCEvaluation.java
new file mode 100644
index 00000000..1a74d25a
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/evaluation/scores/ROCEvaluation.java
@@ -0,0 +1,147 @@
+package de.lmu.ifi.dbs.elki.evaluation.scores;
+
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+import de.lmu.ifi.dbs.elki.math.geometry.XYCurve;
+import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer;
+
+/**
+ * Compute ROC (Receiver Operating Characteristics) curves.
+ *
+ * A ROC curve compares the true positive rate (y-axis) and false positive rate
+ * (x-axis).
+ *
+ * It was first used in radio signal detection, but has since found widespread
+ * use in information retrieval, in particular for evaluating binary
+ * classification problems.
+ *
+ * ROC curves are particularly useful to evaluate a ranking of objects with
+ * respect to a binary classification problem: a random sampling will
+ * approximately achieve a ROC value of 0.5, while a perfect separation will
+ * achieve 1.0 (all positives first) or 0.0 (all negatives first). In most use
+ * cases, a score significantly below 0.5 indicates that the algorithm result
+ * has been used the wrong way, and should be used backwards.
+ *
+ * @author Erich Schubert
+ *
+ * @apiviz.has XYCurve
+ */
+public class ROCEvaluation extends AbstractScoreEvaluation {
+ /**
+ * Static instance
+ */
+ public static final ROCEvaluation STATIC = new ROCEvaluation();
+
+ @Override
+ public <I extends ScoreIter> double evaluate(Predicate<? super I> predicate, I iter) {
+ return computeROCAUC(predicate, iter);
+ }
+
+ /**
+ * Compute a ROC curve given a set of positive IDs and a sorted list of
+ * (comparable, ID)s, where the comparable object is used to decided when two
+ * objects are interchangeable.
+ *
+ * @param <I> Iterator type
+ * @param predicate Predicate to test for positive objects
+ * @param iter Iterator over results, with ties.
+ * @return area under curve
+ */
+ public static <I extends ScoreIter> XYCurve materializeROC(Predicate<? super I> predicate, I iter) {
+ int poscnt = 0, negcnt = 0;
+ XYCurve curve = new XYCurve("False Positive Rate", "True Positive Rate");
+
+ // start in bottom left
+ curve.add(0.0, 0.0);
+
+ while(iter.valid()) {
+ // positive or negative match?
+ do {
+ if(predicate.test(iter)) {
+ ++poscnt;
+ }
+ else {
+ ++negcnt;
+ }
+ iter.advance();
+ } // Loop while tied:
+ while(iter.valid() && iter.tiedToPrevious());
+ // Add a new point.
+ curve.addAndSimplify(negcnt, poscnt);
+ }
+ // Ensure we end up in the top right corner.
+ // Simplification will skip this if we already were.
+ curve.addAndSimplify(negcnt, poscnt);
+ curve.rescale(1. / negcnt, 1. / poscnt);
+ return curve;
+ }
+
+ /**
+ * Compute the area under the ROC curve given a set of positive IDs and a
+ * sorted list of (comparable, ID)s, where the comparable object is used to
+ * decided when two objects are interchangeable.
+ *
+ * @param <I> Iterator type
+ * @param predicate Predicate to test for positive objects
+ * @param iter Iterator over results, with ties.
+ * @return area under curve
+ */
+ public static <I extends ScoreIter> double computeROCAUC(Predicate<? super I> predicate, I iter) {
+ int poscnt = 0, negcnt = 0, pospre = 0, negpre = 0;
+ double acc = 0.;
+ while(iter.valid()) {
+ // positive or negative match?
+ do {
+ if(predicate.test(iter)) {
+ ++poscnt;
+ }
+ else {
+ ++negcnt;
+ }
+ iter.advance();
+ } // Loop while tied:
+ while(iter.valid() && iter.tiedToPrevious());
+ if(negcnt > negpre) {
+ acc += (poscnt + pospre) * .5 * (negcnt - negpre);
+ negpre = negcnt;
+ }
+ pospre = poscnt;
+ }
+ acc /= negcnt * (long) poscnt;
+ return acc == acc ? acc : 0.5; /* Detect NaN */
+ }
+
+ /**
+ * Parameterization class.
+ *
+ * @author Erich Schubert
+ *
+ * @apiviz.exclude
+ */
+ public static class Parameterizer extends AbstractParameterizer {
+ @Override
+ protected ROCEvaluation makeInstance() {
+ return STATIC;
+ }
+ }
+}
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/scores/ScoreEvaluation.java b/src/de/lmu/ifi/dbs/elki/evaluation/scores/ScoreEvaluation.java
new file mode 100644
index 00000000..d32714ad
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/evaluation/scores/ScoreEvaluation.java
@@ -0,0 +1,114 @@
+package de.lmu.ifi.dbs.elki.evaluation.scores;
+
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import de.lmu.ifi.dbs.elki.data.Cluster;
+import de.lmu.ifi.dbs.elki.database.ids.DBIDs;
+import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDList;
+import de.lmu.ifi.dbs.elki.result.outlier.OutlierResult;
+import de.lmu.ifi.dbs.elki.utilities.datastructures.iterator.Iter;
+
+/**
+ * Compute ranking/scoring based evaluation measures.
+ *
+ * @author Erich Schubert
+ */
+public interface ScoreEvaluation {
+ /**
+ * Evaluate a given predicate and iterator.
+ *
+ * @param predicate Predicate (for positives)
+ * @param iter Iterator
+ * @return Score
+ * @param <I> Iterator type
+ */
+ <I extends ScoreIter> double evaluate(Predicate<? super I> predicate, I iter);
+
+ /**
+ * Evaluate given a cluster (of positive elements) and a scoring list.
+ *
+ * @param clus Cluster object
+ * @param nei Query result
+ * @return Score
+ */
+ double evaluate(Cluster<?> clus, DoubleDBIDList nei);
+
+ /**
+ * Evaluate given a list of positives and a scoring.
+ *
+ * @param ids Positive IDs, usually a set.
+ * @param nei Query Result
+ * @return Score
+ */
+ double evaluate(DBIDs ids, DoubleDBIDList nei);
+
+ /**
+ * Evaluate given a set of positives and a scoring.
+ *
+ * @param ids Positive IDs, usually a set.
+ * @param outlier Outlier detection result
+ * @return Score
+ */
+ double evaluate(DBIDs ids, OutlierResult outlier);
+
+ /**
+ * Iterator for comparing scores.
+ *
+ * @author Erich Schubert
+ */
+ public static interface ScoreIter extends Iter {
+ /**
+ * Test whether the score is the same as the previous objects score.
+ *
+ * When there is no previous result, implementations should return false!
+ *
+ * @return Boolean
+ */
+ boolean tiedToPrevious();
+ }
+
+ /**
+ * Predicate to test whether an object is a true positive or false positive.
+ *
+ * @author Erich Schubert
+ *
+ * @param <T> Data type
+ */
+ public static interface Predicate<T> {
+ /**
+ * Test a result.
+ *
+ * @param o Object to test
+ * @return {@code true} when positive.
+ */
+ boolean test(T o);
+
+ /**
+ * Return the number of positive ids.
+ *
+ * @return Number of positive elements
+ */
+ int numPositive();
+ }
+}
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/DBIDRefIter.java b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/DBIDRefIter.java
new file mode 100644
index 00000000..2fdb5978
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/DBIDRefIter.java
@@ -0,0 +1,39 @@
+package de.lmu.ifi.dbs.elki.evaluation.scores.adapter;
+
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
+
+/**
+ * A score iterator wrapping a DBIDRef object.
+ *
+ * @author Erich Schubert
+ */
+public interface DBIDRefIter {
+ /**
+ * Get the current DBIDRef.
+ *
+ * @return DBID reference
+ */
+ DBIDRef getRef();
+} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/DBIDsTest.java b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/DBIDsTest.java
new file mode 100644
index 00000000..d41c7af4
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/DBIDsTest.java
@@ -0,0 +1,59 @@
+package de.lmu.ifi.dbs.elki.evaluation.scores.adapter;
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import de.lmu.ifi.dbs.elki.database.ids.DBIDs;
+import de.lmu.ifi.dbs.elki.evaluation.scores.ScoreEvaluation.Predicate;
+
+/**
+ * Test predicate using a DBID set as positive elements.
+ *
+ * @apiviz.composedOf DBIDs
+ *
+ * @author Erich Schubert
+ */
+public class DBIDsTest implements Predicate<DBIDRefIter> {
+ /**
+ * DBID set.
+ */
+ private DBIDs set;
+
+ /**
+ * Constructor.
+ *
+ * @param set Set of positive objects
+ */
+ public DBIDsTest(DBIDs set) {
+ this.set = set;
+ }
+
+ @Override
+ public boolean test(DBIDRefIter o) {
+ return set.contains(o.getRef());
+ }
+
+ @Override
+ public int numPositive() {
+ return set.size();
+ }
+} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/DecreasingVectorIter.java b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/DecreasingVectorIter.java
new file mode 100644
index 00000000..d0a55b19
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/DecreasingVectorIter.java
@@ -0,0 +1,116 @@
+package de.lmu.ifi.dbs.elki.evaluation.scores.adapter;
+
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+import de.lmu.ifi.dbs.elki.data.NumberVector;
+import de.lmu.ifi.dbs.elki.evaluation.scores.ScoreEvaluation.ScoreIter;
+import de.lmu.ifi.dbs.elki.utilities.datastructures.arrays.IntegerArrayQuickSort;
+import de.lmu.ifi.dbs.elki.utilities.datastructures.arrays.IntegerComparator;
+import de.lmu.ifi.dbs.elki.utilities.datastructures.iterator.ArrayIter;
+
+/**
+ * Class to iterate over a number vector in decreasing order.
+ *
+ * @author Erich Schubert
+ *
+ * @apiviz.composedOf NumberVector
+ */
+public class DecreasingVectorIter implements ScoreIter, IntegerComparator, ArrayIter {
+ /**
+ * Order of dimensions.
+ */
+ private int[] sort;
+
+ /**
+ * Data vector.
+ */
+ private NumberVector vec;
+
+ /**
+ * Current position.
+ */
+ int pos = 0;
+
+ /**
+ * Constructor.
+ *
+ * @param vec Vector to iterate over.
+ */
+ public DecreasingVectorIter(NumberVector vec) {
+ this.vec = vec;
+ final int dim = vec.getDimensionality();
+ this.sort = new int[dim];
+ for(int d = 0; d < dim; d++) {
+ sort[d] = d;
+ }
+ IntegerArrayQuickSort.sort(sort, this);
+ }
+
+ @Override
+ public int compare(int x, int y) {
+ return Double.compare(vec.doubleValue(y), vec.doubleValue(x));
+ }
+
+ public int dim() {
+ return sort[pos];
+ }
+
+ @Override
+ public boolean valid() {
+ return pos < vec.getDimensionality() && pos >= 0;
+ }
+
+ @Override
+ public DecreasingVectorIter advance() {
+ ++pos;
+ return this;
+ }
+
+ @Override
+ public boolean tiedToPrevious() {
+ return pos > 0 && Double.compare(vec.doubleValue(sort[pos]), vec.doubleValue(sort[pos - 1])) == 0;
+ }
+
+ @Override
+ public int getOffset() {
+ return pos;
+ }
+
+ @Override
+ public DecreasingVectorIter advance(int count) {
+ pos += count;
+ return this;
+ }
+
+ @Override
+ public DecreasingVectorIter retract() {
+ pos--;
+ return this;
+ }
+
+ @Override
+ public DecreasingVectorIter seek(int off) {
+ pos = off;
+ return this;
+ }
+} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/DistanceResultAdapter.java b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/DistanceResultAdapter.java
new file mode 100644
index 00000000..704c38bc
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/DistanceResultAdapter.java
@@ -0,0 +1,92 @@
+package de.lmu.ifi.dbs.elki.evaluation.scores.adapter;
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
+import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter;
+import de.lmu.ifi.dbs.elki.evaluation.scores.ScoreEvaluation.ScoreIter;
+
+/**
+ * This adapter is used to process a list of (double, DBID) objects. The list
+ * <em>must</em> be sorted appropriately, the score is only used to detect
+ * ties.
+ *
+ * @author Erich Schubert
+ *
+ * @apiviz.composedOf DoubleDBIDListIter
+ */
+public class DistanceResultAdapter implements ScoreIter, DBIDRefIter {
+ /**
+ * Original Iterator
+ */
+ protected DoubleDBIDListIter iter;
+
+ /**
+ * Distance of previous.
+ */
+ protected double prevDist = Double.NaN;
+
+ /**
+ * Constructor
+ *
+ * @param iter Iterator for distance results
+ */
+ public DistanceResultAdapter(DoubleDBIDListIter iter) {
+ super();
+ this.iter = iter;
+ }
+
+ @Override
+ public boolean valid() {
+ return iter.valid();
+ }
+
+ @Override
+ public DistanceResultAdapter advance() {
+ prevDist = iter.doubleValue();
+ iter.advance();
+ return this;
+ }
+
+ @Override
+ public DBIDRef getRef() {
+ return iter;
+ }
+
+ @Override
+ public boolean tiedToPrevious() {
+ return iter.doubleValue() == prevDist;
+ }
+
+ @Deprecated
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+
+ @Deprecated
+ @Override
+ public boolean equals(Object obj) {
+ return super.equals(obj);
+ }
+} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/FilteredDistanceResultAdapter.java b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/FilteredDistanceResultAdapter.java
new file mode 100644
index 00000000..9a8a2ddc
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/FilteredDistanceResultAdapter.java
@@ -0,0 +1,76 @@
+package de.lmu.ifi.dbs.elki.evaluation.scores.adapter;
+
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+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.DoubleDBIDListIter;
+
+/**
+ * This adapter is used to process a list of (double, DBID) objects, but allows
+ * skipping one object in the ranking. The list <em>must</em> be sorted
+ * appropriately, the score is only used to detect ties.
+ *
+ * @author Erich Schubert
+ */
+public class FilteredDistanceResultAdapter extends DistanceResultAdapter {
+ /**
+ * DBID to skip (usually: query object).
+ */
+ DBIDRef skip;
+
+ /**
+ * Constructor
+ *
+ * @param iter Iterator for distance results
+ * @param skip DBID to skip (reference must remain stable!)
+ */
+ public FilteredDistanceResultAdapter(DoubleDBIDListIter iter, DBIDRef skip) {
+ super(iter);
+ this.skip = skip;
+ if(iter.valid() && DBIDUtil.equal(iter, skip)) {
+ iter.advance();
+ }
+ }
+
+ @Override
+ public DistanceResultAdapter advance() {
+ super.advance();
+ if(iter.valid() && DBIDUtil.equal(iter, skip)) {
+ iter.advance();
+ }
+ return this;
+ }
+
+ @Deprecated
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+
+ @Deprecated
+ @Override
+ public boolean equals(Object obj) {
+ return super.equals(obj);
+ }
+} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/IncreasingVectorIter.java b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/IncreasingVectorIter.java
new file mode 100644
index 00000000..979dc166
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/IncreasingVectorIter.java
@@ -0,0 +1,116 @@
+package de.lmu.ifi.dbs.elki.evaluation.scores.adapter;
+
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+import de.lmu.ifi.dbs.elki.data.NumberVector;
+import de.lmu.ifi.dbs.elki.evaluation.scores.ScoreEvaluation.ScoreIter;
+import de.lmu.ifi.dbs.elki.utilities.datastructures.arrays.IntegerArrayQuickSort;
+import de.lmu.ifi.dbs.elki.utilities.datastructures.arrays.IntegerComparator;
+import de.lmu.ifi.dbs.elki.utilities.datastructures.iterator.ArrayIter;
+
+/**
+ * Class to iterate over a number vector in decreasing order.
+ *
+ * @author Erich Schubert
+ *
+ * @apiviz.composedOf NumberVector
+ */
+public class IncreasingVectorIter implements ScoreIter, IntegerComparator, ArrayIter {
+ /**
+ * Order of dimensions.
+ */
+ private int[] sort;
+
+ /**
+ * Data vector.
+ */
+ private NumberVector vec;
+
+ /**
+ * Current position.
+ */
+ int pos = 0;
+
+ /**
+ * Constructor.
+ *
+ * @param vec Vector to iterate over.
+ */
+ public IncreasingVectorIter(NumberVector vec) {
+ this.vec = vec;
+ final int dim = vec.getDimensionality();
+ this.sort = new int[dim];
+ for(int d = 0; d < dim; d++) {
+ sort[d] = d;
+ }
+ IntegerArrayQuickSort.sort(sort, this);
+ }
+
+ @Override
+ public int compare(int x, int y) {
+ return Double.compare(vec.doubleValue(x), vec.doubleValue(y));
+ }
+
+ public int dim() {
+ return sort[pos];
+ }
+
+ @Override
+ public boolean valid() {
+ return pos < vec.getDimensionality();
+ }
+
+ @Override
+ public IncreasingVectorIter advance() {
+ ++pos;
+ return this;
+ }
+
+ @Override
+ public boolean tiedToPrevious() {
+ return pos > 0 && Double.compare(vec.doubleValue(sort[pos]), vec.doubleValue(sort[pos - 1])) == 0;
+ }
+
+ @Override
+ public int getOffset() {
+ return pos;
+ }
+
+ @Override
+ public IncreasingVectorIter advance(int count) {
+ pos += count;
+ return this;
+ }
+
+ @Override
+ public IncreasingVectorIter retract() {
+ pos--;
+ return this;
+ }
+
+ @Override
+ public IncreasingVectorIter seek(int off) {
+ pos = off;
+ return this;
+ }
+} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/OutlierScoreAdapter.java b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/OutlierScoreAdapter.java
new file mode 100644
index 00000000..a36a57d6
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/OutlierScoreAdapter.java
@@ -0,0 +1,103 @@
+package de.lmu.ifi.dbs.elki.evaluation.scores.adapter;
+
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+import de.lmu.ifi.dbs.elki.database.ids.DBIDIter;
+import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
+import de.lmu.ifi.dbs.elki.database.relation.DoubleRelation;
+import de.lmu.ifi.dbs.elki.evaluation.scores.ScoreEvaluation.ScoreIter;
+import de.lmu.ifi.dbs.elki.result.outlier.OutlierResult;
+
+/**
+ * This adapter can be used for an arbitrary collection of Integers, and uses
+ * that id1.compareTo(id2) != 0 for id1 != id2 to satisfy the comparability.
+ *
+ * Note that of course, no id should occur more than once.
+ *
+ * The ROC values would be incorrect then anyway!
+ *
+ * @author Erich Schubert
+ *
+ * @apiviz.composedOf OutlierResult
+ */
+public class OutlierScoreAdapter implements ScoreIter, DBIDRefIter {
+ /**
+ * Original iterator.
+ */
+ private DBIDIter iter;
+
+ /**
+ * Outlier score.
+ */
+ private DoubleRelation scores;
+
+ /**
+ * Previous value.
+ */
+ double prev = Double.NaN;
+
+ /**
+ * Constructor.
+ *
+ * @param o Result
+ */
+ public OutlierScoreAdapter(OutlierResult o) {
+ super();
+ this.iter = o.getOrdering().iter(o.getScores().getDBIDs()).iter();
+ this.scores = o.getScores();
+ }
+
+ @Override
+ public boolean valid() {
+ return iter.valid();
+ }
+
+ @Override
+ public OutlierScoreAdapter advance() {
+ prev = scores.doubleValue(iter);
+ iter.advance();
+ return this;
+ }
+
+ @Override
+ public boolean tiedToPrevious() {
+ return scores.doubleValue(iter) == prev;
+ }
+
+ @Override
+ public DBIDRef getRef() {
+ return iter;
+ }
+
+ @Deprecated
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+
+ @Deprecated
+ @Override
+ public boolean equals(Object obj) {
+ return super.equals(obj);
+ }
+} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/SimpleAdapter.java b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/SimpleAdapter.java
new file mode 100644
index 00000000..beb301a8
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/SimpleAdapter.java
@@ -0,0 +1,89 @@
+package de.lmu.ifi.dbs.elki.evaluation.scores.adapter;
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import de.lmu.ifi.dbs.elki.database.ids.DBIDIter;
+import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
+import de.lmu.ifi.dbs.elki.evaluation.scores.ScoreEvaluation.ScoreIter;
+
+/**
+ * This adapter can be used for an arbitrary collection of Integers, and uses
+ * that id1.compareTo(id2) != 0 for id1 != id2 to satisfy the comparability.
+ *
+ * Note that of course, no id should occur more than once.
+ *
+ * The ROC values would be incorrect then anyway!
+ *
+ * @author Erich Schubert
+ *
+ * @apiviz.composedOf DBIDIter
+ */
+public class SimpleAdapter implements ScoreIter, DBIDRefIter {
+ /**
+ * Original Iterator
+ */
+ private DBIDIter iter;
+
+ /**
+ * Constructor
+ *
+ * @param iter Iterator for object IDs
+ */
+ public SimpleAdapter(DBIDIter iter) {
+ super();
+ this.iter = iter;
+ }
+
+ @Override
+ public boolean valid() {
+ return iter.valid();
+ }
+
+ @Override
+ public SimpleAdapter advance() {
+ iter.advance();
+ return this;
+ }
+
+ @Override
+ public boolean tiedToPrevious() {
+ return false; // No information.
+ }
+
+ @Deprecated
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+
+ @Deprecated
+ @Override
+ public boolean equals(Object obj) {
+ return super.equals(obj);
+ }
+
+ @Override
+ public DBIDRef getRef() {
+ return iter;
+ }
+} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/VectorNonZero.java b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/VectorNonZero.java
new file mode 100644
index 00000000..cc97006f
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/VectorNonZero.java
@@ -0,0 +1,44 @@
+package de.lmu.ifi.dbs.elki.evaluation.scores.adapter;
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import de.lmu.ifi.dbs.elki.data.NumberVector;
+
+/**
+ * Class that uses a NumberVector as reference, and considers all non-zero
+ * values as positive entries.
+ *
+ * @apiviz.composedOf NumberVector
+ *
+ * @author Erich Schubert
+ */
+public class VectorNonZero extends VectorOverThreshold {
+ /**
+ * Constructor.
+ *
+ * @param vec Reference vector.
+ */
+ public VectorNonZero(NumberVector vec) {
+ super(vec, 0.);
+ }
+} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/VectorOverThreshold.java b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/VectorOverThreshold.java
new file mode 100644
index 00000000..99c24332
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/VectorOverThreshold.java
@@ -0,0 +1,79 @@
+package de.lmu.ifi.dbs.elki.evaluation.scores.adapter;
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import de.lmu.ifi.dbs.elki.data.NumberVector;
+import de.lmu.ifi.dbs.elki.evaluation.scores.ScoreEvaluation.Predicate;
+
+/**
+ * Class that uses a NumberVector as reference, and considers all non-zero
+ * values as positive entries.
+ *
+ * @apiviz.composedOf NumberVector
+ *
+ * @author Erich Schubert
+ */
+public class VectorOverThreshold implements Predicate<DecreasingVectorIter> {
+ /**
+ * Vector to use as reference
+ */
+ NumberVector vec;
+
+ /**
+ * Threshold
+ */
+ double threshold;
+
+ /**
+ * Number of positive values.
+ */
+ int numpos;
+
+ /**
+ * Constructor.
+ *
+ * @param vec Reference vector.
+ * @param threshold Threshold value.
+ */
+ public VectorOverThreshold(NumberVector vec, double threshold) {
+ super();
+ this.vec = vec;
+ this.threshold = threshold;
+ this.numpos = 0;
+ for(int i = 0, l = vec.getDimensionality(); i < l; i++) {
+ if(vec.doubleValue(i) > threshold) {
+ ++numpos;
+ }
+ }
+ }
+
+ @Override
+ public boolean test(DecreasingVectorIter o) {
+ return Math.abs(vec.doubleValue(o.dim())) > threshold;
+ }
+
+ @Override
+ public int numPositive() {
+ return numpos;
+ }
+} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/VectorZero.java b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/VectorZero.java
new file mode 100644
index 00000000..e7b728fc
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/VectorZero.java
@@ -0,0 +1,71 @@
+package de.lmu.ifi.dbs.elki.evaluation.scores.adapter;
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import de.lmu.ifi.dbs.elki.data.NumberVector;
+import de.lmu.ifi.dbs.elki.evaluation.scores.ScoreEvaluation.Predicate;
+
+/**
+ * Class that uses a NumberVector as reference, and considers all zero values as
+ * positive entries.
+ *
+ * @apiviz.composedOf NumberVector
+ *
+ * @author Erich Schubert
+ */
+public class VectorZero implements Predicate<IncreasingVectorIter> {
+ /**
+ * Vector to use as reference
+ */
+ NumberVector vec;
+
+ /**
+ * Number of positive values.
+ */
+ int numpos;
+
+ /**
+ * Constructor.
+ *
+ * @param vec Reference vector.
+ */
+ public VectorZero(NumberVector vec) {
+ this.vec = vec;
+ this.numpos = 0;
+ for(int i = 0, l = vec.getDimensionality(); i < l; i++) {
+ if(Math.abs(vec.doubleValue(i)) < Double.MIN_NORMAL) {
+ ++numpos;
+ }
+ }
+ }
+
+ @Override
+ public boolean test(IncreasingVectorIter o) {
+ return Math.abs(vec.doubleValue(o.dim())) < Double.MIN_NORMAL;
+ }
+
+ @Override
+ public int numPositive() {
+ return numpos;
+ }
+} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/package-info.java b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/package-info.java
new file mode 100644
index 00000000..746d9a1c
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/evaluation/scores/adapter/package-info.java
@@ -0,0 +1,26 @@
+/**
+ * Adapter classes for ranking and scoring measures.
+ */
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package de.lmu.ifi.dbs.elki.evaluation.scores.adapter; \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/evaluation/scores/package-info.java b/src/de/lmu/ifi/dbs/elki/evaluation/scores/package-info.java
new file mode 100644
index 00000000..d409b7f9
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/evaluation/scores/package-info.java
@@ -0,0 +1,28 @@
+/**
+ * <p>Evaluation of rankings and scorings.</p>
+ *
+ * @apiviz.exclude java.util.*
+ */
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package de.lmu.ifi.dbs.elki.evaluation.scores; \ No newline at end of file