Java Code Examples for org.apache.commons.math3.distribution.ZipfDistribution#sample()
The following examples show how to use
org.apache.commons.math3.distribution.ZipfDistribution#sample() .
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: TopNCounterTest.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
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(); }
Example 2
Source File: ContentService.java From EdgeSim with MIT License | 5 votes |
/** * Initialize the popularity according to power law distribution */ public static List<SingleLocalHobby> initialPopularity(List<SingleLocalHobby> noPopularityMediaList){ ZipfDistribution zd = new ZipfDistribution(Parameter.ZIPF_SAMPLE, Parameter.ZIPF_CONEFFICIENT); int [] popularity = zd.sample(noPopularityMediaList.size()); for(int i = 0 ; i<noPopularityMediaList.size();i++){ noPopularityMediaList.get(i).getSingleContent().setPopularity(popularity[i]); } return sortByInitialPopularity(noPopularityMediaList); }
Example 3
Source File: TopNCounterTest.java From kylin with Apache License 2.0 | 5 votes |
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(); }