/** * Convert a collection of hyper-parameter search arrays into a double- dimension * array-of-doubles. Missing hyper parms will be filled in with the default value. * * @param hypers A set of {hyper-parameter field names, search space values} * @return The same set as a double[][] */ private double[][] hyper2doubles(Map<String, Object[]> hypers) { String[] ss = hyperNames(); double[] defs = hyperDefaults(); double[][] dss = new double[ss.length][]; int cnt = 0; // Count of found hyper parameters for (int i = 0; i < ss.length; i++) { // For all hyper-names Object[] os = hypers != null ? hypers.get(ss[i]) : null; // Get an array-of-something if (os == null) os = new Object[] {defs[i]}; // Missing? Use default else cnt++; // Found a hyper parameter double[] ds = dss[i] = new double[os.length]; // Array of params for search for (int j = 0; j < os.length; j++) ds[j] = ReflectionUtils.asDouble(os[j]); } if (hypers != null && cnt != hypers.size()) // Quicky error check for unknow parms for (String s : hypers.keySet()) if (ArrayUtils.find(ss, s) == -1) throw new IllegalArgumentException("Unkown hyper-parameter " + s); return dss; }
/** Factory method to create the model-specific parameters schema. */ public final P createParametersSchema() { // special case, because ModelBuilderSchema is the top of the tree and is parameterized // differently if (ModelBuilderSchema.class == this.getClass()) { return (P) new ModelParametersSchemaV3(); } try { Class<? extends ModelParametersSchemaV3> parameters_class = ReflectionUtils.findActualClassParameter(this.getClass(), 2); return (P) parameters_class.newInstance(); } catch (Exception e) { throw H2O.fail( "Caught exception trying to instantiate a builder instance for ModelBuilderSchema: " + this + ": " + e, e); } }