Пример #1
0
 public GLMOutput(GLM glm) {
   super(glm);
   _dinfo = glm._dinfo;
   if (!glm.hasWeightCol()) {
     _dinfo = (DataInfo) _dinfo.clone();
     _dinfo._adaptedFrame =
         new Frame(_dinfo._adaptedFrame.names().clone(), _dinfo._adaptedFrame.vecs().clone());
     _dinfo.dropWeights();
   }
   _scoringDinfo = _dinfo.scoringInfo();
   String[] cnames = glm._dinfo.coefNames();
   String[] names = _dinfo._adaptedFrame._names;
   String[][] domains = _dinfo._adaptedFrame.domains();
   int id = glm._generatedWeights == null ? -1 : ArrayUtils.find(names, glm._generatedWeights);
   if (id >= 0) {
     String[] ns = new String[names.length - 1];
     String[][] ds = new String[domains.length - 1][];
     System.arraycopy(names, 0, ns, 0, id);
     System.arraycopy(domains, 0, ds, 0, id);
     System.arraycopy(names, id + 1, ns, id, ns.length - id);
     System.arraycopy(domains, id + 1, ds, id, ds.length - id);
     names = ns;
     domains = ds;
   }
   _names = names;
   _domains = domains;
   _coefficient_names = Arrays.copyOf(cnames, cnames.length + 1);
   _coefficient_names[_coefficient_names.length - 1] = "Intercept";
   _binomial = glm._parms._family == Family.binomial;
   _nclasses = glm.nclasses();
   _multinomial = _nclasses > 2;
 }
Пример #2
0
 /**
  * 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;
 }