package experimentalcode.erich.outlierensemble;

import java.util.Arrays;

import de.lmu.ifi.dbs.elki.database.Database;
import de.lmu.ifi.dbs.elki.database.ids.DBID;
import de.lmu.ifi.dbs.elki.result.outlier.OutlierResult;
import de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException;
import de.lmu.ifi.dbs.elki.utilities.scaling.outlier.OutlierScalingFunction;

/**
 * This is a pseudo outlier scoring obtained by only considering the ranks of the objects.
 * 
 * @author Erich Schubert
 */
public class RankingPseudoOutlierScaling implements OutlierScalingFunction {
  /**
   * The actual scores
   */
  private double[] scores;

  @Override
  public void prepare(Database<?> db, OutlierResult or) {
    // collect all outlier scores
    scores = new double[db.size()];
    int pos = 0;
    for(DBID id : db) {
      scores[pos] = or.getScores().getValueFor(id);
      pos++;
    }
    if (pos != db.size()) {
      throw new AbortException("Database size is incorrect!");
    }
    // sort them
    // TODO: Inverted scores!
    Arrays.sort(scores);
  }

  @Override
  public double getMax() {
    return 1.0;
  }

  @Override
  public double getMin() {
    return 0.0;
  }

  @Override
  public double getScaled(double value) {
    int pos = Arrays.binarySearch(scores, value);
    return ((float)pos) / scores.length;
  }
}
@@ -160,16 +160,84 @@
 s.DBID;%0A
+import de.lmu.ifi.dbs.elki.result.outlier.InvertedOutlierScoreMeta;%0A
 import d
@@ -285,16 +285,16 @@
 Result;%0A
-
 import d
@@ -508,16 +508,19 @@
 ranks of
+%0A *
  the obj
@@ -699,16 +699,53 @@
 cores;%0A%0A
+  private boolean inverted = false;%0A%0A
   @Overr
@@ -893,16 +893,112 @@
 os = 0;%0A
+    if (or.getOutlierMeta() instanceof InvertedOutlierScoreMeta) %7B%0A      inverted = true;%0A    %7D%0A
     for(
@@ -1090,17 +1090,16 @@
 %7D%0A    if
- 
 (pos != 
@@ -1489,23 +1489,114 @@
     
-return ((float)
+if(inverted) %7B%0A      return 1.0 - ((double) pos) / scores.length;%0A    %7D%0A    else %7B%0A      return ((double) 
 pos)
@@ -1613,13 +1613,19 @@
 length;%0A
+    %7D%0A
   %7D%0A%7D

Add support for inverted outlier scores (when using the invertedoutlierscore class)