@Test public void testRandomSampling() { logger.info("randomSampling"); TransposeDataList strataIdList = new TransposeDataList(); strataIdList.put("strata1", new FlatDataList(Arrays.asList(new Object[]{"1","2","3","4"}))); strataIdList.put("strata2", new FlatDataList(Arrays.asList(new Object[]{"1","2","3","4","5","6","7"}))); AssociativeArray nh = generateNh(); boolean withReplacement = true; double expResult = Descriptives.sum(nh.toFlatDataCollection()); TransposeDataCollection sampledIds = StratifiedSampling.randomSampling(strataIdList, nh, withReplacement); double result = 0; for(Object stata : sampledIds.keySet()) { result+= sampledIds.get(stata).size(); } assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH); }
public static TransposeDataCollection randomSampling(TransposeDataList strataIdList, AssociativeArray nh, boolean withReplacement) { TransposeDataCollection sampledIds = new TransposeDataCollection(); for(Map.Entry<Object, FlatDataList> entry : strataIdList.entrySet()) { Object strata = entry.getKey(); Number sampleN = ((Number)nh.get(strata)); if(sampleN==null) { continue; } sampledIds.put(strata, SimpleRandomSampling.randomSampling(entry.getValue(), sampleN.intValue(), withReplacement)); } return sampledIds; }
StratifiedSampling { public static TransposeDataCollection randomSampling(TransposeDataList strataIdList, AssociativeArray nh, boolean withReplacement) { TransposeDataCollection sampledIds = new TransposeDataCollection(); for(Map.Entry<Object, FlatDataList> entry : strataIdList.entrySet()) { Object strata = entry.getKey(); Number sampleN = ((Number)nh.get(strata)); if(sampleN==null) { continue; } sampledIds.put(strata, SimpleRandomSampling.randomSampling(entry.getValue(), sampleN.intValue(), withReplacement)); } return sampledIds; } }
StratifiedSampling { public static TransposeDataCollection randomSampling(TransposeDataList strataIdList, AssociativeArray nh, boolean withReplacement) { TransposeDataCollection sampledIds = new TransposeDataCollection(); for(Map.Entry<Object, FlatDataList> entry : strataIdList.entrySet()) { Object strata = entry.getKey(); Number sampleN = ((Number)nh.get(strata)); if(sampleN==null) { continue; } sampledIds.put(strata, SimpleRandomSampling.randomSampling(entry.getValue(), sampleN.intValue(), withReplacement)); } return sampledIds; }  }
StratifiedSampling { public static TransposeDataCollection randomSampling(TransposeDataList strataIdList, AssociativeArray nh, boolean withReplacement) { TransposeDataCollection sampledIds = new TransposeDataCollection(); for(Map.Entry<Object, FlatDataList> entry : strataIdList.entrySet()) { Object strata = entry.getKey(); Number sampleN = ((Number)nh.get(strata)); if(sampleN==null) { continue; } sampledIds.put(strata, SimpleRandomSampling.randomSampling(entry.getValue(), sampleN.intValue(), withReplacement)); } return sampledIds; }  static TransposeDataCollection weightedProbabilitySampling(AssociativeArray2D strataFrequencyTable, AssociativeArray nh, boolean withReplacement); static TransposeDataCollection randomSampling(TransposeDataList strataIdList, AssociativeArray nh, boolean withReplacement); static double mean(TransposeDataCollection sampleDataCollection, AssociativeArray populationNh); static double variance(TransposeDataCollection sampleDataCollection, AssociativeArray populationNh); static double std(TransposeDataCollection sampleDataCollection, AssociativeArray populationNh); static double xbarVariance(TransposeDataCollection sampleDataCollection, AssociativeArray nh, AssociativeArray populationNh); static double xbarStd(TransposeDataCollection sampleDataCollection, AssociativeArray nh, AssociativeArray populationNh); static AssociativeArray optimumSampleSize(int n, AssociativeArray populationNh, AssociativeArray populationStdh); }
StratifiedSampling { public static TransposeDataCollection randomSampling(TransposeDataList strataIdList, AssociativeArray nh, boolean withReplacement) { TransposeDataCollection sampledIds = new TransposeDataCollection(); for(Map.Entry<Object, FlatDataList> entry : strataIdList.entrySet()) { Object strata = entry.getKey(); Number sampleN = ((Number)nh.get(strata)); if(sampleN==null) { continue; } sampledIds.put(strata, SimpleRandomSampling.randomSampling(entry.getValue(), sampleN.intValue(), withReplacement)); } return sampledIds; }  static TransposeDataCollection weightedProbabilitySampling(AssociativeArray2D strataFrequencyTable, AssociativeArray nh, boolean withReplacement); static TransposeDataCollection randomSampling(TransposeDataList strataIdList, AssociativeArray nh, boolean withReplacement); static double mean(TransposeDataCollection sampleDataCollection, AssociativeArray populationNh); static double variance(TransposeDataCollection sampleDataCollection, AssociativeArray populationNh); static double std(TransposeDataCollection sampleDataCollection, AssociativeArray populationNh); static double xbarVariance(TransposeDataCollection sampleDataCollection, AssociativeArray nh, AssociativeArray populationNh); static double xbarStd(TransposeDataCollection sampleDataCollection, AssociativeArray nh, AssociativeArray populationNh); static AssociativeArray optimumSampleSize(int n, AssociativeArray populationNh, AssociativeArray populationStdh);  }