-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #245 from eclipse/add_outlier_stats
Add outlier stats class
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...ipse.dawnsci.analysis.dataset/src/org/eclipse/dawnsci/analysis/dataset/impl/Outliers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/*- | ||
* Copyright 2016 Diamond Light Source Ltd. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.eclipse.dawnsci.analysis.dataset.impl; | ||
|
||
public class Outliers { | ||
|
||
private final static double MADSCALEFACTOR = 1.4826; | ||
private final static double SNSCALEFACTOR = 1.1926; | ||
|
||
public static double[] medianAbsoluteDeviation(Dataset data) { | ||
|
||
double median = (Double)Stats.median(data); | ||
data = Maths.subtract(data, median); | ||
data = Maths.abs(data); | ||
double median2 = (Double)Stats.median(data); | ||
double mad = MADSCALEFACTOR * median2; | ||
|
||
return new double[]{mad, median}; | ||
} | ||
|
||
public static double snNaive(Dataset data) { | ||
|
||
Dataset medAbs = DatasetFactory.zeros(data); | ||
Dataset dif = DatasetFactory.zeros(data); | ||
|
||
IndexIterator it = data.getIterator(); | ||
int count = 0; | ||
while (it.hasNext()) { | ||
double val = data.getElementDoubleAbs(it.index); | ||
Maths.subtract(data, val, dif); | ||
Maths.abs(dif,dif); | ||
//Lower median - Math.floor((n/2)+1) of sorted | ||
dif.sort(null); | ||
medAbs.setObjectAbs(count++, dif.getElementDoubleAbs((int)Math.floor((dif.getSize()/2)+1))); | ||
} | ||
|
||
|
||
//Higher median - Math.floor((n+1)/2) of sorted | ||
medAbs.sort(null); | ||
double median = medAbs.getElementDoubleAbs((int)Math.floor((medAbs.getSize()+1)/2)); | ||
|
||
return median * SNSCALEFACTOR; | ||
} | ||
|
||
public static double lowMed(Dataset data) { | ||
return data.getElementDoubleAbs((int)Math.floor((data.getSize()/2)+1)); | ||
} | ||
|
||
public static double highMed(Dataset data) { | ||
return data.getElementDoubleAbs((int)Math.floor((data.getSize()+1)/2)); | ||
} | ||
|
||
|
||
} |