analyzer.h

Go to the documentation of this file.
00001 
00005 /*
00006  * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
00007  * Copyright (c) 2000-2006 Baylor College of Medicine
00008  *
00009  * This software is issued under a joint BSD/GNU license. You may use the
00010  * source code in this file under either license. However, note that the
00011  * complete EMAN2 and SPARX software packages have some GPL dependencies,
00012  * so you are responsible for compliance with the licenses of these packages
00013  * if you opt to use BSD licensing. The warranty disclaimer below holds
00014  * in either instance.
00015  *
00016  * This complete copyright notice must be included in any revised version of the
00017  * source code. Additional authorship citations may be added, but existing
00018  * author citations must be preserved.
00019  *
00020  * This program is free software; you can redistribute it and/or modify
00021  * it under the terms of the GNU General Public License as published by
00022  * the Free Software Foundation; either version 2 of the License, or
00023  * (at your option) any later version.
00024  *
00025  * This program is distributed in the hope that it will be useful,
00026  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00028  * GNU General Public License for more details.
00029  *
00030  * You should have received a copy of the GNU General Public License
00031  * along with this program; if not, write to the Free Software
00032  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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;       //number of desired classes
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;       //number of desired principal components
00248                 int pixels;     // pixels under the mask
00249                 int nimg; // number of input images
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__

Generated on Sat Nov 7 02:18:55 2009 for EMAN2 by  doxygen 1.5.6