Beispiel #1
0
void Node::iteration(bool last) {
  double bestGain = 0.0;
  Clustering bestClustering;
  bestClustering.copy(&clustering);
  Clustering backupClustering;
  backupClustering.copy(&clustering);
  buildValuesOverClusters();
  for(int i = 0; i < NUMBER_OF_RANDOM_RESTARTS; i++) {
    cout << "Random restart #" << i << endl;

    if(clusteringType() != FLAT)
      clustering.splitOrMerge(last);
		
    if(clustering.size() == 1) {
      cout << "Warning: there is only one cluster in " << name << endl;
      continue;
    }
    buildClustersOverClusters();

    double gain = calculateInformationGain();
    cout << "Initial value of objective function: " << gain << endl;
    for(int j = 0; j < NUMBER_OF_CONVERGENT_STEPS; j++) {
      cout << "Convergent step: " << j << endl;
      gain += clustering.correctionLoop();
    }
    if(gain > bestGain) {
      bestGain = gain;
      cout << "Best gain: " << gain << endl;
      bestClustering.copy(&clustering);
    }
    clustering.copy(&backupClustering);
  }
  clustering.copy(&bestClustering);
}