void AzTimeLog::print(const char *msg, const AzOut &out) 
{
  if (out.isNull()) return; 
  _printTime(out); 
  AzPrint::writeln(out, msg); 
  out.flush(); 
}
Ejemplo n.º 2
0
 inline AzPrint(const AzOut &out) : o(NULL), dlm(NULL), name_dlm(NULL), 
                                    count(0), useDlm(true), level(0) {
   if (!out.isNull()) {
     o = out.o; 
   }
   level = out.getLevel(); 
 }
Ejemplo n.º 3
0
 inline void reset(const AzOut &out) {
   o = NULL; 
   if (!out.isNull()) {
     o = out.o; 
   }
   level = out.getLevel(); 
   dlm = NULL; 
   count = 0; 
 }
Ejemplo n.º 4
0
  /*-------------------*/
  void begin(const char *compo, const char *name, const char *desc=NULL) 
  {
    if (out.getLevel() == 0) return; 

    if (out.isNull()) return; 

    AzBytArr s(desc); 
    if (s.length() > 0) {
      s.c(" ("); s.c(name); s.c(")"); 
      AzPrint o(out); 
      o.printBegin("", " ", NULL, ind); 
      o.print("<"); o.print(s); o.print(">"); 
      o.printEnd(); 
    }
  }
Ejemplo n.º 5
0
/*--------------------------------------------------------*/
void AzOptOnTree::printParam(const AzOut &out, 
                             bool beVerbose) const 
{
  if (out.isNull()) return; 

  AzPrint o(out); 
  o.reset_options(); 
  o.set_precision(5); 
  o.ppBegin("AzOptOnTree", "Optimization"); 
  o.printV("loss=", AzLoss::lossName(loss_type)); 
  o.printV(kw_max_ite_num, max_ite_num); 
  o.printV(kw_lambda, lambda); 
  o.printV_posiOnly(kw_sigma, sigma); 
  o.printV(kw_eta, eta); 
  o.printV(kw_exit_delta, exit_delta); 
  o.printV(kw_max_delta, max_delta); 

  o.printSw(kw_doUseAvg, doUseAvg); 
  o.printSw(kw_doIntercept, doIntercept); 

  o.printSw(kw_opt_beVerbose, beVerbose); 

  /*---  these are fixed; displaying for maintenance purpose only  ---*/
  o.printSw("doRefershP", doRefreshP); 
  o.printSw("doUnregIntercept", doUnregIntercept);  /* unregularized intercept */

  o.ppEnd(); 
}
Ejemplo n.º 6
0
 void printParam(const AzOut &out, const char *pfx) const {
   if (out.isNull()) return; 
   AzPrint o(out, pfx); 
   o.printV(kw_rho, rho); 
   o.printV(kw_eps, eps); 
   o.printEnd(); 
 } 
Ejemplo n.º 7
0
/*------------------------------------------------------------------*/
void AzTrTreeFeat::dump(const AzOut &out, const char *header) const
{
  if (out.isNull()) return; 
 
  AzPrint o(out); 
  o.printBegin(header); 
  o.printSw("doAllowZeroWeightLeaf", doAllowZeroWeightLeaf); 
  o.printSw("doCountRules", doCountRules); 
  o.printSw("doCheckConsistency", doCheckConsistency); 
  o.printEnd(); 
  ip_featDef.dump(dmp_out, "ip_featDef"); 
  
  int f_num = featNum(); 
  int fx; 
  for (fx = 0; fx < f_num; ++fx) {
    const AzTrTreeFeatInfo *fp = f_inf.point(fx); 
    
    o.printBegin("", ", ", "="); 
    o.inBrackets(fx); 
    o.print("isRemoved", fp->isRemoved); 
    o.print("tx", fp->tx); 
    o.print("nx", fp->nx); 
    o.print("rule length", fp->rule.length()); 
    o.printEnd(); 
  }
}
Ejemplo n.º 8
0
 void writeln(const char *txt, int ind_len) {
   if (out.isNull()) return; 
   AzBytArr s(txt); 
   _multi_lines(&s, ind_len);  
   AzBytArr s_ind; s_ind.fill(' ', ind_len); 
   AzPrint::writeln(out, s_ind, s); 
 }
