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

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

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

Gamma.<init>介绍

[英]Constructs a Gamma distribution with a given shape (alpha) and rate (beta).
[中]构造具有给定形状(alpha)和速率(beta)的Gamma分布。

代码示例

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

  1. @Override
  2. AbstractDistribution create(Random random) {
  3. return new Gamma(0.1, 0.1, random);
  4. }
  5. },

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

  1. /**
  2. * Constructs a Negative Binomial distribution which describes the probability of getting
  3. * a particular number of negative trials (k) before getting a fixed number of positive
  4. * trials (r) where each positive trial has probability (p) of being successful.
  5. *
  6. * @param r the required number of positive trials.
  7. * @param p the probability of success.
  8. * @param randomGenerator a uniform random number generator.
  9. */
  10. public NegativeBinomial(int r, double p, Random randomGenerator) {
  11. setRandomGenerator(randomGenerator);
  12. this.r = r;
  13. this.p = p;
  14. this.gamma = new Gamma(r, 1, randomGenerator);
  15. this.poisson = new Poisson(0.0, randomGenerator);
  16. }

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

  1. private static double[] gamma(int n, double shape) {
  2. double[] r = new double[n];
  3. Random gen = RandomUtils.getRandom();
  4. AbstractContinousDistribution gamma = new Gamma(shape, shape, gen);
  5. for (int i = 0; i < n; i++) {
  6. r[i] = gamma.nextDouble();
  7. }
  8. return r;
  9. }
  10. }

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

  1. private static void checkGammaCdf(double alpha, double beta, double... values) {
  2. Gamma g = new Gamma(alpha, beta, RandomUtils.getRandom());
  3. int i = 0;
  4. for (double x : seq(0, 2 * alpha, 2 * alpha / 10)) {
  5. assertEquals(String.format(Locale.ENGLISH, "alpha=%.2f, i=%d, x=%.2f", alpha, i, x),
  6. values[i], g.cdf(x), 1.0e-7);
  7. i++;
  8. }
  9. }

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

  1. @Test
  2. public void testPdf() {
  3. Random gen = RandomUtils.getRandom();
  4. for (double alpha : new double[]{0.01, 0.1, 1, 2, 10, 100}) {
  5. for (double beta : new double[]{0.1, 1, 2, 100}) {
  6. Gamma g1 = new Gamma(alpha, beta, gen);
  7. for (double x : seq(0, 0.99, 0.1)) {
  8. double p = Math.pow(beta, alpha) * Math.pow(x, alpha - 1) *
  9. Math.exp(-beta * x - org.apache.mahout.math.jet.stat.Gamma.logGamma(alpha));
  10. assertEquals(String.format(Locale.ENGLISH, "alpha=%.2f, beta=%.2f, x=%.2f\n", alpha, beta, x),
  11. p, g1.pdf(x), 1.0e-9);
  12. }
  13. }
  14. }
  15. }
  16. }

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

  1. @Test
  2. public void testGamma() {
  3. // this Gamma distribution is very heavily skewed. The 0.1%-ile is 6.07e-30 while
  4. // the median is 0.006 and the 99.9th %-ile is 33.6 while the mean is 1.
  5. // this severe skew means that we have to have positional accuracy that
  6. // varies by over 11 orders of magnitude.
  7. Random gen = RandomUtils.getRandom();
  8. for (int i = 0; i < repeats(); i++) {
  9. runTest(new Gamma(0.1, 0.1, gen), 100,
  10. // new double[]{6.0730483624079e-30, 6.0730483624079e-20, 6.0730483627432e-10, 5.9339110446023e-03,
  11. // 2.6615455373884e+00, 1.5884778179295e+01, 3.3636770117188e+01},
  12. new double[]{0.001, 0.01, 0.1, 0.5, 0.9, 0.99, 0.999},
  13. "gamma", true, gen);
  14. }
  15. }

