analyzer.h
Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef eman_analyzer_h__
00037 #define eman_analyzer_h__
00038
00039 #include "emobject.h"
00040 #include <gsl/gsl_linalg.h>
00041 using std::vector;
00042
00043 namespace EMAN
00044 {
00045 class EMData;
00046
00060 class Analyzer
00061 {
00062 public:
00063 Analyzer() {}
00064
00065 virtual ~Analyzer()
00066 {}
00067
00072 virtual int insert_image(EMData * image) = 0;
00073
00078 virtual int insert_images_list(vector<EMData *> image_list);
00079
00083 virtual vector<EMData*> analyze() = 0;
00084
00088 virtual string get_name() const = 0;
00089
00093 virtual string get_desc() const = 0;
00094
00098 virtual void set_params(const Dict & new_params)
00099 {
00100 params = new_params;
00101 }
00102
00106 virtual Dict get_params() const
00107 {
00108 return params;
00109 }
00110
00117 virtual TypeDict get_param_types() const = 0;
00118
00119 protected:
00120 mutable Dict params;
00121 vector<EMData *> images;
00122 };
00123
00138 class KMeansAnalyzer:public Analyzer
00139 {
00140 public:
00141 KMeansAnalyzer() : ncls(0),verbose(0),minchange(0),maxiter(100),mininclass(2),slowseed(0) {}
00142
00143 virtual int insert_image(EMData * image) {
00144 images.push_back(image);
00145 return 0;
00146 }
00147
00148 virtual vector<EMData*> analyze();
00149
00150 string get_name() const
00151 {
00152 return "kmeans";
00153 }
00154
00155 string get_desc() const
00156 {
00157 return "k-means classification";
00158 }
00159
00160 static Analyzer * NEW()
00161 {
00162 return new KMeansAnalyzer();
00163 }
00164
00165 void set_params(const Dict & new_params);
00166
00167 TypeDict get_param_types() const
00168 {
00169 TypeDict d;
00170 d.put("verbose", EMObject::INT, "Display progress if set, more detail with larger numbers (9 max)");
00171 d.put("ncls", EMObject::INT, "number of desired classes");
00172 d.put("maxiter", EMObject::INT, "maximum number of iterations");
00173 d.put("minchange", EMObject::INT, "Terminate if fewer than minchange members move in an iteration");
00174 d.put("mininclass", EMObject::INT, "Minumum number of particles to keep a class as good (not enforced at termination");
00175 d.put("slowseed",EMObject::INT, "Instead of seeding all classes at once, it will gradually increase the number of classes by adding new seeds in groups with large standard deviations");
00176 d.put("calcsigmamean",EMObject::INT, "Computes standard deviation of the mean image for each class-average (center), and returns them at the end of the list of centers");
00177 return d;
00178 }
00179
00180 protected:
00181 void update_centers(int sigmas=0);
00182 void reclassify();
00183 void reseed();
00184
00185 vector<EMData *> centers;
00186 int ncls;
00187 int verbose;
00188 int minchange;
00189 int maxiter;
00190 int mininclass;
00191 int nchanged;
00192 int slowseed;
00193 int calcsigmamean;
00194
00195 };
00196
00202 class SVDAnalyzer : public Analyzer
00203 {
00204 public:
00205 SVDAnalyzer() : mask(0), nvec(0), nimg(0), A(NULL) {}
00206
00207 virtual int insert_image(EMData * image);
00208
00209 virtual int insert_images_list(vector<EMData *> image_list) {
00210 vector<EMData*>::const_iterator iter;
00211 for(iter=image_list.begin(); iter!=image_list.end(); ++iter) {
00212 images.push_back(*iter);
00213 }
00214 return 0;
00215 }
00216
00217 virtual vector<EMData*> analyze();
00218
00219 string get_name() const
00220 {
00221 return "svd_gsl";
00222 }
00223
00224 string get_desc() const
00225 {
00226 return "Singular Value Decomposition from GSL. Comparable to pca";
00227 }
00228
00229 static Analyzer * NEW()
00230 {
00231 return new SVDAnalyzer();
00232 }
00233
00234 void set_params(const Dict & new_params);
00235
00236 TypeDict get_param_types() const
00237 {
00238 TypeDict d;
00239 d.put("mask", EMObject::EMDATA, "mask image");
00240 d.put("nvec", EMObject::INT, "number of desired basis vectors");
00241 d.put("nimg", EMObject::INT, "total number of input images, required even with insert_image()");
00242 return d;
00243 }
00244
00245 protected:
00246 EMData * mask;
00247 int nvec;
00248 int pixels;
00249 int nimg;
00250
00251 private:
00252 int nsofar;
00253 gsl_matrix *A;
00254 };
00255
00256 template <> Factory < Analyzer >::Factory();
00257
00258 void dump_analyzers();
00259 map<string, vector<string> > dump_analyzers_list();
00260 }
00261
00262 #endif //eman_analyzer_h__