The call does not block.
+ * @return always returns this job. + */ public Job fork() { init(); H2OCountedCompleter task = new H2OCountedCompleter() { @@ -545,6 +566,9 @@ public void invoke() { /** * Invoked before job runs. This is the place to checks arguments are valid or throw * IllegalArgumentException. It will get invoked both from the Web and Java APIs. + * + * @throws IllegalArgumentException throws the exception if initialization fails to ensure + * correct job runtime environment. */ protected void init() throws IllegalArgumentException { if (destination_key == null) destination_key = defaultDestKey(); @@ -559,40 +583,6 @@ protected JobState exec() { throw new RuntimeException("Should be overridden if job is a request"); } - public static boolean isJobEnded(Key jobkey) { - boolean done = false; - - Job[] jobs = Job.all(); - boolean found = false; - for (int i = jobs.length - 1; i >= 0; i--) { - if (jobs[i].job_key == null) { - continue; - } - - if (! jobs[i].job_key.equals(jobkey)) { - continue; - } - - // This is the job we are looking for. - found = true; - - if (jobs[i].end_time > 0) { - done = true; - } - - if (jobs[i].isCancelled()) { - done = true; - } - - break; - } - - if (! found) { - done = true; - } - - return done; - } /** * Block synchronously waiting for a job to end, success or not. @@ -601,7 +591,7 @@ public static boolean isJobEnded(Key jobkey) { */ public static void waitUntilJobEnded(Key jobkey, int pollingIntervalMillis) { while (true) { - if (isJobEnded(jobkey)) { + if (Job.isEnded(jobkey)) { return; } diff --git a/src/main/java/water/Model.java b/src/main/java/water/Model.java index 695f9a8af0..9d1e29a30f 100644 --- a/src/main/java/water/Model.java +++ b/src/main/java/water/Model.java @@ -90,25 +90,60 @@ public int nclasses() { /** Variable importance of individual variables measured by this model. */ public VariableImportance varimp() { return null; } - /** Bulk score the frame 'fr', producing a Frame result; the 1st Vec is the + /** Bulk score for givenfr frame.
+ * The frame is always adapted to this model.
+ *
+ * @param fr frame to be scored
+ * @return frame holding predicted values
+ *
+ * @see #score(Frame, boolean)
+ */
+ public final Frame score(Frame fr) {
+ return score(fr, true);
+ }
+ /** Bulk score the frame fr
, producing a Frame result; the 1st Vec is the
* predicted class, the remaining Vecs are the probability distributions.
* For Regression (single-class) models, the 1st and only Vec is the
- * prediction value. Also passed in a flag describing how hard we try to
- * adapt the frame. */
- public Frame score( Frame fr) {
+ * prediction value.
+ *
+ * The flat adapt
+ * @param fr frame which should be scored
+ * @param adapt a flag enforcing an adaptation of fr
to this model. If flag
+ * is false
scoring code expect that fr
is already adapted.
+ * @return a new frame containing a predicted values. For classification it contains a column with
+ * prediction and distribution for all response classes. For regression it contains only
+ * one column with predicted values.
+ */
+ public final Frame score(Frame fr, boolean adapt) {
int ridx = fr.find(_names[_names.length-1]);
- if(ridx != -1){ // drop the response for scoring!
+ if (ridx != -1) { // drop the response for scoring!
fr = new Frame(fr);
fr.remove(ridx);
}
// Adapt the Frame layout - returns adapted frame and frame containing only
// newly created vectors
- Frame[] adaptFrms = adapt(fr,false);
+ Frame[] adaptFrms = adapt ? adapt(fr,false) : null;
// Adapted frame containing all columns - mix of original vectors from fr
// and newly created vectors serving as adaptors
- Frame adaptFrm = adaptFrms[0];
+ Frame adaptFrm = adapt ? adaptFrms[0] : fr;
// Contains only newly created vectors. The frame eases deletion of these vectors.
- Frame onlyAdaptFrm = adaptFrms[1];
+ Frame onlyAdaptFrm = adapt ? adaptFrms[1] : null;
+ // Invoke scoring
+ Frame output = scoreImpl(adaptFrm);
+ // Be nice to DKV and delete vectors which i created :-)
+ if (adapt) onlyAdaptFrm.delete();
+ return output;
+ }
+
+ /** Score already adapted frame.
+ *
+ * @param fr
+ * @return
+ */
+ private Frame scoreImpl(Frame adaptFrm) {
+ int ridx = adaptFrm.find(_names[_names.length-1]);
+ assert ridx == -1 : "Adapted frame should not contain response in scoring method!";
+ // Create a new vector for response
Vec v = adaptFrm.anyVec().makeZero();
// If the model produces a classification/enum, copy the domain into the
// result vector.
@@ -136,8 +171,6 @@ public Frame score( Frame fr) {
// Return just the output columns
int x=_names.length-1, y=adaptFrm.numCols();
Frame output = adaptFrm.extractFrame(x, y);
- // Delete manually only vectors which i created :-/
- onlyAdaptFrm.delete();
return output;
}
@@ -266,24 +299,24 @@ public static int[][] getDomainMapping(String[] modelDom, String[] colDom, boole
*
* @param colName name of column which is mapped, can be null.
* @param modelDom
- * @param exact
+ * @param logNonExactMapping
* @return
*/
- public static int[][] getDomainMapping(String colName, String[] modelDom, String[] colDom, boolean exact) {
+ public static int[][] getDomainMapping(String colName, String[] modelDom, String[] colDom, boolean logNonExactMapping) {
int emap[] = new int[modelDom.length];
boolean bmap[] = new boolean[modelDom.length];
HashMap md = new HashMap();
for( int i = 0; i < colDom.length; i++) md.put(colDom[i], i);
for( int i = 0; i < modelDom.length; i++) {
Integer I = md.get(modelDom[i]);
- if (I == null && exact)
+ if (I == null && logNonExactMapping)
Log.warn(Sys.SCORM, "Column "+colName+" was trained with factor '"+modelDom[i]+"' which DOES NOT appear in column data");
if (I!=null) {
emap[i] = I;
bmap[i] = true;
}
}
- if (exact) { // Inform about additional values in column domain which do not appear in model domain
+ if (logNonExactMapping) { // Inform about additional values in column domain which do not appear in model domain
for (int i=0; i