comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/Outlier.java @ 2646:c11da3540b70

Checked in out dated version of outlier test. flys-artifacts/trunk@4301 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 25 Apr 2012 16:04:37 +0000
parents 4f7d1ea38404
children ab81ffd1343e
comparison
equal deleted inserted replaced
2645:4f7d1ea38404 2646:c11da3540b70
1 package de.intevation.flys.artifacts.math; 1 package de.intevation.flys.artifacts.math;
2
3 import org.apache.commons.math.MathException;
2 4
3 import org.apache.commons.math.stat.descriptive.moment.Mean; 5 import org.apache.commons.math.stat.descriptive.moment.Mean;
4 import org.apache.commons.math.stat.descriptive.moment.StandardDeviation; 6 import org.apache.commons.math.stat.descriptive.moment.StandardDeviation;
5 7
6 import org.apache.commons.math.distribution.TDistributionImpl; 8 import org.apache.commons.math.distribution.TDistributionImpl;
7 9
8 import java.util.List; 10 import java.util.List;
9 import java.util.ArrayList; 11 import java.util.ArrayList;
10 12
13 import org.apache.log4j.Logger;
14
11 public class Outlier 15 public class Outlier
12 { 16 {
17 private static Logger log = Logger.getLogger(Outlier.class);
18
13 public static class IndexedValue { 19 public static class IndexedValue {
14 protected int index; 20 protected int index;
15 protected double value; 21 protected double value;
16 22
17 public IndexedValue() { 23 public IndexedValue() {
69 double m = mean.getResult(); 75 double m = mean.getResult();
70 double s = std.getResult(); 76 double s = std.getResult();
71 77
72 double maxZ = -Double.MAX_VALUE; 78 double maxZ = -Double.MAX_VALUE;
73 int iv = -1; 79 int iv = -1;
74 for (int i >= 0; i = N-1; --i) { 80 for (int i = N-1; i >= 0; --i) {
75 IndexedValue v = values.get(i); 81 IndexedValue v = values.get(i);
76 double z = Math.abs(m - v.getValue())/s; 82 double z = Math.abs(m - v.getValue())/s;
77 if (z > maxZ) { 83 if (z > maxZ) {
78 maxZ = z; 84 maxZ = z;
79 iv = i; 85 iv = i;
80 } 86 }
81 } 87 }
82 88
83 double t = Math.sqrt((N*(N-2)*z*z)/((N-1)*(N-1) - N*z*z)) 89 double t = Math.sqrt((N*(N-2)*maxZ*maxZ)
90 /((N-1)*(N-1) - N*maxZ*maxZ));
84 91
85 TDistributionImpl tdist = new TDistributionImpl(N-2); 92 TDistributionImpl tdist = new TDistributionImpl(N-2);
86 93
87 double p = tdist.cumulativeProbability(t) 94 try {
95 double p = tdist.cumulativeProbability(t);
96
97 if (p < alpha) {
98 outliers.add(values.get(iv));
99 values.remove(iv);
100 }
101 }
102 catch (MathException me) {
103 log.error(me);
104 }
88 } 105 }
89 106
90 107
91 return outliers; 108 return outliers;
92 } 109 }

http://dive4elements.wald.intevation.org