00001 // Copyright 2007, Massachusetts Institute of Technology. 00002 // The use of this code is permitted for research only. There is 00003 // absolutely no warranty for this software. 00004 // 00005 // Author: John Lee (jjl@mit.edu) 00006 // 00007 00008 #ifndef CLUSTERING_CLUSTERER_H 00009 #define CLUSTERING_CLUSTERER_H 00010 00011 #include <vector> 00012 #include <iostream> 00013 #include "point_set/point-set.h" 00014 #include "point_set/point-ref.h" 00015 00016 using namespace std; 00017 00018 namespace libpmk { 00020 00030 class Clusterer { 00031 public: 00032 Clusterer(); 00033 virtual ~Clusterer() { } 00034 00036 00041 void Cluster(const vector<PointRef>& data); 00042 00044 00049 const PointSet& centers() const; 00050 00052 00056 int centers_size() const; 00057 00059 00064 int membership(int index) const; 00065 00068 int membership_size() const; 00069 00071 00091 void WriteToStream(ostream& output_stream) const; 00092 00094 void WriteToFile(const char* output_filename) const; 00095 00097 00103 void ReadFromStream(istream& input_stream); 00104 00106 void ReadFromFile(const char* input_filename); 00107 00108 protected: 00109 auto_ptr<PointSet> cluster_centers_; 00110 vector<int> membership_; 00111 bool done_; 00112 00114 00122 virtual void DoClustering(const vector<PointRef>& data) = 0; 00123 }; 00124 } // namespace libpmk 00125 00126 #endif // CLUSTERING_CLUSTERER_H