### Question:
GridSearch { static List<List<?>> chooseHyperParameterCombos(List<HyperParamValues<?>> ranges, int howMany) { Preconditions.checkArgument(howMany > 0 && howMany <= MAX_COMBOS); int numParams = ranges.size(); int perParam = chooseValuesPerHyperParam(ranges, howMany); if (numParams == 0 || perParam == 0) { return Collections.singletonList(Collections.emptyList()); } int howManyCombos = 1; List<List<?>> paramRanges = new ArrayList<>(numParams); for (HyperParamValues<?> range : ranges) { List<?> values = range.getTrialValues(perParam); paramRanges.add(values); howManyCombos *= values.size(); } List<List<?>> allCombinations = new ArrayList<>(howManyCombos); for (int combo = 0; combo < howManyCombos; combo++) { List<Object> combination = new ArrayList<>(numParams); for (int param = 0; param < numParams; param++) { int whichValueToTry = combo; for (int i = 0; i < param; i++) { whichValueToTry /= paramRanges.get(i).size(); } whichValueToTry %= paramRanges.get(param).size(); combination.add(paramRanges.get(param).get(whichValueToTry)); } allCombinations.add(combination); } if (howMany >= howManyCombos) { Collections.shuffle(allCombinations); return allCombinations; } RandomDataGenerator rdg = new RandomDataGenerator(RandomManager.getRandom()); int[] indices = rdg.nextPermutation(howManyCombos, howMany); List<List<?>> result = new ArrayList<>(indices.length); for (int i = 0; i < indices.length; i++) { result.add(allCombinations.get(i)); } Collections.shuffle(result); return result; } private  GridSearch();   }### Answer:
@Test public void testCombos() { List<HyperParamValues<?>> hyperParams = new ArrayList<>(); hyperParams.add(HyperParams.fixed(1.0)); hyperParams.add(HyperParams.range(2, 10)); hyperParams.add(HyperParams.around(5.0, 0.5)); List<List<?>> combos = GridSearch.chooseHyperParameterCombos(hyperParams, 4); assertEquals(4, combos.size()); assertContains(combos, Arrays.<Number>asList(1.0, 2, 4.75)); assertContains(combos, Arrays.<Number>asList(1.0, 10, 4.75)); assertContains(combos, Arrays.<Number>asList(1.0, 2, 5.25)); assertContains(combos, Arrays.<Number>asList(1.0, 10, 5.25)); }
@Test public void testCombos2() { List<HyperParamValues<?>> hyperParams = new ArrayList<>(); hyperParams.add(HyperParams.fixed(1.0)); hyperParams.add(HyperParams.range(2, 10)); hyperParams.add(HyperParams.around(5.0, 0.5)); List<List<?>> combos = GridSearch.chooseHyperParameterCombos(hyperParams, 2); assertEquals(2, combos.size()); assertContains(combos, Arrays.<Number>asList(1.0, 10, 4.75)); assertContains(combos, Arrays.<Number>asList(1.0, 2, 4.75)); }
@Test public void testNoCombos() { List<List<?>> combos = GridSearch.chooseHyperParameterCombos(Collections.emptyList(), 1); assertEquals(1, combos.size()); assertEquals(0, combos.get(0).size()); }