Example #1
0
 @Override
 protected void toJavaUnifyPreds(SB bodySb) {
   if (isClassifier()) {
     bodySb.i().p("float sum = 0;").nl();
     bodySb.i().p("for(int i=1; i<preds.length; i++) sum += preds[i];").nl();
     bodySb.i().p("if (sum>0) for(int i=1; i<preds.length; i++) preds[i] /= sum;").nl();
   } else bodySb.i().p("preds[1] = preds[1]/NTREES;").nl();
 }
Example #2
0
 @Override
 protected void toJavaUnifyPreds(SB bodyCtxSB) {
   if (isClassifier()) {
     bodyCtxSB
         .i()
         .p(
             "// Compute Probabilities for classifier (scale via http://www.hongliangjie.com/2011/01/07/logsum/)")
         .nl();
     bodyCtxSB.i().p("float dsum = 0, maxval = Float.NEGATIVE_INFINITY;").nl();
     if (nclasses() == 2) {
       bodyCtxSB.i().p("preds[2] = -preds[1];").nl();
     }
     bodyCtxSB
         .i()
         .p("for(int i=1; i<preds.length; i++) maxval = Math.max(maxval, preds[i]);")
         .nl();
     bodyCtxSB
         .i()
         .p(
             "for(int i=1; i<preds.length; i++) dsum += (preds[i]=(float) Math.exp(preds[i] - maxval));")
         .nl();
     bodyCtxSB.i().p("for(int i=1; i<preds.length; i++) preds[i] = preds[i] / dsum;").nl();
   }
 }