Example usage for org.apache.commons.math3.stat.inference KolmogorovSmirnovTest KolmogorovSmirnovTest

List of usage examples for org.apache.commons.math3.stat.inference KolmogorovSmirnovTest KolmogorovSmirnovTest

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat.inference KolmogorovSmirnovTest KolmogorovSmirnovTest.

Prototype

public KolmogorovSmirnovTest() 

Source Link

Document

Construct a KolmogorovSmirnovTest instance with a default random data generator.

Usage

From source file:be.uclouvain.mlg.jForest.importance.external.permutation.KSTestOnTreePredPerfs.java

@Override
public double[] getImportances() {
    KolmogorovSmirnovTest ks = new KolmogorovSmirnovTest();

    double[] res = new double[nfeat];
    for (int i = 0; i < nfeat; i++) {
        if (returnPval) {
            res[i] = ks.kolmogorovSmirnovTest(perfs, permPerfs[i]);
        } else {/* ww w.j  a v  a  2  s  . c o m*/
            res[i] = ks.kolmogorovSmirnovStatistic(perfs, permPerfs[i]);
        }
    }

    return res;
}

From source file:io.yields.math.framework.data.DataProvidersTest.java

@Explore(name = "check distributional properties of random numbers", dataProvider = DataProviders.FixedMersenneTwisterDataProvider.class, nrOfRuns = 10000)
@Exploration(name = "2D uniform samples", context = FunctionExplorerWithoutProperties.class, group = "data providers")
public void testRandomDistribution(Explorer<Pair> explorer) {
    KolmogorovSmirnovTest ksTest = new KolmogorovSmirnovTest();
    DescriptiveStatistics xStats = new DescriptiveStatistics();
    DescriptiveStatistics yStats = new DescriptiveStatistics();
    explorer.all().forEach(result -> {
        Pair pair = result.getFunctionOutcome().orElse(new Pair());
        xStats.addValue(pair.getX1());/* ww  w .  ja  v  a 2 s.  co  m*/
        yStats.addValue(pair.getX2());
    });
    DescriptiveStatistics cross = new DescriptiveStatistics();
    for (int i = 0; i < xStats.getN(); i++) {
        cross.addValue((xStats.getValues()[i] - .5) * (yStats.getValues()[i] - .5));
    }
    /**
     * x and y should be uniformly distributed
     */
    assertThat(ksTest.kolmogorovSmirnovStatistic(new UniformRealDistribution(0, 1), xStats.getValues()))
            .isEqualTo(0, Delta.delta(.015));
    assertThat(ksTest.kolmogorovSmirnovStatistic(new UniformRealDistribution(0, 1), yStats.getValues()))
            .isEqualTo(0, Delta.delta(.015));
    /**
     * and have zero correlation
     */
    assertThat(cross.getMean()).isEqualTo(0, Delta.delta(.05));
}

From source file:org.apache.flink.api.java.sampling.VeryFastReservoirSamplingTest.java

@BeforeClass
public static void init() {
    // initiate source data set.
    source = new ArrayList<Double>(SOURCE_SIZE);
    for (int i = 0; i < SOURCE_SIZE; i++) {
        source.add((double) i);
    }/*from w w w . j a  v a2s . com*/

    ksTest = new KolmogorovSmirnovTest();
}

From source file:org.apache.solr.client.solrj.io.eval.KolmogorovSmirnovEvaluator.java

@Override
public Object doWork(Object first, Object second) throws IOException {
    if (null == first || (first instanceof List<?>
            && 0 != ((List<?>) first).stream().filter(item -> null == item).count())) {
        throw new IOException(String.format(Locale.ROOT,
                "Invalid expression %s - null found for the first value", toExpression(constructingFactory)));
    }/*from ww w  . j ava2 s. com*/
    if (null == second || (second instanceof List<?>
            && 0 != ((List<?>) second).stream().filter(item -> null == item).count())) {
        throw new IOException(String.format(Locale.ROOT,
                "Invalid expression %s - null found for the second value", toExpression(constructingFactory)));
    }
    if (!(second instanceof List<?>)
            || 0 != ((List<?>) second).stream().filter(item -> !(item instanceof Number)).count()) {
        throw new IOException(String.format(Locale.ROOT,
                "Invalid expression %s - found type %s for the second value, expecting a List of numbers",
                toExpression(constructingFactory), first.getClass().getSimpleName()));
    }

    KolmogorovSmirnovTest ks = new KolmogorovSmirnovTest();
    double[] data = ((List<?>) second).stream().mapToDouble(item -> ((Number) item).doubleValue()).toArray();

    if (first instanceof RealDistribution) {
        RealDistribution realDistribution = (RealDistribution) first;

        Map<String, Double> m = new HashMap<>();
        m.put("p-value", ks.kolmogorovSmirnovTest(realDistribution, data));
        m.put("d-statistic", ks.kolmogorovSmirnovStatistic(realDistribution, data));
        return new Tuple(m);
    } else if (first instanceof List<?>
            && 0 == ((List<?>) first).stream().filter(item -> !(item instanceof Number)).count()) {
        double[] data2 = ((List<?>) first).stream().mapToDouble(item -> ((Number) item).doubleValue())
                .toArray();

        Map<String, Double> m = new HashMap<>();
        m.put("d-statistic", ks.kolmogorovSmirnovTest(data, data2));
        return new Tuple(m);
    } else {
        throw new IOException(String.format(Locale.ROOT,
                "Invalid expression %s - found type %s for the first value, expecting a RealDistribution or list of numbers",
                toExpression(constructingFactory), first.getClass().getSimpleName()));
    }
}

From source file:org.apache.solr.client.solrj.io.stream.StreamExpressionTest.java

@Test
public void fakeTest() {
    NormalDistribution a = new NormalDistribution(10, 2);
    NormalDistribution c = new NormalDistribution(100, 6);
    double[] d = c.sample(250);

    KolmogorovSmirnovTest ks = new KolmogorovSmirnovTest();
    double pv = ks.kolmogorovSmirnovStatistic(a, d);

    String s = "";
}