#include <analyzer_sparx.h>
Inheritance diagram for EMAN::PCAsmall:
Public Member Functions | |
PCAsmall () | |
virtual int | insert_image (EMData *image) |
insert a image to the list of input images | |
virtual vector< EMData * > | analyze () |
main function for Analyzer, analyze input images and create output images | |
string | get_name () const |
Get the Analyzer's name. | |
string | get_desc () const |
Get the Analyzer's description. | |
void | set_params (const Dict &new_params) |
Set the Analyzer parameters using a key/value dictionary. | |
TypeDict | get_param_types () const |
Get Analyzer parameter information in a dictionary. | |
Static Public Member Functions | |
static Analyzer * | NEW () |
Static Public Attributes | |
static const string | NAME = "pca" |
Protected Attributes | |
EMData * | mask |
int | nvec |
Private Attributes | |
float * | covmat |
int | ncov |
int | nimages |
float * | eigval |
Definition at line 45 of file analyzer_sparx.h.
EMAN::PCAsmall::PCAsmall | ( | ) | [inline] |
vector< EMData * > PCAsmall::analyze | ( | ) | [virtual] |
main function for Analyzer, analyze input images and create output images
Implements EMAN::Analyzer.
Definition at line 284 of file analyzer.cpp.
References coveig(), covmat, eigval, eigvec, EMDeletePtr(), EMAN::EMData::get_data(), EMAN::Analyzer::images, mask, ncov, nvec, rdata, reconstitute_image_mask(), EMAN::EMData::set_attr(), EMAN::EMData::set_size(), and status.
00285 { 00286 float *eigvec; 00287 int status = 0; 00288 // printf("start analyzing..., ncov = %d\n", ncov); 00289 eigval = (float*)calloc(ncov,sizeof(float)); 00290 eigvec = (float*)calloc(ncov*ncov,sizeof(float)); 00291 status = Util::coveig(ncov, covmat, eigval, eigvec); 00292 // for (int i=1; i<=nvec; i++) printf("eigval = %11.4e\n", 00293 // eigval[ncov-i]); 00294 00295 // pack eigenvectors into the return imagelist 00296 EMData *eigenimage = new EMData(); 00297 eigenimage->set_size(ncov,1,1); 00298 float *rdata = eigenimage->get_data(); 00299 for (int j = 1; j<= nvec; j++) { 00300 for (int i = 0; i < ncov; i++) rdata[i] = eigvec(i,ncov-j); 00301 00302 EMData* recons_eigvec = Util::reconstitute_image_mask(eigenimage,mask); 00303 recons_eigvec->set_attr( "eigval", eigval[j-1] ); 00304 images.push_back(recons_eigvec); 00305 } 00306 00307 free(eigvec); 00308 EMDeletePtr(eigenimage); 00309 00310 return images; 00311 }
string EMAN::PCAsmall::get_desc | ( | ) | const [inline, virtual] |
Get the Analyzer's description.
Implements EMAN::Analyzer.
Definition at line 64 of file analyzer_sparx.h.
string EMAN::PCAsmall::get_name | ( | ) | const [inline, virtual] |
Get the Analyzer's name.
Each Analyzer is identified by a unique name.
Implements EMAN::Analyzer.
Definition at line 59 of file analyzer_sparx.h.
References NAME.
00060 { 00061 return NAME; 00062 }
TypeDict EMAN::PCAsmall::get_param_types | ( | ) | const [inline, virtual] |
Get Analyzer parameter information in a dictionary.
Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.
Implements EMAN::Analyzer.
Definition at line 83 of file analyzer_sparx.h.
References EMAN::EMObject::EMDATA, EMAN::EMObject::INT, and EMAN::TypeDict::put().
00084 { 00085 TypeDict d; 00086 d.put("mask", EMObject::EMDATA, "mask image"); 00087 d.put("nvec", EMObject::INT, "number of desired principal components"); 00088 return d; 00089 }
int PCAsmall::insert_image | ( | EMData * | image | ) | [virtual] |
insert a image to the list of input images
image |
Implements EMAN::Analyzer.
Definition at line 257 of file analyzer.cpp.
References compress_image_mask(), covmat, EMDeletePtr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), imgdata, mask, ncov, nimages, NullPointerException, and nx.
00258 { 00259 if(mask==0) 00260 throw NullPointerException("Null mask image pointer, set_params() first"); 00261 00262 EMData *maskedimage = Util::compress_image_mask(image,mask); 00263 00264 int nx = maskedimage->get_xsize(); 00265 float *imgdata = maskedimage->get_data(); 00266 if (nx != ncov) { 00267 fprintf(stderr,"insert_image: something is wrong...\n"); 00268 exit(1); 00269 } 00270 00271 // there is a faster version of the following rank-1 update 00272 nimages++; 00273 for (int j = 1; j <= nx; j++) 00274 for (int i = 1; i<=nx; i++) { 00275 covmat(i,j) += imgdata(i)*imgdata(j); 00276 } 00277 00278 EMDeletePtr(maskedimage); 00279 return 0; 00280 }
static Analyzer* EMAN::PCAsmall::NEW | ( | ) | [inline, static] |
Definition at line 69 of file analyzer_sparx.h.
References PCAsmall().
00070 { 00071 return new PCAsmall(); 00072 }
void PCAsmall::set_params | ( | const Dict & | new_params | ) | [virtual] |
Set the Analyzer parameters using a key/value dictionary.
new_params | A dictionary containing the new parameters. |
Reimplemented from EMAN::Analyzer.
Definition at line 314 of file analyzer.cpp.
References compress_image_mask(), covmat, EMDeletePtr(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), mask, ncov, nimages, nvec, nx, ny, EMAN::Analyzer::params, and EMAN::EMData::set_size().
00315 { 00316 params = new_params; 00317 mask = params["mask"]; 00318 nvec = params["nvec"]; 00319 00320 // count the number of pixels under the mask 00321 // (this is really ugly!!!) 00322 EMData *dummy = new EMData(); 00323 00324 int nx = mask->get_xsize(); 00325 int ny = mask->get_ysize(); 00326 int nz = mask->get_zsize(); 00327 00328 dummy->set_size(nx,ny,nz); 00329 00330 EMData *dummy1d = Util::compress_image_mask(dummy,mask); 00331 ncov = dummy1d->get_xsize(); 00332 EMDeletePtr(dummy); 00333 EMDeletePtr(dummy1d); 00334 00335 // allocate and set up the covriance matrix 00336 nimages = 0; 00337 covmat = (float*)calloc(ncov*ncov,sizeof(float)); 00338 }
float* EMAN::PCAsmall::covmat [private] |
Definition at line 98 of file analyzer_sparx.h.
Referenced by analyze(), insert_image(), and set_params().
float* EMAN::PCAsmall::eigval [private] |
EMData* EMAN::PCAsmall::mask [protected] |
Definition at line 94 of file analyzer_sparx.h.
Referenced by analyze(), insert_image(), and set_params().
const string EMAN::PCAsmall::NAME = "pca" [static] |
int EMAN::PCAsmall::ncov [private] |
Definition at line 99 of file analyzer_sparx.h.
Referenced by analyze(), insert_image(), and set_params().
int EMAN::PCAsmall::nimages [private] |
int EMAN::PCAsmall::nvec [protected] |