org.apache.mahout.math.jet.random.Uniform Java Examples

The following examples show how to use org.apache.mahout.math.jet.random.Uniform. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TDigestTest.java    From streaminer with Apache License 2.0 6 votes vote down vote up
@Test
public void testNarrowNormal() {
    // this mixture of a uniform and normal distribution has a very narrow peak which is centered
    // near the median.  Our system should be scale invariant and work well regardless.
    final Random gen = RandomUtils.getRandom();
    AbstractContinousDistribution mix = new AbstractContinousDistribution() {
        AbstractContinousDistribution normal = new Normal(0, 1e-5, gen);
        AbstractContinousDistribution uniform = new Uniform(-1, 1, gen);

        @Override
        public double nextDouble() {
            double x;
            if (gen.nextDouble() < 0.5) {
                x = uniform.nextDouble();
            } else {
                x = normal.nextDouble();
            }
            return x;
        }
    };

    for (int i = 0; i < repeats(); i++) {
        runTest(mix, 100, new double[]{0.001, 0.01, 0.1, 0.3, 0.5, 0.7, 0.9, 0.99, 0.999}, "mixture", false, gen);
    }
}
 
Example #2
Source File: TDigestTest.java    From t-digest with Apache License 2.0 6 votes vote down vote up
@Test
public void testNarrowNormal() {
    // this mixture of a uniform and normal distribution has a very narrow peak which is centered
    // near the median.  Our system should be scale invariant and work well regardless.
    final Random gen = getRandom();
    AbstractContinousDistribution mix = new AbstractContinousDistribution() {
        final AbstractContinousDistribution normal = new Normal(0, 1e-5, gen);
        final AbstractContinousDistribution uniform = new Uniform(-1, 1, gen);

        @Override
        public double nextDouble() {
            double x;
            if (gen.nextDouble() < 0.5) {
                x = uniform.nextDouble();
            } else {
                x = normal.nextDouble();
            }
            return x;
        }
    };

    for (int i = 0; i < repeats(); i++) {
        runTest(factory(400), mix, new double[]{0.001, 0.01, 0.1, 0.3, 0.5, 0.7, 0.9, 0.99, 0.999}, "mixture", false);
    }
}
 
Example #3
Source File: TDigestTest.java    From streaminer with Apache License 2.0 5 votes vote down vote up
@Test
public void testUniform() {
    Random gen = RandomUtils.getRandom();
    for (int i = 0; i < repeats(); i++) {
        runTest(new Uniform(0, 1, gen), 100,
                new double[]{0.001, 0.01, 0.1, 0.5, 0.9, 0.99, 0.999},
                "uniform", true, gen);
    }
}
 
Example #4
Source File: TDigestTest.java    From streaminer with Apache License 2.0 5 votes vote down vote up
@Test
public void compareToQDigest() {
    Random rand = RandomUtils.getRandom();

    for (int i = 0; i < repeats(); i++) {
        compare(new Gamma(0.1, 0.1, rand), "gamma", 1L << 48, rand);
        compare(new Uniform(0, 1, rand), "uniform", 1L << 48, rand);
    }
}
 
Example #5
Source File: ComparisonTest.java    From t-digest with Apache License 2.0 5 votes vote down vote up
@Test
public void compareToQDigest() throws FileNotFoundException {
    Random rand = new Random();
    try (PrintWriter out = new PrintWriter(new FileOutputStream("qd-tree-comparison.csv"))) {
        out.printf("tag,compression,q,e1,e2,t.size,q.size\n");

        for (int i = 0; i < M; i++) {
            compareQD(out, new Gamma(0.1, 0.1, rand), "gamma", 1L << 48);
            // the bounds for the uniform distribution are varied to avoid round off effects
            compareQD(out, new Uniform(0, rand.nextDouble() * 0.05 + 1.01, rand), "uniform", 1L << 48);
        }
    }
}
 
Example #6
Source File: ComparisonTest.java    From t-digest with Apache License 2.0 5 votes vote down vote up
@Test
public void compareToStreamingQuantile() throws FileNotFoundException {
    Random rand = new Random();

    try (PrintWriter out = new PrintWriter(new FileOutputStream("sq-tree-comparison.csv"))) {
        out.printf("tag,compression,q,e1,e2,t.size,q.size\n");
        for (int i = 0; i < M; i++) {
            compareSQ(out, new Gamma(0.1, 0.1, rand), "gamma");
            compareSQ(out, new Uniform(0, 1, rand), "uniform");
        }
    }
}
 
Example #7
Source File: TDigestTest.java    From t-digest with Apache License 2.0 5 votes vote down vote up
@Test
public void testUniform() {
    Random gen = getRandom();
    for (int i = 0; i < repeats(); i++) {
        runTest(factory(), new Uniform(0, 1, gen),
                new double[]{0.001, 0.01, 0.1, 0.5, 0.9, 0.99, 0.999},
                "uniform", true);
    }
}
 
Example #8
Source File: Util.java    From t-digest with Apache License 2.0 4 votes vote down vote up
@Override
public AbstractContinousDistribution create(Random gen) {
    return new Uniform(0, 1, gen);
}
 
Example #9
Source File: DateSampler.java    From log-synth with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("UnusedDeclaration")
public void setStart(String start) throws ParseException {
    this.start = df.parse(start).getTime();
    base = new Uniform(0, this.end - this.start, RandomUtils.getRandom());
}
 
Example #10
Source File: DateSampler.java    From log-synth with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("UnusedDeclaration")
public void setEnd(String end) throws ParseException {
    this.end = df.parse(end).getTime();
    base = new Uniform(0, this.end - this.start, RandomUtils.getRandom());
}