List of usage examples for org.apache.commons.math3.distribution RealDistribution cumulativeProbability
double cumulativeProbability(double x);
From source file:cz.cuni.mff.spl.evaluator.statistics.KolmogorovSmirnovTestFlag.java
/** * Computes the one-sample Kolmogorov-Smirnov test statistic, \(D_n=\sup_x |F_n(x)-F(x)|\) where * \(F\) is the distribution (cdf) function associated with {@code distribution}, \(n\) is the * length of {@code data} and \(F_n\) is the empirical distribution that puts mass \(1/n\) at * each of the values in {@code data}.//w w w . ja v a 2s . c om * * @param distribution reference distribution * @param data sample being evaluated * @return Kolmogorov-Smirnov statistic \(D_n\) * @throws InsufficientDataException if {@code data} does not have length at least 2 * @throws NullArgumentException if {@code data} is null */ public double kolmogorovSmirnovStatistic(RealDistribution distribution, double[] data) { checkArray(data); final int n = data.length; final double nd = n; final double[] dataCopy = new double[n]; System.arraycopy(data, 0, dataCopy, 0, n); Arrays.sort(dataCopy); double d = 0d; for (int i = 1; i <= n; i++) { final double yi = distribution.cumulativeProbability(dataCopy[i - 1]); final double currD = FastMath.max(yi - (i - 1) / nd, i / nd - yi); if (currD > d) { d = currD; } } return d; }
From source file:org.apache.solr.client.solrj.io.eval.CumulativeProbabilityEvaluator.java
@Override public Object doWork(Object first, Object second) throws IOException { if (null == first) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - null found for the first value", toExpression(constructingFactory))); }//ww w .jav a2 s. c o m if (null == second) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - null found for the second value", toExpression(constructingFactory))); } if (!(first instanceof RealDistribution) && !(first instanceof IntegerDistribution)) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - found type %s for the first value, expecting a real or integer Distribution", toExpression(constructingFactory), first.getClass().getSimpleName())); } if (!(second instanceof Number)) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - found type %s for the second value, expecting a Number", toExpression(constructingFactory), first.getClass().getSimpleName())); } if (first instanceof RealDistribution) { RealDistribution rd = (RealDistribution) first; Number predictOver = (Number) second; return rd.cumulativeProbability(predictOver.doubleValue()); } else { IntegerDistribution id = (IntegerDistribution) first; Number predictOver = (Number) second; return id.cumulativeProbability(predictOver.intValue()); } }