Example #1
0
int compare_DataNode(const void* A,const void* B)
{
   DataNode *x = (DataNode *)A;
   DataNode *y = (DataNode *)B;
   if (x->missing && y->missing) {
       return 0;
   }
   else if (x->missing && !y->missing) {
       return 1;
   }
   else if (!x->missing && y->missing) {
      return -1;
   }
   else {
      if (x->double_val() < y->double_val()) {
         return -1;
      }
      else if (x->double_val() == y->double_val()) {
         return 0;
      }
      else {
         return 1;
      }
   }
}
Example #2
0
DataNode Field::covariance(const Field *B) const
{
   if (B) throw exception("Field::covariance(B): not yet implemented");
   DataNode retval;
   retval.missing = 1;

   if (col_struct.type() != 'S') {
      unsigned i,k;
      for (k=0,i=0; i<ne; i++) if (!dat_vec[i].missing) k++;
      if (k >= 2) {
         Vector<double> tmp(k);
         for (k=0,i=0; i<ne; i++) {
            if (!dat_vec[i].missing) tmp[k++] = dat_vec[i].double_val();
         }
         retval.double_val(tmp.variance());
         retval.missing = 0;
      }
   }
   return retval;
}
Example #3
0
DataNode Field::product(void) const
{
   DataNode retval;
   retval.missing = 1;
   if (col_struct.type() != 'S') {
      unsigned i,k=0;
      double x;
      for (x=1.0,k=0,i=0; i<ne; i++) {
         if (!dat_vec[i].missing) {
            k++;
            x *= dat_vec[i].double_val();
         }
      }
      if (k) {
         retval.missing = 0;
         retval.double_val(x);
      }
   }
   return retval;
}
Example #4
0
DataNode Field::sumsq(void) const
{
   DataNode retval;
   retval.missing = 1;
   if (col_struct.type() !='S') {
      unsigned i,k;
      double y,x;
      for (x=0.0, k=0,i=0; i<ne; i++) {
         if (!dat_vec[i].missing) {
            k++;
            y = dat_vec[i].double_val();
            x += y*y;
         }
      }
      if (k) {
         retval.missing = 0;
         retval.double_val(x);
      }
   }
   return retval;
}
Example #5
0
DataNode Field::min(void) const
{
   DataNode retval;
   retval.missing = 1;

   if (col_struct.type() != 'S') {
      unsigned i, k=0;
      while (dat_vec[k].missing) k++;
      double y,mx = dat_vec[k].double_val();
      for (i=k; i<ne; i++) {
         if (!dat_vec[i].missing) {
            y = dat_vec[i].double_val();
            if ( y < mx) mx = y;
         }
      }
      if (k < ne) {
         retval.missing = 0;
         retval.double_val(mx);
      }
   }
   return retval;
}