changes
authorbdemsky <bdemsky>
Fri, 16 Oct 2009 03:15:08 +0000 (03:15 +0000)
committerbdemsky <bdemsky>
Fri, 16 Oct 2009 03:15:08 +0000 (03:15 +0000)
Robust/src/Benchmarks/SingleTM/KMeans/Cluster.java
Robust/src/Benchmarks/SingleTM/KMeans/KMeans.java

index 8b36949a9fb8ab968a404ed9d87e47c240553238..e35be98720f4d37c12fde3b5007c4ca6e875ae4a 100644 (file)
@@ -88,9 +88,7 @@ public class Cluster {
     {
       float[] moments = new float[num_moments];
 
-      //float mzero=0.0f;
       for (int i = 0; i < num_elts; i++) {
-        //mzero += data[i];
         moments[0] += data[i];
       }
 
@@ -98,7 +96,7 @@ public class Cluster {
       for (int j = 1; j < num_moments; j++) {
         moments[j] = 0;
         for (int i = 0; i < num_elts; i++) {
-          moments[j] += (float) Math.pow((data[i]-moments[0]), j+1);
+          moments[j] = (float)(moments[j]+ Math.pow((data[i]-moments[0]), j+1));
         }
         moments[j] = moments[j] / num_elts;
       }
@@ -126,9 +124,7 @@ public class Cluster {
         for (int j = 0; j < numObjects; j++) {
           data[j][i] = (data[j][i]-moments[0])/moments[1];
         }
-        moments=null;
       }
-      single_variable=null;
     }
 
 
@@ -142,8 +138,8 @@ public class Cluster {
         int      numObjects,             /* number of input objects */
         int      numAttributes,          /* size of attribute of each object */
         float[][]  attributes,           /* [numObjects][numAttributes] */
-        KMeans kms,                      /* KMeans class hold the inputs and outputs */
-        GlobalArgs args                  /* Global thread arguments */
+        KMeans kms,                       /* KMeans class hold the inputs and outputs */
+        GlobalArgs args                 /* Global thread arguments */
         )
     {
       int itime;
@@ -163,12 +159,10 @@ public class Cluster {
 
       /*
        * From min_nclusters to max_nclusters, find best_nclusters
-       */ 
-      System.out.println("min_nclusters= " + kms.min_nclusters + " max_nclusters= " + kms.max_nclusters);
+       */
       for (nclusters = kms.min_nclusters; nclusters <= kms.max_nclusters; nclusters++) {
 
         randomPtr.random_seed(7);
-        args.nclusters = nclusters;
 
         Normal norm = new Normal();
 
@@ -182,10 +176,9 @@ public class Cluster {
             randomPtr,
             args);
 
-        {
-          kms.cluster_centres = tmp_cluster_centres;
-          kms.best_nclusters = nclusters;
-        }
+       kms.cluster_centres = tmp_cluster_centres;
+       kms.best_nclusters = nclusters;
+
 
         itime++;
       } /* nclusters */
index 7144b19884dbe44f06f26eb1bf5443aa23009d21..741ba26127cd0f0c2d6ca7c01ff9f3b477c2d70a 100644 (file)
@@ -234,7 +234,7 @@ public class KMeans extends Thread {
      * The core of the clustering
      */
 
-    //int[] cluster_assign = new int[numObjects];
+    int[] cluster_assign = new int[numObjects];
     int nloops = 1;
     int len = kms.max_nclusters - kms.min_nclusters + 1;
 
@@ -317,9 +317,7 @@ public class KMeans extends Thread {
           km.isBinaryFile = new Integer(args[i++]).intValue();
         }
       } else if(arg.equals("-z")) {
-        if(i < args.length) {
-
-        }
+       km.use_zscore_transform=0;
       } else if(arg.equals("-nthreads")) {
         if(i < args.length) {
           km.nthreads = new Integer(args[i++]).intValue();
@@ -361,38 +359,60 @@ public class KMeans extends Thread {
     byte oldbytes[]=null;
 
 
+    j = -1;
     while ((n = inputFile.read(b)) != 0) {
-      j = -1;
       int x=0;
 
       if (oldbytes!=null) {
        //find space
+       boolean cr=false;
        for (;x < n; x++) {
          if (b[x] == ' ')
            break;
+         if (b[x] == '\n') {
+           cr=true;
+           break;
+         }
        }
        byte newbytes[]=new byte[x+oldbytes.length];
-       for(int ii=0;ii<oldbytes.length;ii++)
+       boolean isnumber=false;
+       for(int ii=0;ii<oldbytes.length;ii++) {
+         if (oldbytes[ii]>='0'&&oldbytes[ii]<='9')
+           isnumber=true;
          newbytes[ii]=oldbytes[ii];
-       for(int ii=0;ii<x;ii++)
+       }
+       for(int ii=0;ii<x;ii++) {
+         if (b[ii]>='0'&&b[ii]<='9')
+           isnumber=true;
          newbytes[ii+oldbytes.length]=b[ii];
-       x++; //skip past space
-       if (j>=0) {
-         buf[i][j]=(float)Double.parseDouble(new String(newbytes, 0, newbytes.length));
        }
-       j++;
+       if (x!=n)
+         x++; //skip past space or cr
+       if (isnumber) {
+         if (j>=0) {
+           buf[i][j]=(float)Double.parseDouble(new String(newbytes, 0, newbytes.length));
+         }
+         j++;
+       }
+       if (cr) {
+         j=-1;
+         i++;
+       }
        oldbytes=null;
       }
 
       while (x < n) {
        int y=x;
+       boolean cr=false;
+       boolean isnumber=false;
        for(y=x;y<n;y++) {
+         if ((b[y]>='0')&&(b[y]<='9'))
+           isnumber=true;
          if (b[y]==' ')
            break;
          if (b[y]=='\n') {
-           i++;
-           j = -1;
-           x=y;//push end to current character
+           cr=true;
+           break;
          }
        }
        if (y==n) {
@@ -404,13 +424,21 @@ public class KMeans extends Thread {
        }
        
        //otherwise x is beginning of character string, y is end
-       if (j>=0) {
-
-         buf[i][j]=(float)Double.parseDouble(new String(b,x,y-x));
+       if (isnumber) {
+         if (j>=0) {
+           buf[i][j]=(float)Double.parseDouble(new String(b,x,y-x));
+         }
+         j++;
+       }
+       if (cr) {
+         i++;//skip to next line
+         j = -1;//don't store line number
+         x=y;//skip to end of number
+         x++;//skip past return
+       } else {
+         x=y;//skip to end of number
+         x++;//skip past space
        }
-       x=y;//skip to end of number
-       x++;//skip past space
-       j++;
       }
     }
     inputFile.close();