Ejemplo n.º 9
0
/*------------------------------------------------------------------*/
void AzIntPool::dump(const AzOut &out, const char *header) const
{
  if (out.isNull()) return; 

  AzPrint o(out); 
  if (header != NULL) {
    o.writeln(header); 
  }

  int num = size(); 
  int ix; 
  for (ix = 0; ix < num; ++ix) {
    o.printBegin("", ", "); 
    /* fprintf(out.fp, "[%5ld],%4ld,", ix, getCount(ix)); */
    o.inBrackets(ix,5); o.print(getCount(ix),4); 

    int ints_num; 
    const int *ints = point(ix, &ints_num); 
    AzBytArr s("("); 
    int jx; 
    for (jx = 0; jx < ints_num; ++jx) {
      if (jx > 0) {
        s.c(","); 
      }
      s.cn(ints[jx]); 
    }
    s.c(")"); 
    o.print(s); 
    o.printEnd(); 
  }
}
Ejemplo n.º 10
0
 virtual void printParam(const AzOut &out) const {
   if (out.isNull()) return; 
   AzPrint o(out); 
   if (s_dataproc.length() > 0) {
     o.ppBegin("AzDataForTrTree", "Data processing"); 
     o.printV(kw_dataproc, s_dataproc); 
     o.ppEnd(); 
   }
 }
/*-------------------------------------------------------------*/
void AzBytArr::print(const AzByte *inp_bytes, int inp_bytes_len, const AzOut &out) 
{
  if (out.isNull()) return; 
  int ix; 
  for (ix = 0; ix < inp_bytes_len; ++ix) {
    *out.o << inp_bytes[ix]; 
    /* fprintf(out.fp, "%c", inp_bytes[ix]); */
  }
}
Ejemplo n.º 12
0
 virtual void printParam_data(const AzOut &out) const {
   if (out.isNull()) return; 
   AzPrint o(out); 
   o.printV(kw_channels, channels); 
   o.printV(kw_sz1, sz1); 
   o.printV(kw_sz2, sz2);     
   o.printV(kw_data_scale, data_scale); 
   o.printEnd(); 
 }    
