www.pudn.com > libpmk.rar > k-means-clusterer.h, change:2007-05-27,size:1493b

// Copyright 2007, Massachusetts Institute of Technology.
// The use of this code is permitted for research only. There is
// absolutely no warranty for this software.
// Author: John Lee (jjl@mit.edu)


#include <vector>
#include "clustering/clusterer.h"
#include "point_set/point-ref.h"
#include "util/distance-computer.h"

using namespace std;

namespace libpmk {
/// Implements K-Means clustering.
class KMeansClusterer : public Clusterer {
   KMeansClusterer(int num_clusters, int max_iters,
                   const DistanceComputer& distance_computer);

   /// Perform K-means.
    * Uses the DistanceComputer it was constructed with to fill up
    * cluster_centers_ with K Features representing the K-means
    * cluster centers. K is assigned by the constructor of
    * KMeansClusterer. If there are fewer data points than K,
    * then the total number of clusters returned is simply the
    * total number of data points (not K).
   virtual void DoClustering(const vector<PointRef>& data);

   int num_clusters_;
   int max_iterations_;
   const DistanceComputer& distance_computer_;

   void ComputeMembership(const vector<PointRef>& data);

   // Returns true if this call to ComputeMeans() has changed
   // cluster_centers_.
   bool ComputeMeans(const vector<PointRef>& data);
}  // namespace libpmk