Example usage for org.apache.mahout.math.jet.random Normal Normal

List of usage examples for org.apache.mahout.math.jet.random Normal Normal

Introduction

In this page you can find the example usage for org.apache.mahout.math.jet.random Normal Normal.

Prototype

public Normal(double mean, double standardDeviation, Random randomGenerator) 

Source Link

Usage

From source file:com.clearspring.analytics.stream.quantile.TDigestTest.java

License:Apache License

@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//w  ww .  jav a 2 s .  com
        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);
    }
}

From source file:com.mapr.stats.GammaNormalDistribution.java

License:Apache License

@Override
public AbstractContinousDistribution posteriorDistribution() {
    return new Normal(m, Math.sqrt(ss / n), gen);
}

From source file:com.mapr.stats.NormalDistributionSampler.java

License:Apache License

@Override
public DistributionWithMean nextDistribution() {
    double mean = gen.nextDouble();
    return new DistributionWithMean(new Normal(mean, sd, gen), mean);
}

From source file:com.tdunning.math.stats.ArrayDigestTest.java

License:Apache License

@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/*from   w ww .jav  a 2  s . c  o m*/
        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, mix, 100, new double[] { 0.001, 0.01, 0.1, 0.3, 0.5, 0.7, 0.9, 0.99, 0.999 },
                "mixture", false);
    }
}

From source file:org.elasticsearch.search.aggregations.metrics.TDigestStateTests.java

License:Apache License

@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() {
        AbstractContinousDistribution normal = new Normal(0, 1e-5, gen);
        AbstractContinousDistribution uniform = new Uniform(-1, 1, gen);

        @Override/*w ww . j  a  va 2  s . c  o m*/
        public double nextDouble() {
            double x;
            if (gen.nextDouble() < 0.5) {
                x = uniform.nextDouble();
            } else {
                x = normal.nextDouble();
            }
            return x;
        }
    };

    for (int i = 0; i < 10; 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");
    }
}

From source file:pickleencoder.PrepareData.java

public Double[] create_gmm_histogram(Double[] p, Double[] m, Double[] s, Double[] bin_edges) {

    int bins = Array.getLength(bin_edges);
    int size = Array.getLength(p);
    //        hist = np.zeros(bin_edges.shape[0]+1)
    Double[] hist = new Double[bins + 1];
    Double[] temp = new Double[bins + 1];
    //    hist[:-1] = (norm.cdf(bin_edges[np.newaxis].T, loc = m, scale = np.sqrt(s)) * p).sum(axis = 1)
    for (int i = 0; i < bins; i++) {
        temp[i] = 0.0;/*from   w  w w  .java2s.c  o  m*/
        //              System.out.println("i" + i);
        for (int j = 0; j < size; j++) {
            Normal n = new Normal(m[j], Math.sqrt(s[j]), null);
            temp[i] += n.cdf(bin_edges[i]) * p[j];
        }
        //            System.out.println(temp[i]);
        //            norm[i] = Gaussian.cdf(bin_edges[i], m[i], Math.sqrt(s[i]));
    }

    //    hist[-1] = 1.0
    temp[bins] = 1.0;
    hist[0] = temp[0];
    //    hist[1:] = (hist[1:] - hist[:-1])
    for (int i = 1; i <= bins; i++) {
        //            System.out.println(temp[i] + " - " + temp[i-1] + " = " + (temp[i] - temp[i-1]));
        hist[i] = temp[i] - temp[i - 1];
    }
    return hist;
}