@Test public void testRandomSampling() { logger.info("randomSampling"); FlatDataList idList = new FlatDataList(); idList.add("a"); idList.add("0"); idList.add("c"); idList.add("1"); idList.add("5"); int n = 100; boolean withReplacement = true; double expResult = n; FlatDataCollection sampledIds = SimpleRandomSampling.randomSampling(idList, n, withReplacement); double result = sampledIds.size(); assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH); }
public static FlatDataCollection randomSampling(FlatDataList idList, int n, boolean withReplacement) { FlatDataList sampledIds = new FlatDataList(); int populationN = idList.size(); for(int i=0;i<n;) { if(withReplacement==false && populationN<=n) { break; } int randomPosition = PHPMethods.mt_rand(0, populationN-1); Object pointID = idList.get(randomPosition); if(withReplacement==false && sampledIds.contains(pointID)) { continue; } sampledIds.add(pointID); ++i; } return sampledIds.toFlatDataCollection(); }
SimpleRandomSampling { public static FlatDataCollection randomSampling(FlatDataList idList, int n, boolean withReplacement) { FlatDataList sampledIds = new FlatDataList(); int populationN = idList.size(); for(int i=0;i<n;) { if(withReplacement==false && populationN<=n) { break; } int randomPosition = PHPMethods.mt_rand(0, populationN-1); Object pointID = idList.get(randomPosition); if(withReplacement==false && sampledIds.contains(pointID)) { continue; } sampledIds.add(pointID); ++i; } return sampledIds.toFlatDataCollection(); } }
SimpleRandomSampling { public static FlatDataCollection randomSampling(FlatDataList idList, int n, boolean withReplacement) { FlatDataList sampledIds = new FlatDataList(); int populationN = idList.size(); for(int i=0;i<n;) { if(withReplacement==false && populationN<=n) { break; } int randomPosition = PHPMethods.mt_rand(0, populationN-1); Object pointID = idList.get(randomPosition); if(withReplacement==false && sampledIds.contains(pointID)) { continue; } sampledIds.add(pointID); ++i; } return sampledIds.toFlatDataCollection(); }  }
SimpleRandomSampling { public static FlatDataCollection randomSampling(FlatDataList idList, int n, boolean withReplacement) { FlatDataList sampledIds = new FlatDataList(); int populationN = idList.size(); for(int i=0;i<n;) { if(withReplacement==false && populationN<=n) { break; } int randomPosition = PHPMethods.mt_rand(0, populationN-1); Object pointID = idList.get(randomPosition); if(withReplacement==false && sampledIds.contains(pointID)) { continue; } sampledIds.add(pointID); ++i; } return sampledIds.toFlatDataCollection(); }  static FlatDataCollection weightedSampling(AssociativeArray weightedTable, int n, boolean withReplacement); static FlatDataCollection randomSampling(FlatDataList idList, int n, boolean withReplacement); static double mean(FlatDataCollection flatDataCollection); static double variance(FlatDataCollection flatDataCollection); static double std(FlatDataCollection flatDataCollection); static double xbarVariance(double variance, int sampleN); static double xbarVariance(double variance, int sampleN, int populationN); static double xbarStd(double std, int sampleN); static double xbarStd(double std, int sampleN, int populationN); static double pbarVariance(double pbar, int sampleN); static double pbarVariance(double pbar, int sampleN, int populationN); static double pbarStd(double pbar, int sampleN); static double pbarStd(double pbar, int sampleN, int populationN); static int minimumSampleSizeForMaximumXbarStd(double maximumXbarStd, double populationStd); static int minimumSampleSizeForMaximumXbarStd(double maximumXbarStd, double populationStd, int populationN); static int minimumSampleSizeForGivenDandMaximumRisk(double d, double aLevel, double populationStd); static int minimumSampleSizeForGivenDandMaximumRisk(double d, double aLevel, double populationStd, int populationN); }
SimpleRandomSampling { public static FlatDataCollection randomSampling(FlatDataList idList, int n, boolean withReplacement) { FlatDataList sampledIds = new FlatDataList(); int populationN = idList.size(); for(int i=0;i<n;) { if(withReplacement==false && populationN<=n) { break; } int randomPosition = PHPMethods.mt_rand(0, populationN-1); Object pointID = idList.get(randomPosition); if(withReplacement==false && sampledIds.contains(pointID)) { continue; } sampledIds.add(pointID); ++i; } return sampledIds.toFlatDataCollection(); }  static FlatDataCollection weightedSampling(AssociativeArray weightedTable, int n, boolean withReplacement); static FlatDataCollection randomSampling(FlatDataList idList, int n, boolean withReplacement); static double mean(FlatDataCollection flatDataCollection); static double variance(FlatDataCollection flatDataCollection); static double std(FlatDataCollection flatDataCollection); static double xbarVariance(double variance, int sampleN); static double xbarVariance(double variance, int sampleN, int populationN); static double xbarStd(double std, int sampleN); static double xbarStd(double std, int sampleN, int populationN); static double pbarVariance(double pbar, int sampleN); static double pbarVariance(double pbar, int sampleN, int populationN); static double pbarStd(double pbar, int sampleN); static double pbarStd(double pbar, int sampleN, int populationN); static int minimumSampleSizeForMaximumXbarStd(double maximumXbarStd, double populationStd); static int minimumSampleSizeForMaximumXbarStd(double maximumXbarStd, double populationStd, int populationN); static int minimumSampleSizeForGivenDandMaximumRisk(double d, double aLevel, double populationStd); static int minimumSampleSizeForGivenDandMaximumRisk(double d, double aLevel, double populationStd, int populationN);  }