Пример #1
0
 @Override
 public void prepareClusters() {
   for (DemoPoint dp : points) {
     int c = (int) (k * Math.random());
     // System.out.println(dp);
     dp.setCluster(c);
   }
   updateStep();
 }
Пример #2
0
 /**
  * Unlike the prepareData in KMeansDemo, this method ignores and overwrites the "size" parameter.
  * It scans a file and changes them to the appropriate values for the contents of the file
  */
 @Override
 public void prepareData() {
   if (infile == null) {
     infile = DEFAULT_IN;
   }
   DemoPoint.setDimension(this.d);
   try {
     Scanner in = new Scanner(new File(infile)).useDelimiter("\n");
     LinkedList<String> l = new LinkedList<String>();
     int count = 0;
     while (in.hasNext() && count < size) {
       l.add(in.next());
       ++count;
     }
     this.size = count;
     this.points = new DemoPoint[size];
     this.clusters = new DemoPoint[k];
     int pointsp = 0;
     // parse the big list into data points
     for (String inS : l) {
       String[] split = inS.split(",");
       double[] data = new double[d];
       for (int i = 0; i < d; ++i) {
         Double din = new Double(split[i]);
         data[i] = din;
       }
       points[pointsp++] = new DemoPoint(data);
     }
   } catch (IOException e) {
     throw new RuntimeException(e); // gotta make it out somehow
   }
 }