gpt4 book ai didi

org.apache.commons.math3.distribution.ZipfDistribution类的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 07:04:49 26 4
gpt4 key购买 nike

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

ZipfDistribution介绍

[英]Implementation of the Zipf distribution.

Parameters: For a random variable X whose values are distributed according to this distribution, the probability mass function is given by

P(X = k) = H(N,s) * 1 / k^s    for  
 k = 1,2,...,N.

H(N,s) is the normalizing constant which corresponds to the generalized harmonic number of order N of s.

  • N is the number of elements
  • s is the exponent
    [中]Zipf分布的实现。
    参数:对于一个随机变量X,其值按照该分布分布,概率质量函数如下所示:
P(X = k) = H(N,s) * 1 / k^s    for  
 k = 1,2,...,N.

H(N,s)是对应于s的N阶广义调和数的归一化常数。
*N是元素的数量
*s是指数

代码示例

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * Generates a random value from the {@link ZipfDistribution Zipf Distribution}.
 *
 * @param numberOfElements the number of elements of the ZipfDistribution
 * @param exponent the exponent of the ZipfDistribution
 * @return random value sampled from the Zipf(numberOfElements, exponent) distribution
 * @exception NotStrictlyPositiveException if {@code numberOfElements <= 0}
 * or {@code exponent <= 0}.
 */
