use of org.apache.commons.math3.stat.descriptive.DescriptiveStatistics in project GDSC-SMLM by aherbert.
the class PSFCreator method getLimits.
/**
* Get the limits of the array ignoring outliers more than 1.5x the inter quartile range
*
* @param data
* @return
*/
private double[] getLimits(double[] data) {
double[] limits = Maths.limits(data);
DescriptiveStatistics stats = new DescriptiveStatistics(data);
double lower = stats.getPercentile(25);
double upper = stats.getPercentile(75);
double iqr = (upper - lower) * 2;
limits[0] = FastMath.max(lower - iqr, limits[0]);
limits[1] = FastMath.min(upper + iqr, limits[1]);
return limits;
}
use of org.apache.commons.math3.stat.descriptive.DescriptiveStatistics in project lucene-solr by apache.
the class DescribeEvaluator method evaluate.
public Tuple evaluate(Tuple tuple) throws IOException {
if (subEvaluators.size() != 1) {
throw new IOException("describe expects 1 column as a parameters");
}
StreamEvaluator colEval = subEvaluators.get(0);
List<Number> numbers = (List<Number>) colEval.evaluate(tuple);
DescriptiveStatistics descriptiveStatistics = new DescriptiveStatistics();
for (Number n : numbers) {
descriptiveStatistics.addValue(n.doubleValue());
}
Map map = new HashMap();
map.put("max", descriptiveStatistics.getMax());
map.put("mean", descriptiveStatistics.getMean());
map.put("min", descriptiveStatistics.getMin());
map.put("stdev", descriptiveStatistics.getStandardDeviation());
map.put("sum", descriptiveStatistics.getSum());
map.put("N", descriptiveStatistics.getN());
map.put("var", descriptiveStatistics.getVariance());
map.put("kurtosis", descriptiveStatistics.getKurtosis());
map.put("skewness", descriptiveStatistics.getSkewness());
map.put("popVar", descriptiveStatistics.getPopulationVariance());
map.put("geometricMean", descriptiveStatistics.getGeometricMean());
map.put("sumsq", descriptiveStatistics.getSumsq());
return new Tuple(map);
}
use of org.apache.commons.math3.stat.descriptive.DescriptiveStatistics in project webofneeds by researchstudio-sat.
the class Kneedle method normalize.
private double[] normalize(final double[] values) {
double[] normalized = new double[values.length];
DescriptiveStatistics stats = new DescriptiveStatistics(values);
for (int i = 0; i < values.length; i++) {
normalized[i] = (values[i] - stats.getMin()) / (stats.getMax() - stats.getMin());
}
return normalized;
}
use of org.apache.commons.math3.stat.descriptive.DescriptiveStatistics in project webofneeds by researchstudio-sat.
the class Kneedle method detectKneeOrElbowPoints.
/**
* Detect all knee points in a curve according to "Kneedle" algorithm.
* Alternatively this method can detect elbow points instead of knee points.
*
* @param x x-coordintes of curve, must be increasing in value
* @param y y-coordinates of curve
* @param detectElbows if true detects elbow points, if false detects knee points
* @return array of indices of knee (or elbow) points in the curve
*/
private int[] detectKneeOrElbowPoints(final double[] x, final double[] y, boolean detectElbows) {
checkConstraints(x, y);
List<Integer> kneeIndices = new LinkedList<Integer>();
List<Integer> lmxIndices = new LinkedList<Integer>();
List<Double> lmxThresholds = new LinkedList<Double>();
double[] xn = normalize(x);
double[] yn = normalize(y);
// compute the y difference values
double[] yDiff = new double[y.length];
for (int i = 0; i < y.length; i++) {
yDiff[i] = yn[i] - xn[i];
}
// original yDiff curve
if (detectElbows) {
DescriptiveStatistics stats = new DescriptiveStatistics(yDiff);
for (int i = 0; i < yDiff.length; i++) {
yDiff[i] = stats.getMax() - yDiff[i];
}
}
// find local maxima, compute threshold values and detect knee points
boolean detectKneeForLastLmx = false;
for (int i = 1; i < y.length - 1; i++) {
// than for its left and right neighbour => local maximum
if (yDiff[i] > yDiff[i - 1] && yDiff[i] > yDiff[i + 1]) {
// local maximum found
lmxIndices.add(i);
// compute the threshold value for this local maximum
// NOTE: As stated in the paper the threshold Tlmx is computed. Since the mean distance of all consecutive
// x-values summed together for a normalized function is always (1 / (n -1)) we do not have to compute the
// whole sum here as stated in the paper.
double tlmx = yDiff[i] - sensitivity / (xn.length - 1);
lmxThresholds.add(tlmx);
// try to find out if the current local maximum is a knee point
detectKneeForLastLmx = true;
}
// check for new knee point
if (detectKneeForLastLmx) {
if (yDiff[i + 1] < lmxThresholds.get(lmxThresholds.size() - 1)) {
// knee detected
kneeIndices.add(lmxIndices.get(lmxIndices.size() - 1));
detectKneeForLastLmx = false;
}
}
}
int[] knees = new int[kneeIndices.size()];
for (int i = 0; i < kneeIndices.size(); i++) {
knees[i] = kneeIndices.get(i);
}
return knees;
}
use of org.apache.commons.math3.stat.descriptive.DescriptiveStatistics in project cloudsim-plus by manoelcampos.
the class MathUtil method getStatistics.
/**
* Gets an object to compute descriptive statistics for an list of numbers.
*
* @param list the list of numbers. Must not be null.
* @return descriptive statistics for the list of numbers.
*/
public static DescriptiveStatistics getStatistics(final List<Double> list) {
final DescriptiveStatistics stats = new DescriptiveStatistics();
list.forEach(stats::addValue);
return stats;
}
Aggregations