org.apache.mahout.math.jet.random.Gamma.nextDouble()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(155)

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

Gamma.nextDouble介绍

[英]Returns a random number from the distribution.
[中]从分布中返回一个随机数。

代码示例

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

  1. /** Returns a random number from the distribution. */
  2. @Override
  3. public double nextDouble() {
  4. return nextDouble(alpha, rate);
  5. }

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

  1. /**
  2. * Returns a sample from this distribution. The value returned will
  3. * be the number of negative samples required before achieving r
  4. * positive samples. Each successive sample is taken independently
  5. * from a Bernouli process with probability p of success.
  6. *
  7. * The algorithm used is taken from J.H. Ahrens, U. Dieter (1974):
  8. * Computer methods for sampling from gamma, beta, Poisson and
  9. * binomial distributions, Computing 12, 223--246.
  10. *
  11. * This algorithm is essentially the same as described at
  12. * http://en.wikipedia.org/wiki/Negative_binomial_distribution#Gamma.E2.80.93Poisson_mixture
  13. * except that the notion of positive and negative outcomes is uniformly
  14. * inverted. Because the inversion is complete and consistent, this
  15. * definition is effectively identical to that defined on wikipedia.
  16. */
  17. public int nextInt(int r, double p) {
  18. return this.poisson.nextInt(gamma.nextDouble(r, p / (1.0 - p)));
  19. }

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

  1. int[] values = new int[1000];
  2. for (int k = 0; k < 1000; k++) {
  3. int j = (int) Math.min(1000, gen.nextDouble());
  4. values[j]++;
  5. int[] values = new int[1000];
  6. for (int k = 0; k < 1000; k++) {
  7. int j = (int) Math.min(1000, gen.nextDouble());
  8. values[j]++;

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

  1. @Test
  2. public void testNextDouble() {
  3. double[] z = new double[100000];
  4. Random gen = RandomUtils.getRandom();
  5. for (double alpha : new double[]{1, 2, 10, 0.1, 0.01, 100}) {
  6. Gamma g = new Gamma(alpha, 1, gen);
  7. for (int i = 0; i < z.length; i++) {
  8. z[i] = g.nextDouble();
  9. }
  10. Arrays.sort(z);
  11. // verify that empirical CDF matches theoretical one pretty closely
  12. for (double q : seq(0.01, 1, 0.01)) {
  13. double p = z[(int) (q * z.length)];
  14. assertEquals(q, g.cdf(p), 0.01);
  15. }
  16. }
  17. }

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

  1. int[] values = new int[1000];
  2. for (int k = 0; k < 1000; k++) {
  3. int j = (int) Math.min(1000, gen.nextDouble());
  4. values[j]++;

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

  1. @Test(timeout=50000)
  2. public void testTimesOtherSparseEfficiency() {
  3. Random raw = RandomUtils.getRandom();
  4. Gamma gen = new Gamma(0.1, 0.1, raw);
  5. // build a sequential sparse matrix and a diagonal matrix and multiply them
  6. Matrix x = new SparseRowMatrix(1000, 2000, false);
  7. for (int i = 0; i < 1000; i++) {
  8. int[] values = new int[1000];
  9. for (int k = 0; k < 1000; k++) {
  10. int j = (int) Math.min(1000, gen.nextDouble());
  11. values[j]++;
  12. }
  13. for (int j = 0; j < 1000; j++) {
  14. if (values[j] > 0) {
  15. x.set(i, j, values[j]);
  16. }
  17. }
  18. }
  19. Vector d = new DenseVector(2000).assign(Functions.random());
  20. Matrix y = new DiagonalMatrix(d);
  21. long t0 = System.nanoTime();
  22. Matrix z = x.times(y);
  23. double elapsedTime = (System.nanoTime() - t0) * 1e-6;
  24. System.out.printf("done in %.1f ms\n", elapsedTime);
  25. for (MatrixSlice row : z) {
  26. for (Vector.Element element : row.nonZeroes()) {
  27. assertEquals(x.get(row.index(), element.index()) * d.get(element.index()), element.get(), 1e-12);
  28. }
  29. }
  30. }

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

  1. public double nextDouble(double alpha, double beta) {
  2. double x = gAlpha.nextDouble(alpha, 1);
  3. double y = gBeta.nextDouble(beta, 1);
  4. return x / (x + y);
  5. }

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

  1. /** Returns a random number from the distribution. */
  2. @Override
  3. public double nextDouble() {
  4. return nextDouble(alpha, rate);
  5. }

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

  1. /** Returns a random number from the distribution. */
  2. @Override
  3. public double nextDouble() {
  4. return nextDouble(alpha, rate);
  5. }

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

  1. /**
  2. * Returns a random number from the distribution.
  3. *
  4. * @return A new sample from this distribution.
  5. */
  6. @Override
  7. public double nextDouble() {
  8. double x = gAlpha.nextDouble(alpha, 1);
  9. double y = gBeta.nextDouble(beta, 1);
  10. return x / (x + y);
  11. }

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

  1. private double nextVariance() {
  2. return 1 / gd.nextDouble(n / 2, ss / 2);
  3. }
  4. }

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

  1. private int pickField() {
  2. double xValue = x.nextDouble();
  3. double yValue = y.nextDouble();
  4. double beta = xValue / (xValue + yValue);
  5. return (int) Math.floor(beta * fieldNames.size());
  6. }
  7. }

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

  1. @Override
  2. public JsonNode sample() {
  3. return new DoubleNode(rand.nextDouble());
  4. }

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

  1. /**
  2. * Returns a sample from this distribution. The value returned will
  3. * be the number of negative samples required before achieving r
  4. * positive samples. Each successive sample is taken independently
  5. * from a Bernouli process with probability p of success.
  6. *
  7. * The algorithm used is taken from J.H. Ahrens, U. Dieter (1974):
  8. * Computer methods for sampling from gamma, beta, Poisson and
  9. * binomial distributions, Computing 12, 223--246.
  10. *
  11. * This algorithm is essentially the same as described at
  12. * http://en.wikipedia.org/wiki/Negative_binomial_distribution#Gamma.E2.80.93Poisson_mixture
  13. * except that the notion of positive and negative outcomes is uniformly
  14. * inverted. Because the inversion is complete and consistent, this
  15. * definition is effectively identical to that defined on wikipedia.
  16. */
  17. public int nextInt(int r, double p) {
  18. return this.poisson.nextInt(gamma.nextDouble(r, p / (1.0 - p)));
  19. }

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

  1. /**
  2. * Returns a sample from this distribution. The value returned will
  3. * be the number of negative samples required before achieving r
  4. * positive samples. Each successive sample is taken independently
  5. * from a Bernouli process with probability p of success.
  6. *
  7. * The algorithm used is taken from J.H. Ahrens, U. Dieter (1974):
  8. * Computer methods for sampling from gamma, beta, Poisson and
  9. * binomial distributions, Computing 12, 223--246.
  10. *
  11. * This algorithm is essentially the same as described at
  12. * http://en.wikipedia.org/wiki/Negative_binomial_distribution#Gamma.E2.80.93Poisson_mixture
  13. * except that the notion of positive and negative outcomes is uniformly
  14. * inverted. Because the inversion is complete and consistent, this
  15. * definition is effectively identical to that defined on wikipedia.
  16. */
  17. public int nextInt(int r, double p) {
  18. return this.poisson.nextInt(gamma.nextDouble(r, p / (1.0 - p)));
  19. }

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

  1. double averageInterval = TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS) / transactionsPerDay.nextDouble();
  2. Exponential interval = new Exponential(1 / averageInterval, gen);

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

  1. @Test
  2. public void testNextDouble() {
  3. double[] z = new double[100000];
  4. Random gen = RandomUtils.getRandom();
  5. for (double alpha : new double[]{1, 2, 10, 0.1, 0.01, 100}) {
  6. Gamma g = new Gamma(alpha, 1, gen);
  7. for (int i = 0; i < z.length; i++) {
  8. z[i] = g.nextDouble();
  9. }
  10. Arrays.sort(z);
  11. // verify that empirical CDF matches theoretical one pretty closely
  12. for (double q : seq(0.01, 1, 0.01)) {
  13. double p = z[(int) (q * z.length)];
  14. assertEquals(q, g.cdf(p), 0.01);
  15. }
  16. }
  17. }

相关文章