public int nextZipf(int numberOfElements, double exponent) throws NotStrictlyPositiveException {
  return new ZipfDistribution(getRandomGenerator(), numberOfElements, exponent).sample();
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * Used by {@link #getNumericalVariance()}.
 *
 * @return the variance of this distribution
 */
protected double calculateNumericalVariance() {
  final int N = getNumberOfElements();
  final double s = getExponent();
  final double Hs2 = generalizedHarmonic(N, s - 2);
  final double Hs1 = generalizedHarmonic(N, s - 1);
  final double Hs = generalizedHarmonic(N, s);
  return (Hs2 / Hs) - ((Hs1 * Hs1) / (Hs * Hs));
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * {@inheritDoc}
 *
 * For number of elements {@code N} and exponent {@code s}, the mean is
 * {@code Hs1 / Hs}, where
 * <ul>
 *  <li>{@code Hs1 = generalizedHarmonic(N, s - 1)},</li>
 *  <li>{@code Hs = generalizedHarmonic(N, s)}.</li>
 * </ul>
 */
public double getNumericalMean() {
  if (!numericalMeanIsCalculated) {
    numericalMean = calculateNumericalMean();
    numericalMeanIsCalculated = true;
  }
  return numericalMean;
}

代码示例来源:origin: Netflix/ndbench

public ZipfianStringKeyGenerator(boolean preLoadKeys, int numKeys, double exponent) {
  super(numKeys, preLoadKeys);
  this.zipf = new ZipfDistribution(numKeys, exponent);
}

代码示例来源:origin: geogebra/geogebra

/**
 * @param param
 *            number of elements
 * @param param2
 *            exponent
 * @return Zipf distribution
 */
ZipfDistribution getZipfDistribution(int param, double param2) {
  if (zipf == null || zipf.getNumberOfElements() != param
      || zipf.getExponent() != param2) {
    zipf = new ZipfDistribution(param, param2);
  }
  return zipf;
}

代码示例来源:origin: apache/incubator-druid

Integer startInt = schema.getStartInt();
cardinality = schema.getEndInt() - startInt;
ZipfDistribution zipf = new ZipfDistribution(cardinality, schema.getZipfExponent());
for (int i = 0; i < cardinality; i++) {
 probabilities.add(new Pair<>((Object) (i + startInt), zipf.probability(i)));
ZipfDistribution zipf = new ZipfDistribution(enumeratedValues.size(), schema.getZipfExponent());
for (int i = 0; i < cardinality; i++) {
 probabilities.add(new Pair<>(enumeratedValues.get(i), zipf.probability(i)));

代码示例来源:origin: deeplearning4j/Arbiter

ZipfDistribution za = (ZipfDistribution) a;
  ZipfDistribution zb = (ZipfDistribution) b;
  return za.getNumberOfElements() == zb.getNumberOfElements() && za.getExponent() == zb.getNumberOfElements();
} else {
  throw new UnsupportedOperationException("Unknown or not supported IntegerDistribution: " + c);

代码示例来源:origin: org.apache.accumulo/accumulo-test

ZipfDistribution zdiBanks = new ZipfDistribution((Integer) state.get("numBanks"), 1);
String bank = Utils.getBank(zdiBanks.inverseCumulativeProbability(rand.nextDouble()));
ZipfDistribution zdiAccts = new ZipfDistribution(numAccts, 1);
String acct1 = Utils.getAccount(zdiAccts.inverseCumulativeProbability(rand.nextDouble()));
String acct2 = Utils.getAccount(zdiAccts.inverseCumulativeProbability(rand.nextDouble()));
while (acct2.equals(acct1)) {

代码示例来源:origin: johnlpage/POCDriver

private int getNextVal(int mult) {
  int rval;
  if (zipfian) {
    rval = zipf.sample();
  } else {
    rval = (int) Math.abs(Math.floor(rng.nextDouble() * mult));
  }
  return rval;
}

代码示例来源:origin: org.apache.commons/commons-math3

/** {@inheritDoc} */
public double cumulativeProbability(final int x) {
  if (x <= 0) {
    return 0.0;
  } else if (x >= numberOfElements) {
    return 1.0;
  }
  return generalizedHarmonic(x, exponent) / generalizedHarmonic(numberOfElements, exponent);
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * {@inheritDoc}
 *
 * The upper bound of the support is the number of elements.
 *
 * @return upper bound of the support
 */
public int getSupportUpperBound() {
  return getNumberOfElements();
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * {@inheritDoc}
 *
 * For number of elements {@code N} and exponent {@code s}, the mean is
 * {@code (Hs2 / Hs) - (Hs1^2 / Hs^2)}, where
 * <ul>
 *  <li>{@code Hs2 = generalizedHarmonic(N, s - 2)},</li>
 *  <li>{@code Hs1 = generalizedHarmonic(N, s - 1)},</li>
 *  <li>{@code Hs = generalizedHarmonic(N, s)}.</li>
 * </ul>
 */
public double getNumericalVariance() {
  if (!numericalVarianceIsCalculated) {
    numericalVariance = calculateNumericalVariance();
    numericalVarianceIsCalculated = true;
  }
  return numericalVariance;
}

代码示例来源:origin: com.netflix.ndbench/ndbench-core

public ZipfianStringKeyGenerator(boolean preLoadKeys, int numKeys, double exponent) {
  super(numKeys, preLoadKeys);
  this.zipf = new ZipfDistribution(numKeys, exponent);
}

代码示例来源:origin: org.deeplearning4j/arbiter-core

ZipfDistribution za = (ZipfDistribution) a;
  ZipfDistribution zb = (ZipfDistribution) b;
  return za.getNumberOfElements() == zb.getNumberOfElements() && za.getExponent() == zb.getNumberOfElements();
} else {
  throw new UnsupportedOperationException("Unknown or not supported IntegerDistribution: " + c);

代码示例来源:origin: com.netflix.ndbench/ndbench-core

@Override
  public String getNextKey() {
    int keyIndex = zipf.sample();
    if (isPreLoadKeys()) {
      return keys.get(keyIndex);
    } else {
      return "T" + keyIndex;
    }
  }
}

代码示例来源:origin: org.apache.commons/commons-math3

/** {@inheritDoc} */
public double probability(final int x) {
  if (x <= 0 || x > numberOfElements) {
    return 0.0;
  }
  return (1.0 / FastMath.pow(x, exponent)) / generalizedHarmonic(numberOfElements, exponent);
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

/**
 * {@inheritDoc}
 *
 * The upper bound of the support is the number of elements.
 *
 * @return upper bound of the support
 */
public int getSupportUpperBound() {
  return getNumberOfElements();
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

/**
 * {@inheritDoc}
 *
 * For number of elements {@code N} and exponent {@code s}, the mean is
 * {@code (Hs2 / Hs) - (Hs1^2 / Hs^2)}, where
 * <ul>
 *  <li>{@code Hs2 = generalizedHarmonic(N, s - 2)},</li>
 *  <li>{@code Hs1 = generalizedHarmonic(N, s - 1)},</li>
 *  <li>{@code Hs = generalizedHarmonic(N, s)}.</li>
 * </ul>
 */
public double getNumericalVariance() {
  if (!numericalVarianceIsCalculated) {
    numericalVariance = calculateNumericalVariance();
    numericalVarianceIsCalculated = true;
  }
  return numericalVariance;
}

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

protected String prepareTestDate() throws IOException {
  String[] allKeys = new String[KEY_SPACE];
  for (int i = 0; i < KEY_SPACE; i++) {
    allKeys[i] = RandomStringUtils.randomAlphabetic(10);
  }
  outputMsg("Start to create test random data...");
  long startTime = System.currentTimeMillis();
  ZipfDistribution zipf = new ZipfDistribution(KEY_SPACE, 0.5);
  int keyIndex;
  File tempFile = File.createTempFile("ZipfDistribution", ".txt");
  if (tempFile.exists())
    FileUtils.forceDelete(tempFile);
  Writer fw = new OutputStreamWriter(new FileOutputStream(tempFile), StandardCharsets.UTF_8);
  try {
    for (int i = 0; i < TOTAL_RECORDS; i++) {
      keyIndex = zipf.sample() - 1;
      fw.write(allKeys[keyIndex]);
      fw.write('\n');
    }
  } finally {
    if (fw != null)
      fw.close();
  }
  outputMsg("Create test data takes : " + (System.currentTimeMillis() - startTime) / 1000 + " seconds.");
  outputMsg("Test data in : " + tempFile.getAbsolutePath());
  return tempFile.getAbsolutePath();
}

代码示例来源:origin: org.apache.solr/solr-solrj

@Override
 public Object doWork(Object first, Object second) throws IOException{
  if(null == first){
   throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the first value",toExpression(constructingFactory)));
  }
  if(null == second){
   throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the second value",toExpression(constructingFactory)));
  }

  Number size = (Number)first;
  Number exp = (Number)second;

  return new ZipfDistribution(size.intValue(), exp.doubleValue());
 }
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com