org.apache.commons.math3.distribution.ParetoDistribution Java Examples
The following examples show how to use
org.apache.commons.math3.distribution.ParetoDistribution.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VMRequestRandomGenerator.java From cloudsimsdn with GNU General Public License v2.0 | 6 votes |
public void generateVMsRandom(int totalVmNum) { int vmCount = 0; double lastStartTime = 0; double startMean = 1800; // sec = 30min double durScale=14400; // sec = 4 hours double durShape=1.2; Random rVmNum = new Random(seed); ExponentialDistribution rStartTime = new ExponentialDistribution(new Well19937c(seed), startMean, ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY); ParetoDistribution rDuration = new ParetoDistribution(new Well19937c(seed), durScale, durShape); int vmGroup=0; while(vmCount < totalVmNum) { int vmsInGroup = rVmNum.nextInt(4)+2; double duration = Math.floor(rDuration.sample()); vmGenerator.generateVMGroup(vmsInGroup, lastStartTime, lastStartTime+duration, null, vmGroup, -1); lastStartTime += Math.floor(rStartTime.sample()); vmCount += vmsInGroup; vmGroup++; } }
Example #2
Source File: ItemTransactionGeneratorSource.java From flink-tutorials with Apache License 2.0 | 5 votes |
@Override public void run(SourceContext<ItemTransaction> ctx) throws Exception { ThreadLocalRandom rnd = ThreadLocalRandom.current(); ParetoDistribution paretoDistribution = new ParetoDistribution(numItems, shape); LOG.info("Starting transaction generator for {} items and {} sleep", numItems, sleep); while (isRunning) { long nextItemId; do { nextItemId = sample(paretoDistribution); } while (nextItemId > numItems); String itemId = "item_" + nextItemId; int quantity = (int) (Math.round(rnd.nextGaussian() / 2 * 10) * 10) + 5; if (quantity == 0) { continue; } long transactionId = rnd.nextLong(Long.MAX_VALUE); synchronized (ctx.getCheckpointLock()) { ctx.collect(new ItemTransaction(transactionId, System.currentTimeMillis(), itemId, quantity)); } if (sleep > 0) { Thread.sleep(sleep); } } }
Example #3
Source File: UserCurrencyAccountsGenerator.java From exchange-core with Apache License 2.0 | 5 votes |
/** * Generates random users and different currencies they should have, so the total account is between * accountsToCreate and accountsToCreate+currencies.size() * <p> * In average each user will have account for 4 symbols (between 1 and currencies,size) * * @param accountsToCreate * @param currencies * @return n + 1 uid records with allowed currencies */ public static List<BitSet> generateUsers(final int accountsToCreate, Collection<Integer> currencies) { log.debug("Generating users with {} accounts ({} currencies)...", accountsToCreate, currencies.size()); final ExecutionTime executionTime = new ExecutionTime(); final List<BitSet> result = new ArrayList<>(); result.add(new BitSet()); // uid=0 no accounts final Random rand = new Random(1); final RealDistribution paretoDistribution = new ParetoDistribution(new JDKRandomGenerator(0), 1, 1.5); final int[] currencyCodes = currencies.stream().mapToInt(i -> i).toArray(); int totalAccountsQuota = accountsToCreate; do { // TODO prefer some currencies more final int accountsToOpen = Math.min(Math.min(1 + (int) paretoDistribution.sample(), currencyCodes.length), totalAccountsQuota); final BitSet bitSet = new BitSet(); do { final int currencyCode = currencyCodes[rand.nextInt(currencyCodes.length)]; bitSet.set(currencyCode); } while (bitSet.cardinality() != accountsToOpen); totalAccountsQuota -= accountsToOpen; result.add(bitSet); // log.debug("{}", bitSet); } while (totalAccountsQuota > 0); log.debug("Generated {} users with {} accounts up to {} different currencies in {}", result.size(), accountsToCreate, currencies.size(), executionTime.getTimeFormatted()); return result; }
Example #4
Source File: TestOrdersGenerator.java From exchange-core with Apache License 2.0 | 5 votes |
public static double[] createWeightedDistribution(int size, int seed) { final RealDistribution paretoDistribution = new ParetoDistribution(new JDKRandomGenerator(seed), 0.001, 1.5); final double[] paretoRaw = DoubleStream.generate(paretoDistribution::sample).limit(size).toArray(); // normalize final double sum = Arrays.stream(paretoRaw).sum(); double[] doubles = Arrays.stream(paretoRaw).map(x -> x / sum).toArray(); // Arrays.stream(doubles).sorted().forEach(d -> log.debug("{}", d)); return doubles; }
Example #5
Source File: ItemTransactionGeneratorSource.java From flink-tutorials with Apache License 2.0 | 4 votes |
private long sample(ParetoDistribution paretoDistribution) { return (Math.round(paretoDistribution.sample() - paretoDistribution.getScale()) + 1); }