00001
00002
00003
00004
00005
00006
00007 #ifndef IMPSTATISTICS_KM_DATA_H
00008 #define IMPSTATISTICS_KM_DATA_H
00009
00010 #include <vector>
00011 #include <iomanip>
00012 #include <iostream>
00013 #include <string>
00014 #include "statistics_config.h"
00015
00016 IMPSTATISTICS_BEGIN_NAMESPACE
00017
00018 #ifndef IMP_DOXYGEN
00019
00020 typedef enum {
00021 UNIFORM,
00022 GAUSS,
00023 LAPLACE,
00024 CO_GAUSS,
00025 CO_LAPLACE,
00026 CLUS_GAUSS,
00027 CLUS_ORTH_FLATS,
00028 CLUS_ELLIPSOIDS,
00029 MULTI_CLUS,
00030 N_DISTRIBS}
00031 DistributionType;
00032
00033 typedef std::vector<double> KMPoint;
00034 typedef std::vector<KMPoint *> KMPointArray;
00035
00036
00037
00038
00039 class IMPSTATISTICSEXPORT KMData {
00040 public:
00041
00042
00043
00044
00045
00046 KMData(int d, int n);
00047
00048 int get_dim() const {
00049 return dim_;
00050 }
00051
00052 int get_number_of_points() const {
00053 return points_->size();
00054 }
00055
00056 KMPointArray* get_points() const {
00057 return points_;
00058 }
00059
00060
00061
00062
00063
00064 KMPoint* operator[](int i) {
00065 return (*points_)[i];
00066 }
00067
00068 const KMPoint* operator[](int i) const {
00069 return (*points_)[i];
00070 }
00071
00072
00073
00074
00075
00076
00077
00078
00079 KMPoint sample_center(double offset=0.);
00080
00081
00082
00083
00084
00085
00086 virtual void sample_centers( KMPointArray *sample,int k,
00087 double offset=0.,bool allow_duplicate=false);
00088
00089 void show(){}
00090 virtual ~KMData();
00091 protected:
00092 int dim_;
00093 KMPointArray *points_;
00094
00095 };
00096
00097
00098
00099
00100
00101 inline KMPointArray* allocate_points(int n,int dim) {
00102 KMPointArray *points = new KMPointArray();
00103 for(int i=0;i<n;i++){
00104 KMPoint *p=new KMPoint();
00105 p->insert(p->end(),dim,0.0);
00106 points->push_back(p);
00107 }
00108 return points;
00109 }
00110
00111
00112 inline void clear_points(KMPointArray *points) {
00113 if (points == NULL)
00114 return;
00115 for(unsigned int i=0;i<points->size();i++){
00116 delete (*points)[i];
00117 }
00118 points->clear();
00119 }
00120
00121 inline void deallocate_points(KMPointArray *points) {
00122 if (points == NULL)
00123 return;
00124 for(unsigned int i=0;i<points->size();i++){
00125 delete (*points)[i];
00126 }
00127 delete points;
00128 }
00129 inline void copy_point(const KMPoint *p_from, KMPoint *p_to) {
00130 p_to->clear();
00131 for(unsigned int i=0;i<p_from->size();i++) {
00132 p_to->push_back((*p_from)[i]);
00133 }
00134 }
00135 void copy_points(KMPointArray *from, KMPointArray *to);
00136
00137 void print_point(const KMPoint &p,std::ostream& out = std::cout);
00138
00139 void print_points(const std::string &title,const KMPointArray &pa,
00140 std::ostream& out = std::cout);
00141
00142 #endif
00143
00144 IMPSTATISTICS_END_NAMESPACE
00145 #endif