/** * 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(); }
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(); }
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)));
public ZipfianStringKeyGenerator(boolean preLoadKeys, int numKeys, double exponent) { super(numKeys, preLoadKeys); this.zipf = new ZipfDistribution(numKeys, exponent); }
public ZipfianStringKeyGenerator(boolean preLoadKeys, int numKeys, double exponent) { super(numKeys, preLoadKeys); this.zipf = new ZipfDistribution(numKeys, exponent); }
@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()); } }
/** * 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(); }
/** * 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(); }
/** * @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; }
if (testOpts.zipfian) { zipfian = true; zipf = new ZipfDistribution(testOpts.zipfsize, 0.99);
"The multiplier of the Zipf distribution should be >= 0, but found %s.", multiplier); final ZipfDistribution dist = new ZipfDistribution(100, param); return scaledSampler(fromIntegerDistribution(dist), multiplier);
@Before public void setUp() { testSourceOptions.splitPointFrequencyRecords = 1; testSourceOptions.numRecords = 10; testSourceOptions.keySizeBytes = 10; testSourceOptions.valueSizeBytes = 20; testSourceOptions.numHotKeys = 3; testSourceOptions.hotKeyFraction = 0.3; testSourceOptions.setSeed(123456); testSourceOptions.bundleSizeDistribution = fromIntegerDistribution(new ZipfDistribution(100, 2.5)); testSourceOptions.forceNumInitialBundles = null; }
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()));
dist = new ZipfDistribution(n, p);
@Override public IntegerDistribution deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { JsonNode node = p.getCodec().readTree(p); String simpleName = node.get("distribution").asText(); switch (simpleName) { case "BinomialDistribution": return new BinomialDistribution(node.get("trials").asInt(), node.get("p").asDouble()); case "GeometricDistribution": return new GeometricDistribution(node.get("p").asDouble()); case "HypergeometricDistribution": return new HypergeometricDistribution(node.get("populationSize").asInt(), node.get("numberOfSuccesses").asInt(), node.get("sampleSize").asInt()); case "PascalDistribution": return new PascalDistribution(node.get("r").asInt(), node.get("p").asDouble()); case "PoissonDistribution": return new PoissonDistribution(node.get("p").asDouble()); case "UniformIntegerDistribution": return new UniformIntegerDistribution(node.get("lower").asInt(), node.get("upper").asInt()); case "ZipfDistribution": return new ZipfDistribution(node.get("numElements").asInt(), node.get("exponent").asDouble()); default: throw new RuntimeException("Unknown or not supported distribution: " + simpleName); } } }
@Override public IntegerDistribution deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { JsonNode node = p.getCodec().readTree(p); String simpleName = node.get("distribution").asText(); switch (simpleName) { case "BinomialDistribution": return new BinomialDistribution(node.get("trials").asInt(), node.get("p").asDouble()); case "GeometricDistribution": return new GeometricDistribution(node.get("p").asDouble()); case "HypergeometricDistribution": return new HypergeometricDistribution(node.get("populationSize").asInt(), node.get("numberOfSuccesses").asInt(), node.get("sampleSize").asInt()); case "PascalDistribution": return new PascalDistribution(node.get("r").asInt(), node.get("p").asDouble()); case "PoissonDistribution": return new PoissonDistribution(node.get("p").asDouble()); case "UniformIntegerDistribution": return new UniformIntegerDistribution(node.get("lower").asInt(), node.get("upper").asInt()); case "ZipfDistribution": return new ZipfDistribution(node.get("numElements").asInt(), node.get("exponent").asDouble()); default: throw new RuntimeException("Unknown or not supported distribution: " + simpleName); } } }