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

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


  private void initialize(int numDimensions) {
    if (initialized)
      return;
    initialized = true;
    projection = new DenseMatrix(BITS, numDimensions);
    projection.assign(new Normal(0, 1, RandomUtils.getRandom()));
  }
View Full Code Here


    Path output = getTestTempFilePath("stdDev/output.file");
    FileSystem fs = FileSystem.get(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

  @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

  @Test
  public void testSimpleOps() {

    T v0 = vectorToTest(20);
    Random gen = RandomUtils.getRandom();
    Vector v1 = v0.assign(new Normal(0, 1, gen));

    // verify that v0 and v1 share and are identical
    assertEquals(v0.get(12), v1.get(12), 0);
    v0.set(12, gen.nextDouble());
    assertEquals(v0.get(12), v1.get(12), 0);
    assertSame(v0, v1);

    Vector v2 = vectorToTest(20).assign(new Normal(0, 1, gen));
    Vector dv1 = new DenseVector(v1);
    Vector dv2 = new DenseVector(v2);
    Vector sv1 = new RandomAccessSparseVector(v1);
    Vector sv2 = new RandomAccessSparseVector(v2);
View Full Code Here

  @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.36, 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

  @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

    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 RandomWrapper 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

  @Test
  public void testSimpleOps() {

    T v0 = vectorToTest(20);
    Random gen = RandomUtils.getRandom();
    Vector v1 = v0.assign(new Normal(0, 1, gen));

    // verify that v0 and v1 share and are identical
    assertEquals(v0.get(12), v1.get(12), 0);
    v0.set(12, gen.nextDouble());
    assertEquals(v0.get(12), v1.get(12), 0);
    assertSame(v0, v1);

    Vector v2 = vectorToTest(20).assign(new Normal(0, 1, gen));
    Vector dv1 = new DenseVector(v1);
    Vector dv2 = new DenseVector(v2);
    Vector sv1 = new RandomAccessSparseVector(v1);
    Vector sv2 = new RandomAccessSparseVector(v2);
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.