Exemple #1
0
 static public String toString( float fs[] ) {
   SB sb = new SB();
   sb.p('[');
   for( float f : fs )
     sb.p(f==Float.MAX_VALUE ? "max": (f==-Float.MAX_VALUE ? "min": Float.toString(f))).p(',');
   return sb.p(']').toString();
 }
Exemple #2
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();
 }
    /**
     * @param flags Flags.
     * @return String builder containing all flags.
     */
    static String toString(short flags) {
      SB sb = new SB();

      for (Mask m : MASKS) {
        if (m.ordinal() != 0) sb.a('|');

        sb.a(m.name().toLowerCase()).a('=').a(m.bit(flags));
      }

      return sb.toString();
    }
Exemple #4
0
 public static SB getBase64(byte[] bytes) {
   long nBytes = bytes.length;
   SB sout = new SB();
   if (nBytes == 0) return sout;
   for (int i = 0, nPad = 0; i < nBytes && nPad == 0; ) {
     if (i % 75 == 0 && i != 0) sout.append("\r\n");
     nPad = (i + 2 == nBytes ? 1 : i + 1 == nBytes ? 2 : 0);
     int outbytes =
         ((bytes[i++] << 16) & 0xFF0000)
             | ((nPad == 2 ? 0 : bytes[i++] << 8) & 0x00FF00)
             | ((nPad >= 1 ? 0 : (int) bytes[i++]) & 0x0000FF);
     // System.out.println(Integer.toHexString(outbytes));
     sout.appendC(base64.charAt((outbytes >> 18) & 0x3F));
     sout.appendC(base64.charAt((outbytes >> 12) & 0x3F));
     sout.appendC(nPad == 2 ? '=' : base64.charAt((outbytes >> 6) & 0x3F));
     sout.appendC(nPad >= 1 ? '=' : base64.charAt(outbytes & 0x3F));
   }
   return sout;
 }
  /**
   * Builds ignite.sh attributes to set up SSH username and password and log directory for started
   * node.
   *
   * @param username SSH user name.
   * @param host Host.
   * @return {@code ignite.sh} script arguments.
   */
  private String buildRemoteLogArguments(String username, String host) {
    assert username != null;
    assert host != null;

    SB sb = new SB();

    sb.a(" -J-D")
        .a(IGNITE_SSH_HOST)
        .a("=\"")
        .a(host)
        .a("\"")
        .a(" -J-D")
        .a(IGNITE_SSH_USER_NAME)
        .a("=\"")
        .a(username)
        .a("\"");

    return sb.toString();
  }
  /**
   * Pretty-formatting for duration.
   *
   * @param ms Millisecond to format.
   * @return Formatted presentation.
   */
  private static String formatDuration(long ms) {
    assert ms >= 0;

    if (ms == 0) return "< 1 ms";

    SB sb = new SB();

    long dd = ms / 1440000; // 1440 mins = 60 mins * 24 hours

    if (dd > 0) sb.a(dd).a(dd == 1 ? " day " : " days ");

    ms %= 1440000;

    long hh = ms / 60000;

    if (hh > 0) sb.a(hh).a(hh == 1 ? " hour " : " hours ");

    long min = ms / 60000;

    if (min > 0) sb.a(min).a(min == 1 ? " min " : " mins ");

    ms %= 60000;

    if (ms > 0) sb.a(ms).a(" ms ");

    return sb.toString().trim();
  }
Exemple #7
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();
   }
 }