示例#1
0
oid_t Clusterer::GetClosestCluster(const Sample &sample) {
  double min_dist = std::numeric_limits<double>::max();
  oid_t closest_cluster = START_OID;
  oid_t cluster_itr = START_OID;

  // Go over all the means and find closest cluster
  for (auto mean : means_) {
    auto dist = sample.GetDistance(mean);
    if (dist < min_dist) {
      closest_cluster = cluster_itr;
      min_dist = dist;
    }
    cluster_itr++;
  }

  closest_[closest_cluster]++;
  sample_count_++;

  return closest_cluster;
}