/*-------------------------------------------------------------*/
void AzTimeLog::_printTime(const AzOut &out)
{
  if (out.isNull()) return; 
  time_t ltime; 
  time(&ltime); 
  AzBytArr str_time(ctime(&ltime)); 
  str_time.strip(); /* remove new line in the end */
  str_time.c(": "); 
  AzPrint::write(out, str_time); 
}
Ejemplo n.º 14
0
/*--------------------------------------------------------*/
void AzTree::show(const AzSvFeatInfo *feat, const AzOut &out,
                  const char *header) const
{
  if (out.isNull()) return;
  AzPrint::writeln(out, header);
  if (nodes == NULL) {
	  AzPrint::writeln(out, "AzTree::show, No tree\n");
    return;
  }
  _show(feat, root_nx, 0, out);
}
Ejemplo n.º 15
0
/*------------------------------------------------------------------*/
void AzTaskTools::dumpWeights(const AzOut &out, 
                        const AzDvect *v_w,
                        const char *name, 
                        const AzSvFeatInfo *feat, 
                        int print_max, 
                        bool changeLine) 
{
  if (out.isNull()) return; 

  AzPrint o(out); 
  o.write(name); 
  o.writeln("  -----"); 

  AzIFarr ifa_ex_weight; 
  v_w->nonZero(&ifa_ex_weight); 

  int num = ifa_ex_weight.size(); 
  ifa_ex_weight.sort_Float(false); /* descending order */

  /*-----  print largest weights  -----*/
  int ix; 
  for (ix = 0; ix < num; ++ix) {
    if (ix >= print_max) break;

    int ex; 
    double val = ifa_ex_weight.get(ix, &ex); 
    AzBytArr str_weight; 
    formatWeight(feat, ex, val, &str_weight); 
    o.write(str_weight); 
    if (changeLine) {
      o.newLine(); 
    }
  }
  o.newLine(); o.newLine(); 

  if (num > print_max) {
    /*-----  print smallest weights  -----*/
    for (ix = num - 1; ix >= 0; --ix) {
      if (num - ix > print_max) break;

      int ex; 
      double val = ifa_ex_weight.get(ix, &ex); 
      AzBytArr str_weight; 
      formatWeight(feat, ex, val, &str_weight); 
      o.write(str_weight); 
      if (changeLine) {
        o.newLine(); 
      }
    }
    o.newLine(); o.newLine(); 
  }
  o.flush(); 
}
/*------------------------------------------------------------------*/
void AzIntArr::print(const AzOut &out, const char *header) const 
{
  if (out.isNull()) return; 
  AzPrint o(out); 
  o.printBegin(header, ""); 
  o.print("("); 
  int ix; 
  for (ix = 0; ix < num; ++ix) {
    o.print(ints[ix]); 
    if (ix == 0) o.resetDlm(","); 
  }
  o.printEnd(")"); 
}
Ejemplo n.º 17
0
/*------------------------------------------------------------------*/
void AzTrTreeFeat::printParam(const AzOut &out) const
{
  if (out.isNull()) return; 

  if (!doCountRules && !doCheckConsistency) {
    return; 
  }

  AzPrint o(out); 
  o.ppBegin("AzTrTreeFeat", "Feature management", ", "); 
  o.printSw(kw_doCountRules, doCountRules); 
  o.printSw(kw_doCheckConsistency, doCheckConsistency); 
  o.ppEnd(); 
}
Ejemplo n.º 18
0
/*--------------------------------------------------------*/
void AzRgfTree::printParam(const AzOut &out) const
{
  if (out.isNull()) return; 

  AzPrint o(out); 
  o.reset_options(); 
  o.ppBegin("AzRgfTree", "Tree-level", ", "); 
  o.printV(kw_max_depth, max_depth); 
  o.printV(kw_min_size, min_size); 
  o.printV(kw_max_leaf_num, max_leaf_num); 
  o.printSw(kw_doUseInternalNodes, doUseInternalNodes); 
  o.printSw(kw_tree_beVerbose, beVerbose); 
  o.ppEnd(); 
}
Ejemplo n.º 19
0
/*-------------------------------------------------------------*/
void AzDmat::dump(const AzOut &out, const char *header, 
                  int max_col, 
                  const AzStrArray *sp_row, 
                  const AzStrArray *sp_col, 
                  int cut_num) const
{
  if (out.isNull()) return; 
  AzPrint o(out); 

  const char *my_header = ""; 
  if (header != NULL) my_header = header; 
  o.writeln(my_header); 

  /* (row,col)=(r,c)\n */
  int c_num = col_num; 
  if (max_col > 0 && max_col < col_num) {
    c_num = max_col; 
  }
  o.printBegin("", ""); 
  o.print("(row,col)="); 
  o.pair_inParen(row_num, col_num, ","); 
  if (c_num < col_num) {
    AzBytArr s(" Showing first "); s.cn(c_num); s.c(" columns only"); 
    o.print(s); 
  }
  o.printEnd(); 

  int cx; 
  for (cx = 0; cx < c_num; ++cx) {
    if (column[cx] == NULL) {
      continue; 
    }

    /* column=cx (col_header) */
    o.printBegin("", " ", "="); 
    o.print("column", cx); 
    if (sp_col != NULL) {
      o.inParen(sp_col->c_str(cx)); 
    }
    o.printEnd();

    column[cx]->dump(out, "", sp_row, cut_num); 
  }
  o.writeln(""); /* blank line */
  o.flush(); 
}
Ejemplo n.º 20
0
/*--------------------------------------------------------*/
void AzsSvrg::printParam(const AzOut &out) const 
{
  if (out.isNull()) return; 

  AzPrint o(out); 
  o.reset_options(); 
  o.set_precision(5); 
  o.ppBegin("", ""); 
  o.printV(kw_loss, lossName(loss_type)); 
  o.printV(kw_svrg_interval, svrg_interval); 
  o.printV(kw_sgd_ite, sgd_ite);
  o.printV(kw_test_interval, test_interval);  

  o.printV(kw_ite_num, ite_num); 
  o.printV(kw_rseed, rseed); 
  o.printV(kw_eta, eta); 
  o.printV(kw_momentum, momentum); 
  o.printV(kw_lam, lam);     
  o.printSw(kw_do_compact, do_compact); 
  o.printSw(kw_do_show_loss, do_show_loss); 
  o.printSw(kw_do_show_timing, do_show_timing); 
  o.printSw(kw_with_replacement, with_replacement); 
  o.printV_if_not_empty(kw_pred_fn, s_pred_fn); 
  
  o.ppEnd(); 

  /*---  check parameters  ---*/  
  throw_if_nonpositive(kw_ite_num, (double)ite_num); 
  throw_if_nonpositive(kw_eta, eta); 
  throw_if_negative(kw_lam, lam); 
  throw_if_nonpositive(kw_svrg_interval, svrg_interval); 
  throw_if_negative(kw_sgd_ite, sgd_ite); 
  if (test_interval > 0) {
    if (test_interval % svrg_interval != 0) {
      AzBytArr s(kw_test_interval); s.c(" must be a multiple of "); s.c(kw_svrg_interval); 
      throw new AzException(AzInputError, "AzsSvrg::resetParam", s.c_str()); 
    }
  }
  if (!doing_classif() && loss_type != AzsLoss_Square) {
    throw new AzException(AzInputError, "AzsSvrg::resetParam", "Only square loss is supported for regression tasks."); 
  }
  if (loss_type == AzsLoss_None) {
    AzBytArr s(kw_loss); s.c(" must be specified.  "); allLoss_str(s); 
    throw new AzException(AzInputError, "AzsSvrg::resetParam", s.c_str()); 
  }
}
Ejemplo n.º 21
0
/*--------------------------------------------------------*/
void AzOptOnTree::dumpWeights(const AzOut &out,                        
                        int print_max, 
                        bool changeLine) const 
{
  if (out.isNull()) return; 
  int nz = v_w.nonZeroRowNum(); 

  AzPrint o(out); 
  o.printBegin("", ",", "="); 
  o.print("#non_zero_weight", nz); 
  o.print("var_const", var_const, 5); 
  o.print("fixed_const", fixed_const, 5); 
  o.printEnd(); 
  o.writeln(""); 
  const char *name = "OUT"; 
  AzTaskTools::dumpWeights(out, &v_w, name, tree_feat, print_max, changeLine); 
}
Ejemplo n.º 22
0
/*------------------------------------------------------------------*/
void AzTaskTools::showDist(const AzStrArray *sp_cat, 
                           const AzIntArr *ia_cat, 
                           const char *header, 
                           const AzOut &out)
{
  if (out.isNull()) return; 
  AzPrint o(out); 
  o.printBegin(header, ", ", ":"); 
  int cx; 
  for (cx = 0; cx < sp_cat->size(); ++cx) {
    int pop = ia_cat->count(cx); 
    o.print(sp_cat->c_str(cx), pop, 5); 
    double ratio = (double)pop/(double)ia_cat->size(); 
    o.inParen(ratio, 3); 
  }
  o.printEnd(); 
}
Ejemplo n.º 23
0
/*--------------------------------------------------------*/
void AzOptOnTree::monitorLoss(int ite, 
                                  double delta, 
                                  const AzOut &out) const 
{
  if (out.isNull()) return; 

  const double *y = v_y.point(); 
  const double *fixed_dw = NULL; 
  double nn = v_y.rowNum(); 
  if (!AzDvect::isNull(&v_fixed_dw)) {
    fixed_dw = v_fixed_dw.point(); 
    nn = v_fixed_dw.sum(); 
  }
  int data_num = v_p.rowNum(); 
  const double *p = v_p.point(); 
  double uloss_sum=0; 
  int t=0,g=0,ok=0; 
  int dx; 
  for (dx = 0; dx < data_num; ++dx) {
    if (p[dx] > 0) ++t; 
    if (y[dx] > 0) ++g; 
    if (y[dx] > 0 && p[dx] > 0) ++ok; 
    double uloss = AzLoss::getLoss(loss_type, p[dx], y[dx]); 
    if (fixed_dw != NULL) uloss *= fixed_dw[dx]; 
    uloss_sum += uloss; 
  }

  double uloss_avg = uloss_sum / nn; 
  double n1 = v_w.absSum(); 
  double n2 = v_w.selfInnerProduct(); 

  /* ite 1,delta,uloss=..,n1,n2,pr,p,r\n */
  AzPrint o(out); 
  o.printBegin("", ",", "="); 
  o.print("ite", ite+1, 2); 
  bool doSci = true; 
  o.print(delta, 4, doSci); 
  o.print("uloss", uloss_avg, 4, doSci); 
  o.print(n1, 3, doSci); o.print(n2, 3, doSci); 
  if (g > 0 && g < data_num) {
    AzTaskTools::printPR(o, ok, t, g); 
  }
  o.printEnd(); 
  o.flush(); 
}
Ejemplo n.º 24
0
/*-------------------------------------------------------------*/
void AzDvect::dump(const AzOut &out, const char *header, 
                   const AzStrArray *sp_row, 
                   int cut_num) const
{
  if (out.isNull()) return; 

  AzPrint o(out); 
  const char *my_header = ""; 
  if (header != NULL) my_header = header; 

  o.writeln(my_header); 

  int nz_num = nonZeroRowNum(); 
  int indent = 3; 
  o.printBegin(my_header, ",", "=", indent); 
  o.print("#row", num); 
  o.print("#non-zero", nz_num); 
  o.printEnd();

  if (cut_num > 0) {
    _dump(out, sp_row, cut_num); 
    return; 
  }

  int ex; 
  for (ex = 0; ex < num; ++ex) {
    if (elm[ex] == 0) {
      continue;  
    }

    /* [row] val (header) */
    o.printBegin("", " ", "=", indent); 
    o.inBrackets(ex, 4); 
    
//    o.print(elm[ex], 5, true); 
    o.print(elm[ex], 20, true); 
    
    if (sp_row != NULL) {
      const char *row_header = sp_row->c_str(ex); 
      o.inParen(row_header); 
    }
    o.printEnd(); 
  }
  o.flush();  
}
Ejemplo n.º 25
0
  void show(const AzSvFeatInfo *feat, //!< may be NULL 
            const AzOut &out, const char *header="") const {
    if (out.isNull()) return; 
    AzPrint o(out); 
    o.printBegin(header, ", ", "="); 
    o.print("constant", const_val); 
    o.print("orgdim", org_dim); 
    o.print("#tree", t_num); 
    o.printEnd(); 

    for (int tx = 0; tx < t_num; ++tx) {
      AzBytArr s("tree"); s.inBrackets(tx); 
      AzPrint::writeln(out, s); 
      if (t[tx] != NULL) {
        t[tx]->show(feat, out); 
      }
    }
  }
Ejemplo n.º 26
0
  /*-------------------*/
  void toplevel_header(const char *desc, AzByte dlm='*') 
  {
    if (out.isNull()) return; 

    newline(); 

    AzBytArr s; 
    s.fill(dlm, 3); 
    int dlm_len = Az64::cstrlen(desc) + s.length()*2; 
    dlm_len = MIN(line_width, dlm_len); 

    AzBytArr s_long; 
    s_long.fill(dlm, dlm_len); 

    AzPrint::writeln(out, s_long.c_str()); 
    AzPrint::write(out, s.c_str()); 
    AzPrint::write(out, desc); 
    AzPrint::writeln(out, s.c_str()); 
    AzPrint::writeln(out, s_long.c_str()); 
  }
Ejemplo n.º 27
0
/*-------------------------------------------------------------*/
void AzDmat::dump(const AzOut &out, const char *header, 
                     const AzStrArray *sp_row, 
                     const AzStrArray *sp_col, 
                     int cut_num) const
{
  if (out.isNull()) return; 

  AzPrint o(out); 

  const char *my_header = ""; 
  if (header != NULL) my_header = header; 
  o.writeln(my_header); 

  /* (row,col)=(r,c)\n */
  o.printBegin("", ""); 
  o.print("(row,col)="); 
  o.pair_inParen(row_num, col_num, ","); 
  o.printEnd(); 

  int cx; 
  for (cx = 0; cx < col_num; ++cx) {
    if (column[cx] == NULL) {
      continue; 
    }

    /* column=cx (col_header) */
    o.printBegin("", " ", "="); 
    o.print("column", cx); 
    if (sp_col != NULL) {
      o.inParen(sp_col->c_str(cx)); 
    }
    o.printEnd();

    column[cx]->dump(out, "", sp_row, cut_num); 
  }
  o.flush(); 
}
Ejemplo n.º 28
0
  /*-------------------*/
  void _item(bool isRequired, 
             const char *kw, const char *desc, 
             const AzBytArr &s_dflt, 
             bool no_quotes=false)
  {
    if (out.isNull()) return; 
    int indent = ind; 
    if (isRequired) indent-=2; 
    AzPrint o(out); 
    o.printBegin("", " ", "", indent); 
    if (isRequired) o.print("*"); 

    AzBytArr s_kw; 
    if (no_quotes) s_kw.concat(kw); 
    else           s_kw.inQuotes(kw, "\""); 
    int len = kw_width - s_kw.length(); 
    if (len > 0) {
      AzBytArr s_fill; 
      s_fill.fill(' ', len); 
      s_kw.concat(&s_fill); 
    }
    AzBytArr s_desc(desc); 
    s_desc.concat(&s_dflt);    
    _multi_lines(&s_desc, ind+kw_width+1);  

    o.print(s_kw); 
    if (len >= 0) {
      o.print(s_desc); 
    }
    else {
      o.printEnd(); 
      o.printBegin("", "", "", ind+kw_width+1); 
      o.print(s_desc); 
    }
    o.printEnd();   
  }
Ejemplo n.º 29
0
/*--------------------------------------------------------*/
void AzTree::_show(const AzSvFeatInfo *feat,
                    int nx,
                    int depth,
                    const AzOut &out) const
{
  if (out.isNull()) return;

  const AzTreeNode *np = &nodes[nx];

  AzPrint o(out);
  o.printBegin("", ", ", "=", depth*2);
  /* [nx], (weight), depth=d, desc,border */
  o.inBrackets(nx,3);
  if (np->weight != 0) {
    o.inParen(np->weight,3);
  }
  o.printV("depth=", depth);
  if (np->fx >= 0) {
    AzBytArr s_desc;
    if (feat != NULL) {
      feat->concatDesc(np->fx, &s_desc);
    }
    else {
      s_desc.c("F");
      s_desc.cn(np->fx);
    }
    o.print(&s_desc);
    o.print(np->border_val,4,false);
  }
  o.printEnd();

  if (!np->isLeaf()) {
    _show(feat, np->le_nx, depth+1, out);
    _show(feat, np->gt_nx, depth+1, out);
  }
}
Ejemplo n.º 30
0
 static inline void writeln(const AzOut &out, const T inp) {
   if (out.isNull()) return; 
   *out.o<<inp<<endl; 
 }