@Test public void testRandomSampling() { logger.info("randomSampling"); FlatDataList idList = new FlatDataList(Arrays.asList(new Object[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16})); int n = 6; boolean randomizeRecords = false; double expResult = n; FlatDataCollection sampledIds = SystematicSampling.randomSampling(idList, n, randomizeRecords); double result = sampledIds.size(); assertTrue(result>=expResult); }
public static FlatDataCollection randomSampling(FlatDataList idList, int n, boolean randomizeRecords) { FlatDataList sampledIds = new FlatDataList(); int populationN = idList.size(); Object[] keys = idList.toArray(); if(randomizeRecords) { PHPMethods.<Object>shuffle(keys); } int k = populationN/n; if(k<2) { throw new IllegalArgumentException("The number of systematics is too small."); } int randomSystematic = PHPMethods.mt_rand(0,k-1); for(int i=randomSystematic;i<keys.length;i+=k) { Object pointID = keys[i]; sampledIds.add(pointID); } return sampledIds.toFlatDataCollection(); }
SystematicSampling { public static FlatDataCollection randomSampling(FlatDataList idList, int n, boolean randomizeRecords) { FlatDataList sampledIds = new FlatDataList(); int populationN = idList.size(); Object[] keys = idList.toArray(); if(randomizeRecords) { PHPMethods.<Object>shuffle(keys); } int k = populationN/n; if(k<2) { throw new IllegalArgumentException("The number of systematics is too small."); } int randomSystematic = PHPMethods.mt_rand(0,k-1); for(int i=randomSystematic;i<keys.length;i+=k) { Object pointID = keys[i]; sampledIds.add(pointID); } return sampledIds.toFlatDataCollection(); } }
SystematicSampling { public static FlatDataCollection randomSampling(FlatDataList idList, int n, boolean randomizeRecords) { FlatDataList sampledIds = new FlatDataList(); int populationN = idList.size(); Object[] keys = idList.toArray(); if(randomizeRecords) { PHPMethods.<Object>shuffle(keys); } int k = populationN/n; if(k<2) { throw new IllegalArgumentException("The number of systematics is too small."); } int randomSystematic = PHPMethods.mt_rand(0,k-1); for(int i=randomSystematic;i<keys.length;i+=k) { Object pointID = keys[i]; sampledIds.add(pointID); } return sampledIds.toFlatDataCollection(); }  }
SystematicSampling { public static FlatDataCollection randomSampling(FlatDataList idList, int n, boolean randomizeRecords) { FlatDataList sampledIds = new FlatDataList(); int populationN = idList.size(); Object[] keys = idList.toArray(); if(randomizeRecords) { PHPMethods.<Object>shuffle(keys); } int k = populationN/n; if(k<2) { throw new IllegalArgumentException("The number of systematics is too small."); } int randomSystematic = PHPMethods.mt_rand(0,k-1); for(int i=randomSystematic;i<keys.length;i+=k) { Object pointID = keys[i]; sampledIds.add(pointID); } return sampledIds.toFlatDataCollection(); }  static FlatDataCollection randomSampling(FlatDataList idList, int n, boolean randomizeRecords); static double mean(FlatDataCollection flatDataCollection); static double xbarVariance(FlatDataCollection flatDataCollection); static double xbarStd(FlatDataCollection flatDataCollection); }
SystematicSampling { public static FlatDataCollection randomSampling(FlatDataList idList, int n, boolean randomizeRecords) { FlatDataList sampledIds = new FlatDataList(); int populationN = idList.size(); Object[] keys = idList.toArray(); if(randomizeRecords) { PHPMethods.<Object>shuffle(keys); } int k = populationN/n; if(k<2) { throw new IllegalArgumentException("The number of systematics is too small."); } int randomSystematic = PHPMethods.mt_rand(0,k-1); for(int i=randomSystematic;i<keys.length;i+=k) { Object pointID = keys[i]; sampledIds.add(pointID); } return sampledIds.toFlatDataCollection(); }  static FlatDataCollection randomSampling(FlatDataList idList, int n, boolean randomizeRecords); static double mean(FlatDataCollection flatDataCollection); static double xbarVariance(FlatDataCollection flatDataCollection); static double xbarStd(FlatDataCollection flatDataCollection);  }