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

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

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

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

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

/**
 * Constructs a Negative Binomial distribution which describes the probability of getting
 * a particular number of negative trials (k) before getting a fixed number of positive
 * trials (r) where each positive trial has probability (p) of being successful.
 *
 * @param r               the required number of positive trials.
 * @param p               the probability of success.
 * @param randomGenerator a uniform random number generator.
 */
public NegativeBinomial(int r, double p, Random randomGenerator) {
 setRandomGenerator(randomGenerator);
 this.r = r;
 this.p = p;
 this.gamma = new Gamma(r, 1, randomGenerator);
 this.poisson = new Poisson(0.0, randomGenerator);
}

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

private static double[] gamma(int n, double shape) {
  double[] r = new double[n];
  Random gen = RandomUtils.getRandom();
  AbstractContinousDistribution gamma = new Gamma(shape, shape, gen);
  for (int i = 0; i < n; i++) {
   r[i] = gamma.nextDouble();
  }
  return r;
 }
}

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

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

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

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

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

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

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

Gamma g1 = new Gamma(1, beta, gen);
Gamma g2 = new Gamma(1, 1, gen);
for (double x : seq(0, 0.99, 0.1)) {
 assertEquals(String.format(Locale.ENGLISH, "Rate invariance: x = %.4f, alpha = 1, beta = %.1f", x, beta),
Gamma g = new Gamma(alpha, 1, gen);
for (double beta : new double[]{0.1, 1, 2, 100}) {
 Gamma g1 = new Gamma(alpha, beta, gen);
 for (double x : seq(0, 0.9999, 0.001)) {
  assertEquals(

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

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

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

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

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

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

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

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

@SuppressWarnings("UnusedDeclaration")
public void setSkew(double skew) {
  if (skew < 0) {
    x = new Gamma(skew, 1, gen);
    y = new Gamma(1, 1, gen);
  } else {
    x = new Gamma(1, 1, gen);
    y = new Gamma(skew, 1, gen);
  }
}

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

Alpha test1 = new Gamma();
Beta test2 = new Gamma();
Alpha test3 = new Beta();

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

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

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

/**
 * Constructs a Negative Binomial distribution which describes the probability of getting
 * a particular number of negative trials (k) before getting a fixed number of positive
 * trials (r) where each positive trial has probability (p) of being successful.
 *
 * @param r               the required number of positive trials.
 * @param p               the probability of success.
 * @param randomGenerator a uniform random number generator.
 */
public NegativeBinomial(int r, double p, Random randomGenerator) {
 setRandomGenerator(randomGenerator);
 this.r = r;
 this.p = p;
 this.gamma = new Gamma(r, 1, randomGenerator);
 this.poisson = new Poisson(0.0, randomGenerator);
}

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

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

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

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

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

相关文章