org.apache.mahout.math.jet.random.Normal类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(85)

本文整理了Java中org.apache.mahout.math.jet.random.Normal类的一些代码示例,展示了Normal类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Normal类的具体详情如下:
包路径:org.apache.mahout.math.jet.random.Normal
类名称:Normal

Normal介绍

[英]Implements a normal distribution specified mean and standard deviation.
[中]实现正态分布指定的平均值和标准偏差。

代码示例

代码示例来源:origin: apache/mahout

@Test
public void testSetState() throws Exception {
 Normal dist = new Normal(0, 1, RandomUtils.getRandom());
 dist.setState(1.3, 5.9);
 DistributionChecks.checkDistribution(dist, breaks, 1.3, 5.9, 10000);
}

代码示例来源:origin: apache/mahout

double b5 = 1.330274429;
double t = 1 / (1 + b0 * a);
return 1 - UNIT_NORMAL.pdf(a) * t * (b1 + t * (b2 + t * (b3 + t * (b4 + t * b5))));

代码示例来源:origin: apache/mahout

/**
 * Returns a random number from the distribution.
 */
@Override
public double nextDouble() {
 // Uses polar Box-Muller transformation.
 if (cacheFilled) {
  cacheFilled = false;
  return cache;
 }
 double x;
 double y;
 double r;
 do {
  x = 2.0 * randomDouble() - 1.0;
  y = 2.0 * randomDouble() - 1.0;
  r = x * x + y * y;
 } while (r >= 1.0);
 double z = Math.sqrt(-2.0 * Math.log(r) / r);
 cache = this.mean + this.standardDeviation * x * z;
 cacheFilled = true;
 return this.mean + this.standardDeviation * y * z;
}

代码示例来源:origin: apache/mahout

/**
 * @param mean               The mean of the resulting distribution.
 * @param standardDeviation  The standard deviation of the distribution.
 * @param randomGenerator    The random number generator to use.  This can be null if you don't
 * need to generate any numbers.
 */
public Normal(double mean, double standardDeviation, Random randomGenerator) {
 setRandomGenerator(randomGenerator);
 setState(mean, standardDeviation);
}

代码示例来源:origin: apache/mahout

@Test
 public void testToString() {
  assertEquals("org.apache.mahout.math.jet.random.Normal(m=1.300000, sd=5.900000)",
    new Normal(1.3, 5.9, null).toString());
 }
}

代码示例来源:origin: tdunning/t-digest

@Override
  AbstractDistribution create(Random random) {
    return new Normal(0.1, 0.1, random);
  }
};

代码示例来源:origin: org.apache.mahout/mahout-mrlegacy

@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);
  assertEquals(-2.36, m.get(1, 0), 0.02);
  assertEquals(-0.35, m.get(1, 1), 0.02);
 }
}

代码示例来源:origin: org.apache.mahout/mahout-mrlegacy

@Test
public void testStdDev2() throws Exception {
 Path input = getTestTempFilePath("stdDev/counts.file");
 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);
}

代码示例来源:origin: tdunning/bandit-ranking

/**
 * Returns a random number from the distribution.
 *
 * @return A new sample from this distribution.
 */
@Override
public double nextDouble() {
  double variance = nextVariance();
  double mean = nd.nextDouble() * Math.sqrt(variance / n) + m;
  return nd.nextDouble() * Math.sqrt(variance) + mean;
}

代码示例来源:origin: apache/mahout

@Test
public void testCdf() {
 Random gen = RandomUtils.getRandom();
 double offset = 0;
 double scale = 1;
 for (int k = 0; k < 20; k++) {
  Normal dist = new Normal(offset, scale, null);
  DistributionChecks.checkCdf(offset, scale, dist, breaks, quantiles);
  offset = gen.nextGaussian();
  scale = Math.exp(3 * gen.nextGaussian());
 }
}

代码示例来源:origin: cloudera/mahout

@Test
 public void testToString() {
  assertEquals("org.apache.mahout.math.jet.random.Normal(m=1.300000, sd=5.900000)",
    new Normal(1.3, 5.9, null).toString());
 }
}

代码示例来源:origin: org.apache.mahout/mahout-math

/**
 * @param mean               The mean of the resulting distribution.
 * @param standardDeviation  The standard deviation of the distribution.
 * @param randomGenerator    The random number generator to use.  This can be null if you don't
 * need to generate any numbers.
 */
public Normal(double mean, double standardDeviation, Random randomGenerator) {
 setRandomGenerator(randomGenerator);
 setState(mean, standardDeviation);
}

代码示例来源:origin: tdunning/log-synth

@Override
  public JsonNode sample() {
    double x;
    do {
      x = rand.nextDouble();
    } while (x < min || x > max);
    return new DoubleNode(x);
  }
}

代码示例来源:origin: apache/mahout

@Test
public void consistency() {
 Random gen = RandomUtils.getRandom();
 double offset = 0;
 double scale = 1;
 Normal dist = new Normal(offset, scale, RandomUtils.getRandom());
 for (int k = 0; k < 20; k++) {
  dist.setState(offset, scale);
  DistributionChecks.checkDistribution(dist, breaks, offset, scale, 10000);
  offset = gen.nextGaussian();
  scale = Math.exp(3 * gen.nextGaussian());
 }
}

代码示例来源:origin: addthis/stream-lib

@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);
  }
}

代码示例来源:origin: cloudera/mahout

/**
 * @param mean               The mean of the resulting distribution.
 * @param standardDeviation  The standard deviation of the distribution.
 * @param randomGenerator    The random number generator to use.  This can be null if you don't
 * need to generate any numbers.
 */
public Normal(double mean, double standardDeviation, Random randomGenerator) {
 setRandomGenerator(randomGenerator);
 setState(mean, standardDeviation);
}

代码示例来源:origin: org.apache.mahout/mahout-math

double b5 = 1.330274429;
double t = 1 / (1 + b0 * a);
return 1 - UNIT_NORMAL.pdf(a) * t * (b1 + t * (b2 + t * (b3 + t * (b4 + t * b5))));

代码示例来源:origin: tdunning/bandit-ranking

@Override
public double nextMean() {
  double sd = Math.sqrt(nextVariance() / n);
  return nd.nextDouble() * sd + m;
}

代码示例来源:origin: cloudera/mahout

/**
 * Returns a random number from the distribution.
 */
@Override
public double nextDouble() {
 // Uses polar Box-Muller transformation.
 if (cacheFilled) {
  cacheFilled = false;
  return cache;
 }
 double x;
 double y;
 double r;
 do {
  x = 2.0 * randomDouble() - 1.0;
  y = 2.0 * randomDouble() - 1.0;
  r = x * x + y * y;
 } while (r >= 1.0);
 double z = Math.sqrt(-2.0 * Math.log(r) / r);
 cache = this.mean + this.standardDeviation * x * z;
 cacheFilled = true;
 return this.mean + this.standardDeviation * y * z;
}

代码示例来源:origin: cloudera/mahout

@Test
public void testSetState() throws Exception {
 Normal dist = new Normal(0, 1, RandomUtils.getRandom());
 dist.setState(1.3, 5.9);
 DistributionChecks.checkDistribution(dist, breaks, 1.3, 5.9, 10000);
}

相关文章