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

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

本文整理了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

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

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

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

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

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

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

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

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

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

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

@Test(timeout=50000)
public void testTimesOtherSparseEfficiency() {
 Random raw = RandomUtils.getRandom();
 Gamma gen = new Gamma(0.1, 0.1, raw);
 // build a sequential sparse matrix and a diagonal matrix and multiply them
 Matrix x = new SparseRowMatrix(1000, 2000, false);
 for (int i = 0; i < 1000; i++) {
  int[] values = new int[1000];
  for (int k = 0; k < 1000; k++) {
   int j = (int) Math.min(1000, gen.nextDouble());
   values[j]++;
  }
  for (int j = 0; j < 1000; j++) {
   if (values[j] > 0) {
    x.set(i, j, values[j]);
   }
  }
 }
 Vector d = new DenseVector(2000).assign(Functions.random());
 Matrix y = new DiagonalMatrix(d);
 long t0 = System.nanoTime();
 Matrix z = x.times(y);
 double elapsedTime = (System.nanoTime() - t0) * 1e-6;
 System.out.printf("done in %.1f ms\n", elapsedTime);
 for (MatrixSlice row : z) {
  for (Vector.Element element : row.nonZeroes()) {
   assertEquals(x.get(row.index(), element.index()) * d.get(element.index()), element.get(), 1e-12);
  }
 }
}

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

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

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

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

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

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

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

/**
 * Returns a random number from the distribution.
 *
 * @return A new sample from this distribution.
 */
@Override
public double nextDouble() {
  double x = gAlpha.nextDouble(alpha, 1);
  double y = gBeta.nextDouble(beta, 1);
  return x / (x + y);
}

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

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

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

private int pickField() {
    double xValue = x.nextDouble();
    double yValue = y.nextDouble();
    double beta = xValue / (xValue + yValue);
    return (int) Math.floor(beta * fieldNames.size());
  }
}

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

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

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

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

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

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

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

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

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

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

相关文章