# HG changeset patch # User Sascha L. Teichmann # Date 1340726459 0 # Node ID 1e2733f749b5513433023fa536585cd7fe0b74a5 # Parent c130be3fa8095123204186c6fb74028eaca7e870 SQ: Added specialized outlier test for the S/Q relation. flys-artifacts/trunk@4802 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r c130be3fa809 -r 1e2733f749b5 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Tue Jun 26 15:16:27 2012 +0000 +++ b/flys-artifacts/ChangeLog Tue Jun 26 16:00:59 2012 +0000 @@ -1,3 +1,9 @@ +2012-06-26 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/artifacts/model/sq/Outlier.java: + New. Specialized outlier test for the S/Q relation. + Outliers are accepted in multiples of the standard deviation. + 2012-06-26 Sascha L. Teichmann * src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java: diff -r c130be3fa809 -r 1e2733f749b5 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Outlier.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Outlier.java Tue Jun 26 16:00:59 2012 +0000 @@ -0,0 +1,88 @@ +package de.intevation.flys.artifacts.model.sq; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.math.stat.descriptive.moment.StandardDeviation; + +public class Outlier +{ + public static final int MAX_ITERATIONS = 1000; + + public interface Callback { + + double eval(SQ sq); + + void iteration(int i); + + void outlier(SQ sq); + + void finished(); + + } // interface Callback + + private static final class EvalSQ { + protected SQ sq; + protected double value; + + public EvalSQ(SQ sq) { + this.sq = sq; + } + } // class EvalSQ + + public static List detectOutliers( + Callback callback, + List sqs, + double stdDevFactor + ) { + List data = new ArrayList(sqs.size()); + + for (SQ sq: sqs) { + data.add(new EvalSQ(sq)); + } + + List good = new ArrayList(sqs.size()); + + for (int i = 0; i < MAX_ITERATIONS && data.size() > 2; ++i) { + + StandardDeviation stdDev = new StandardDeviation(); + + for (EvalSQ esq: data) { + stdDev.increment(esq.value = callback.eval(esq.sq)); + } + + double accepted = stdDevFactor * stdDev.getResult(); + + callback.iteration(i); + + for (EvalSQ esq: data) { + if (Math.abs(esq.value) > accepted) { + callback.outlier(esq.sq); + } + else { + good.add(esq); + } + } + + if (good.size() == data.size()) { + break; + } + + List tmp = good; + good = data; + data = tmp; + good.clear(); + } + + callback.finished(); + + List result = new ArrayList(good.size()); + + for (EvalSQ esq: good) { + result.add(esq.sq); + } + + return result; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :