Esempio n. 1
0
 void reset(T *tree, 
            int data_num, 
            const AzBytArr *inp_s_temp_prefix) {
   reset(); 
   if (inp_s_temp_prefix == NULL || inp_s_temp_prefix->length() <= 0) {
     return; 
   }
   s_temp_prefix.reset(inp_s_temp_prefix); 
   unit_size = tree->estimateSizeofDataIndexes(data_num); 
   if (unit_size <= 0) {
     return; 
   }
   if (unit_size > max_size) {
     throw new AzException(AzInputError, "AzTemp_forTrTreeEns::reset", 
                           "Data size is too large."); 
   }
   open_new_file(); 
 }
Esempio n. 2
0
 virtual void show_stat(AzBytArr &s) const {
   if (p.typ == AzpActivDflt_None) return;     
   if (!p.do_stat) return; 
   AzDvect my_v_pop(&v_pop_last); 
   my_v_pop.normalize1(); 
   s.nl(); 
   double accum = 0; 
   int ix; 
   for (ix = 0; ix < my_v_pop.rowNum(); ++ix) {
     accum += my_v_pop.get(ix); 
     s.c("b"); s.cn(v_border.get(ix)); s.c("="); s.cn(my_v_pop.get(ix),3); s.c("("); s.cn(accum,3); s.c("),"); 
   }
 }
Esempio n. 3
0
/*--------------------------------------------------------*/
void AzTreeEnsemble::show_weights(const AzOut &out, AzSvFeatInfo *fi) const
{
  AzIIFarr iifa_tx_nx_posiw, iifa_tx_nx_negaw; 
  int tx; 
  for (tx = 0; tx < t_num; ++tx) {
    int nx; 
    for (nx = 0; nx < t[tx]->nodeNum(); ++nx) {
      const AzTreeNode *np = t[tx]->node(nx); 
      if (np->weight > 0) {
        iifa_tx_nx_posiw.put(tx, nx, np->weight); 
      }
      else if (np->weight < 0) {
        iifa_tx_nx_negaw.put(tx, nx, np->weight); 
      }
    }
  }
  iifa_tx_nx_posiw.sort_Float(false); /* descending order */
  iifa_tx_nx_negaw.sort_Float(true); /* ascending order */

  AzPrint::writeln(out, "Positive weights -------------------"); 
  int ix; 
  for (ix = 0; ix < iifa_tx_nx_posiw.size(); ++ix) {
    int tx, nx; 
    double w = iifa_tx_nx_posiw.get(ix, &tx, &nx); 
    AzBytArr s_desc; 
    t[tx]->genDesc(fi, nx, &s_desc); 
    AzBytArr s; s.cn(w, 6, false); s.c(' '); s.c(&s_desc); 
    AzPrint::writeln(out, s); 
  }

  AzPrint::writeln(out, "Negative weights -------------------"); 
  for (ix = 0; ix < iifa_tx_nx_negaw.size(); ++ix) {
    int tx, nx; 
    double w = iifa_tx_nx_negaw.get(ix, &tx, &nx); 
    AzBytArr s_desc; 
    t[tx]->genDesc(fi, nx, &s_desc); 
    AzBytArr s; s.cn(w, 6, false); s.c(' '); s.c(&s_desc); 
    AzPrint::writeln(out, s); 
  }
}
Esempio n. 4
0
 inline void reset(const AzTreeRule *inp) {
   ba.reset(); 
   if (inp == NULL) return; 
   ba.reset(&inp->ba); 
 }
Esempio n. 5
0
 inline void print_space(int len) {
   AzBytArr s; s.fill(' ', len); 
   print(s); 
 }
Esempio n. 6
0
 static inline void writeln(const AzOut &out, const AzBytArr &s) {
   writeln(out, s.c_str()); 
 }
Esempio n. 7
0
 inline void writeln(const AzBytArr &s) {
   if (o == NULL) return; 
   *o<<s.c_str()<<endl; 
 }
Esempio n. 8
0
 inline void inParen(const AzBytArr &s) {
   if (o == NULL) return; 
   inParen(s.c_str()); 
 }
Esempio n. 9
0
 inline void inBrackets(int val, int width=-1, bool doFillZero=false) {
   if (o == NULL) return; 
   itemBegin(); 
   AzBytArr s; inBrackets(&s, val, width, doFillZero); 
   *o<<s.c_str(); 
 }
Esempio n. 10
0
 inline void printV_if_not_empty(const char *kw, const AzBytArr &s) {
   if (o == NULL) return; 
   if (s.length() <= 0) return; 
   itemBegin(); 
   *o<<kw<<s.c_str(); 
 }
Esempio n. 11
0
 void reset() {
   unit_size = -1; 
   s_temp_prefix.reset();
   pool_file.reset(); 
 }
Esempio n. 12
0
 inline const char *param_c_str() const {
   return s_param.c_str(); 
 }
Esempio n. 13
0
 void throw_if_empty(const char *kw, const AzBytArr &s) const {
   if (s.length() <= 0) throw new AzException(AzInputError, "AzsLinear::resetParam", kw, "must be specified."); 
 }  
Esempio n. 14
0
 inline void finalize() {
   if (ba.getLen() == 0) {
     ba.concat('_'); /* root node (CONST) */
   }
 }
Esempio n. 15
0
 inline void append(const AzTreeRule *inp) {
   if (inp != NULL) {
     ba.concat(&inp->ba); 
   }
 }
Esempio n. 16
0
 inline static void print(int number, const char *msg, const AzOut &out) {
   AzBytArr s; s.cn(number); 
   print(s.c_str(), msg, out); 
 }
Esempio n. 17
0
 inline void printV(const char *kw, const AzBytArr &s) {
   if (o == NULL) return; 
   itemBegin(); 
   *o<<kw<<s.c_str(); 
 }
Esempio n. 18
0
 void setup_no_activation() {
   s_activ_typ.reset("None"); 
   typ = 'N'; 
   trunc = -1; 
 }
Esempio n. 19
0
 /*-------------------*/
 inline void print(const AzBytArr &s) {
   if (o == NULL) return; 
   print(s.c_str()); 
 }
Esempio n. 20
0
 virtual void write(AzFile *file) {
   AzTools::write_header(file, version, reserved_len);    
   s_activ_typ.write(file); 
   file->writeByte(typ); 
   file->writeDouble(trunc); 
 }
Esempio n. 21
0
 inline void inBrackets(double val, int prec=-1, bool doSci=false) {
   if (o == NULL) return; 
   itemBegin(); 
   AzBytArr s; inBrackets(&s, val, prec, doSci); 
   *o<<s.c_str(); 
 }
Esempio n. 22
0
 virtual void read(AzFile *file) {
   AzTools::read_header(file, reserved_len);
   s_activ_typ.read(file); 
   typ = file->readByte(); 
   trunc = file->readDouble(); 
 }
Esempio n. 23
0
 inline void inBrackets(const AzBytArr &s) {
   if (o == NULL) return; 
   inBrackets(s.c_str()); 
 }
Esempio n. 24
0
/*-------------------------------------------------------------------------*/
int AzTools_text::replace_utf8dashes(AzByte *data, int len) /* inout */
{
  const char *eyec = "AzTools_text:;replace_utf8dashes"; 
  AzBytArr s_mydata;
  AzByte *mydata = s_mydata.reset(len*2, 0); 
  AzByte *mywp = mydata;  
  /* 0xe28093: en dash (often used as in 1900-1935) */
  /* 0xe28094: em dash (long dash) */ 
  /* 0xe2809c: double quote begin -> [ " ]  */
  /* 0xe2809d: duoble quote end   -> [ " ]  */
  /* 0xe28098: single quote begin -> [ ' ]*/
  /* 0xe28099: single quote end -> [ 's] if ending a token; [ ' ] otherwise */
  const AzByte *data_end = data+len, *wp = data; 
  for ( ; wp < data_end; ) {
    const AzByte *ptr = (AzByte *)memchr(wp,  0xE2, data_end-wp); 
    if (ptr == NULL) {
      ptr = data_end; 
    }
    int mvlen = Az64::ptr_diff(ptr-wp, eyec); 
    if (mvlen > 0) {
      memcpy(mywp, wp, mvlen);  mywp += mvlen; /* string before 0xE2 */
    }
    if (ptr+3 <= data_end) {
      AzByte prevch = (ptr-1 >= data) ? *(ptr-1) : 0; 
      AzByte nextch = (ptr+3 < data_end) ? *(ptr+3) : 0; 
      AzBytArr s; 
      if (*(ptr+1) == 0x80) {
        if (*(ptr+2) == 0x93) { /* en dash */
          if (prevch>='0' && prevch<='9' && nextch>='0' && nextch<='9') s.c("-");  /* between digits */
          else                                                          s.c(" - "); 
        }
        else if (*(ptr+2) == 0x94)                          s.c(" - "); /* em dash */
        else if (*(ptr+2) == 0x98)                          s.c(" ' "); 
        else if (*(ptr+2) == 0x9c || *(ptr+2) == 0x9d)      s.c(" \" "); /* double quote */        
        else if (*(ptr+2) == 0x99) {
          if (ptr+5<=data_end && memcmp(ptr+3, "s ", 2)==0) s.c(" '");    
          else                                              s.c(" ' "); 
        }
        else s.c(ptr, 3); 
      }
      else s.c(ptr, 3); 
      memcpy(mywp, s.point(), s.length());  mywp += s.length(); 
      wp = ptr+3;     
    }
    else {
      mvlen = Az64::ptr_diff(data_end-ptr, eyec);
      if (mvlen > 0) {
        memcpy(mywp, ptr, mvlen); mywp += mvlen; 
      }
      wp = data_end; 
    }
  }
  int mydata_len = Az64::ptr_diff(mywp-mydata); 
  memcpy(data, mydata, mydata_len); 
  mydata[mydata_len] = '\0'; 
  return mydata_len; 
}
Esempio n. 25
0
 inline void write(const AzBytArr &s) {
   if (o == NULL) return; 
   *o<<s.c_str(); 
 }
Esempio n. 26
0
 inline void close() {
   ofs.close(); 
   if (ofs.fail()) {
     throw new AzException(AzFileIOError, "AzOfs::close", "Failed to close:", s_fn.c_str()); 
   }
 }
Esempio n. 27
0
 static inline void force_writeln(const AzBytArr &s) {
   force_writeln(s.c_str()); 
 }
Esempio n. 28
0
 inline static void print(const AzBytArr &s, const AzOut &out) {
   print(s.c_str(), out); 
 }
Esempio n. 29
0
 inline virtual void show(const char *header, const AzOut &out) const {
   AzBytArr s; 
   s.c(header); 
   format(s); 
   AzPrint::writeln(out, s); 
 }
Esempio n. 30
0
 inline void reset() {
   ba.clear(); 
 }