Search in sources :

Example 1 with GaussianRandomGenerator

use of org.apache.commons.math3.random.GaussianRandomGenerator in project metron by apache.

the class OnlineStatisticsProviderTest method testNormallyDistributedRandomDataShiftedBackwards.

@Test
public void testNormallyDistributedRandomDataShiftedBackwards() {
    List<Double> values = new ArrayList<>();
    GaussianRandomGenerator gaussian = new GaussianRandomGenerator(new MersenneTwister(0L));
    for (int i = 0; i < 1000000; ++i) {
        double d = gaussian.nextNormalizedDouble() - 10;
        values.add(d);
    }
    validateEquality(values);
}
Also used : GaussianRandomGenerator(org.apache.commons.math3.random.GaussianRandomGenerator) ArrayList(java.util.ArrayList) MersenneTwister(org.apache.commons.math3.random.MersenneTwister) Test(org.junit.Test)

Example 2 with GaussianRandomGenerator

use of org.apache.commons.math3.random.GaussianRandomGenerator in project metron by apache.

the class OnlineStatisticsProviderTest method testNormallyDistributedRandomDataShifted.

@Test
public void testNormallyDistributedRandomDataShifted() {
    List<Double> values = new ArrayList<>();
    GaussianRandomGenerator gaussian = new GaussianRandomGenerator(new MersenneTwister(0L));
    for (int i = 0; i < 1000000; ++i) {
        double d = gaussian.nextNormalizedDouble() + 10;
        values.add(d);
    }
    validateEquality(values);
}
Also used : GaussianRandomGenerator(org.apache.commons.math3.random.GaussianRandomGenerator) ArrayList(java.util.ArrayList) MersenneTwister(org.apache.commons.math3.random.MersenneTwister) Test(org.junit.Test)

Example 3 with GaussianRandomGenerator

use of org.apache.commons.math3.random.GaussianRandomGenerator in project metron by apache.

the class StellarStatisticsFunctionsTest method testMergeProviders.

@Test
public void testMergeProviders() throws Exception {
    List<StatisticsProvider> providers = new ArrayList<>();
    /*
    Create 10 providers, each with a sample drawn from a gaussian distribution.
    Update the reference stats from commons math to ensure we are
     */
    GaussianRandomGenerator gaussian = new GaussianRandomGenerator(new MersenneTwister(1L));
    SummaryStatistics sStatistics = new SummaryStatistics();
    DescriptiveStatistics dStatistics = new DescriptiveStatistics();
    for (int i = 0; i < 10; ++i) {
        List<Double> sample = new ArrayList<>();
        for (int j = 0; j < 100; ++j) {
            double s = gaussian.nextNormalizedDouble();
            sample.add(s);
            sStatistics.addValue(s);
            dStatistics.addValue(s);
        }
        StatisticsProvider provider = (StatisticsProvider) run("STATS_ADD(STATS_INIT(), " + Joiner.on(",").join(sample) + ")", new HashMap<>());
        providers.add(provider);
    }
    /*
    Merge the providers and validate
     */
    Map<String, Object> providerVariables = new HashMap<>();
    for (int i = 0; i < providers.size(); ++i) {
        providerVariables.put("provider_" + i, providers.get(i));
    }
    StatisticsProvider mergedProvider = (StatisticsProvider) run("STATS_MERGE([" + Joiner.on(",").join(providerVariables.keySet()) + "])", providerVariables);
    OnlineStatisticsProviderTest.validateStatisticsProvider(mergedProvider, sStatistics, dStatistics);
}
Also used : DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) GaussianRandomGenerator(org.apache.commons.math3.random.GaussianRandomGenerator) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) MersenneTwister(org.apache.commons.math3.random.MersenneTwister) Test(org.junit.Test)

Example 4 with GaussianRandomGenerator

use of org.apache.commons.math3.random.GaussianRandomGenerator in project metron by apache.

the class OnlineStatisticsProviderTest method testNormallyDistributedRandomData.

@Test
public void testNormallyDistributedRandomData() {
    List<Double> values = new ArrayList<>();
    GaussianRandomGenerator gaussian = new GaussianRandomGenerator(new MersenneTwister(0L));
    for (int i = 0; i < 1000000; ++i) {
        double d = gaussian.nextNormalizedDouble();
        values.add(d);
    }
    validateEquality(values);
}
Also used : GaussianRandomGenerator(org.apache.commons.math3.random.GaussianRandomGenerator) ArrayList(java.util.ArrayList) MersenneTwister(org.apache.commons.math3.random.MersenneTwister) Test(org.junit.Test)

Example 5 with GaussianRandomGenerator

use of org.apache.commons.math3.random.GaussianRandomGenerator in project metron by apache.

the class OnlineStatisticsProviderTest method testNormallyDistributedRandomDataAllNegative.

@Test
public void testNormallyDistributedRandomDataAllNegative() {
    List<Double> values = new ArrayList<>();
    GaussianRandomGenerator gaussian = new GaussianRandomGenerator(new MersenneTwister(0L));
    for (int i = 0; i < 1000000; ++i) {
        double d = -1 * gaussian.nextNormalizedDouble();
        values.add(d);
    }
    validateEquality(values);
}
Also used : GaussianRandomGenerator(org.apache.commons.math3.random.GaussianRandomGenerator) ArrayList(java.util.ArrayList) MersenneTwister(org.apache.commons.math3.random.MersenneTwister) Test(org.junit.Test)

Aggregations

GaussianRandomGenerator (org.apache.commons.math3.random.GaussianRandomGenerator)9 MersenneTwister (org.apache.commons.math3.random.MersenneTwister)9 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 DescriptiveStatistics (org.apache.commons.math3.stat.descriptive.DescriptiveStatistics)3 Random (java.util.Random)2 SummaryStatistics (org.apache.commons.math3.stat.descriptive.SummaryStatistics)1 BeforeClass (org.junit.BeforeClass)1