代码示例来源: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. Gamma g1 = new Gamma(1, beta, gen);
  2. Gamma g2 = new Gamma(1, 1, gen);
  3. for (double x : seq(0, 0.99, 0.1)) {
  4. assertEquals(String.format(Locale.ENGLISH, "Rate invariance: x = %.4f, alpha = 1, beta = %.1f", x, beta),
  5. Gamma g = new Gamma(alpha, 1, gen);
  6. for (double beta : new double[]{0.1, 1, 2, 100}) {
  7. Gamma g1 = new Gamma(alpha, beta, gen);
  8. for (double x : seq(0, 0.9999, 0.001)) {
  9. assertEquals(

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

  1. @Test(timeout=50000)
  2. public void testTimesSparseEfficiency() {
  3. Random raw = RandomUtils.getRandom();
  4. Gamma gen = new Gamma(0.1, 0.1, raw);

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

  1. @Test
  2. public void compareToQDigest() {
  3. Random rand = RandomUtils.getRandom();
  4. for (int i = 0; i < repeats(); i++) {
  5. compare(new Gamma(0.1, 0.1, rand), "gamma", 1L << 48, rand);
  6. compare(new Uniform(0, 1, rand), "uniform", 1L << 48, rand);
  7. }
  8. }

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

  1. @Test(timeout=50000)
  2. public void testTimesDenseEfficiency() {
  3. Random raw = RandomUtils.getRandom();
  4. Gamma gen = new Gamma(0.1, 0.1, raw);

代码示例来源: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 BetaDistribution(double alpha, double beta, Random random) {
  2. this.alpha = alpha;
  3. this.beta = beta;
  4. gAlpha = new Gamma(alpha, 1, random);
  5. gBeta = new Gamma(beta, 1, random);
  6. }

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

  1. @SuppressWarnings("UnusedDeclaration")
  2. public void setSkew(double skew) {
  3. if (skew < 0) {
  4. x = new Gamma(skew, 1, gen);
  5. y = new Gamma(1, 1, gen);
  6. } else {
  7. x = new Gamma(1, 1, gen);
  8. y = new Gamma(skew, 1, gen);
  9. }
  10. }

代码示例来源:origin: stackoverflow.com

  1. Alpha test1 = new Gamma();
  2. Beta test2 = new Gamma();
  3. Alpha test3 = new Beta();

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

  1. public Changer(@JsonProperty("values") List<FieldSampler> fields) {
  2. this.fields = fields;
  3. fieldNames = Lists.newArrayList();
  4. for (FieldSampler field : fields) {
  5. fieldNames.add(field.getName());
  6. }
  7. x = new Gamma(1, 1, gen);
  8. y = new Gamma(3, 1, gen);
  9. }

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

  1. /**
  2. * Constructs a Negative Binomial distribution which describes the probability of getting
  3. * a particular number of negative trials (k) before getting a fixed number of positive
  4. * trials (r) where each positive trial has probability (p) of being successful.
  5. *
  6. * @param r the required number of positive trials.
  7. * @param p the probability of success.
  8. * @param randomGenerator a uniform random number generator.
  9. */
  10. public NegativeBinomial(int r, double p, Random randomGenerator) {
  11. setRandomGenerator(randomGenerator);
  12. this.r = r;
  13. this.p = p;
  14. this.gamma = new Gamma(r, 1, randomGenerator);
  15. this.poisson = new Poisson(0.0, randomGenerator);
  16. }

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

  1. private static void checkGammaCdf(double alpha, double beta, double... values) {
  2. Gamma g = new Gamma(alpha, beta, RandomUtils.getRandom());
  3. int i = 0;
  4. for (double x : seq(0, 2 * alpha, 2 * alpha / 10)) {
  5. assertEquals(String.format(Locale.ENGLISH, "alpha=%.2f, i=%d, x=%.2f", alpha, i, x),
  6. values[i], g.cdf(x), 1.0e-7);
  7. i++;
  8. }
  9. }

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

  1. @Test
  2. public void testPdf() {
  3. Random gen = RandomUtils.getRandom();
  4. for (double alpha : new double[]{0.01, 0.1, 1, 2, 10, 100}) {
  5. for (double beta : new double[]{0.1, 1, 2, 100}) {
  6. Gamma g1 = new Gamma(alpha, beta, gen);
  7. for (double x : seq(0, 0.99, 0.1)) {
  8. double p = Math.pow(beta, alpha) * Math.pow(x, alpha - 1) *
  9. Math.exp(-beta * x - org.apache.mahout.math.jet.stat.Gamma.logGamma(alpha));
  10. assertEquals(String.format(Locale.ENGLISH, "alpha=%.2f, beta=%.2f, x=%.2f\n", alpha, beta, x),
  11. p, g1.pdf(x), 1.0e-9);
  12. }
  13. }
  14. }
  15. }
  16. }

代码示例来源: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. }

相关文章