Package org.apache.mahout.math.jet.random

Examples of org.apache.mahout.math.jet.random.Normal


  @Test
  public void testEntropy() {
    Auc auc = new Auc();
    Random gen = RandomUtils.getRandom();
    Normal n0 = new Normal(-1, 1, gen);
    Normal n1 = new Normal(1, 1, gen);
    for (int i=0; i<100000; i++) {
      double score = n0.nextDouble();
      double p = n1.pdf(score) / (n0.pdf(score) + n1.pdf(score));
      auc.add(0, p);

      score = n1.nextDouble();
      p = n1.pdf(score) / (n0.pdf(score) + n1.pdf(score));
      auc.add(1, p);
    }
    Matrix m = auc.entropy();
    assertEquals(-0.35, m.get(0, 0), 0.02);
    assertEquals(-2.34, m.get(0, 1), 0.02);
View Full Code Here


    Path output = getTestTempFilePath("stdDev/output.file");
    FileSystem fs = FileSystem.get(input.toUri(), conf);
    SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf, input, IntWritable.class,
            DoubleWritable.class);
    Random random = RandomUtils.getRandom();
    Normal normal = new Normal(5, 3, random);
    for (int i = 0; i < 1000000; i++) {
      writer.append(new IntWritable(i), new DoubleWritable((long) normal.nextInt()));
    }
    writer.close();
    double v = BasicStats.stdDev(input, output, conf);
    assertEquals(3, v, 0.02);
  }
View Full Code Here

    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;
            }
        };
View Full Code Here

    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;
            }
        };
View Full Code Here

    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;
            }
        };
View Full Code Here

        return nd.nextDouble() * sd + m;
    }

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

    }

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

TOP

Related Classes of org.apache.mahout.math.jet.random.Normal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.