src/kmeans.cpp
// Seed each cluster with the average of 10 randomly selected points
// I saw a lot of empty clusters after seeding this way.  Switching to
// Seed1() method.
Seed each cluster with the average of 10 randomly selected points
I saw a lot of empty clusters after seeding this way.  Switching to
Seed1() method.
Seed each cluster with the average of 10 randomly selected points I saw a lot of empty clusters after seeding this way . Switching to Seed1 () method .
void KMeans::Seed2(void) {
  double *sums = new double[dim_];
  int num_sample = 10;
  for (int c = 0; c < num_clusters_; ++c) {
    for (int f = 0; f < dim_; ++f) sums[f] = 0;
    for (int i = 0; i < num_sample; ++i) {
      int o = RandBetween(0, num_objects_ - 1);
      for (int f = 0; f < dim_; ++f) {
	sums[f] += objects_[o][f];
      }
    }
    for (int f = 0; f < dim_; ++f) {
      means_[c][f] = sums[f] / num_sample;
    }
  }
  delete [] sums;
}
void KMeans :: Seed2 ( void ) { double * sums = new double [ dim_ ] ; int num_sample = 10 ; for ( int c = 0 ; c < num_clusters_ ; ++ c ) { for ( int f = 0 ; f < dim_ ; ++ f ) sums [ f ] = 0 ; for ( int i = 0 ; i < num_sample ; ++ i ) { int o = RandBetween ( 0 , num_objects_ - 1 ) ; for ( int f = 0 ; f < dim_ ; ++ f ) { sums [ f ] += objects_ [ o ] [ f ] ; } } for ( int f = 0 ; f < dim_ ; ++ f ) { means_ [ c ] [ f ] = sums [ f ] / num_sample ; } } delete [ ] sums ; }
Seed each cluster with the average of 10 randomly selected points
I saw a lot of empty clusters after seeding this way.
Seed each cluster with the average of 10 randomly selected points I saw a lot of empty clusters after seeding this way .