#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 | |
| Analyzer * | NEW () |
Static Public Attributes | |
| 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.
|
|
Definition at line 48 of file analyzer_sparx.h.
|
|
|
main function for Analyzer, analyze input images and create output images
Implements EMAN::Analyzer. Definition at line 275 of file analyzer.cpp. References coveig(), covmat, eigval, eigvec, EMDeletePtr(), EMAN::EMData::get_data(), mask, ncov, rdata, reconstitute_image_mask(), EMAN::EMData::set_attr(), EMAN::EMData::set_size(), and status. 00276 {
00277 float *eigvec;
00278 int status = 0;
00279 // printf("start analyzing..., ncov = %d\n", ncov);
00280 eigval = (float*)calloc(ncov,sizeof(float));
00281 eigvec = (float*)calloc(ncov*ncov,sizeof(float));
00282 status = Util::coveig(ncov, covmat, eigval, eigvec);
00283 // for (int i=1; i<=nvec; i++) printf("eigval = %11.4e\n",
00284 // eigval[ncov-i]);
00285
00286 // pack eigenvectors into the return imagelist
00287 EMData *eigenimage = new EMData();
00288 eigenimage->set_size(ncov,1,1);
00289 float *rdata = eigenimage->get_data();
00290 for (int j = 1; j<= nvec; j++) {
00291 for (int i = 0; i < ncov; i++) rdata[i] = eigvec(i,ncov-j);
00292
00293 EMData* recons_eigvec = Util::reconstitute_image_mask(eigenimage,mask);
00294 recons_eigvec->set_attr( "eigval", eigval[j-1] );
00295 images.push_back(recons_eigvec);
00296 }
00297
00298 free(eigvec);
00299 EMDeletePtr(eigenimage);
00300
00301 return images;
00302 }
|
|
|
Get the Analyzer's description.
Implements EMAN::Analyzer. Definition at line 64 of file analyzer_sparx.h. 00065 {
00066 return "Principal component analysis";
00067 }
|
|
|
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. 00060 {
00061 return NAME;
00062 }
|
|
|
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::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 }
|
|
|
insert a image to the list of input images
Implements EMAN::Analyzer. Definition at line 248 of file analyzer.cpp. References compress_image_mask(), covmat, EMDeletePtr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), imgdata, mask, nimages, NullPointerException, and nx. 00249 {
00250 if(mask==0)
00251 throw NullPointerException("Null mask image pointer, set_params() first");
00252
00253 EMData *maskedimage = Util::compress_image_mask(image,mask);
00254
00255 int nx = maskedimage->get_xsize();
00256 float *imgdata = maskedimage->get_data();
00257 if (nx != ncov) {
00258 fprintf(stderr,"insert_image: something is wrong...\n");
00259 exit(1);
00260 }
00261
00262 // there is a faster version of the following rank-1 update
00263 nimages++;
00264 for (int j = 1; j <= nx; j++)
00265 for (int i = 1; i<=nx; i++) {
00266 covmat(i,j) += imgdata(i)*imgdata(j);
00267 }
00268
00269 EMDeletePtr(maskedimage);
00270 return 0;
00271 }
|
|
|
Definition at line 69 of file analyzer_sparx.h. 00070 {
00071 return new PCAsmall();
00072 }
|
|
|
Set the Analyzer parameters using a key/value dictionary.
Reimplemented from EMAN::Analyzer. Definition at line 305 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, and EMAN::EMData::set_size(). 00306 {
00307 params = new_params;
00308 mask = params["mask"];
00309 nvec = params["nvec"];
00310
00311 // count the number of pixels under the mask
00312 // (this is really ugly!!!)
00313 EMData *dummy = new EMData();
00314
00315 int nx = mask->get_xsize();
00316 int ny = mask->get_ysize();
00317 int nz = mask->get_zsize();
00318
00319 dummy->set_size(nx,ny,nz);
00320
00321 EMData *dummy1d = Util::compress_image_mask(dummy,mask);
00322 ncov = dummy1d->get_xsize();
00323 EMDeletePtr(dummy);
00324 EMDeletePtr(dummy1d);
00325
00326 // allocate and set up the covriance matrix
00327 nimages = 0;
00328 covmat = (float*)calloc(ncov*ncov,sizeof(float));
00329 }
|
|
|
Definition at line 98 of file analyzer_sparx.h. Referenced by analyze(), insert_image(), and set_params(). |
|
|
Definition at line 101 of file analyzer_sparx.h. Referenced by analyze(). |
|
|
Definition at line 94 of file analyzer_sparx.h. Referenced by analyze(), insert_image(), and set_params(). |
|
|
Definition at line 51 of file analyzer.cpp. |
|
|
Definition at line 99 of file analyzer_sparx.h. Referenced by analyze(), and set_params(). |
|
|
Definition at line 100 of file analyzer_sparx.h. Referenced by insert_image(), and set_params(). |
|
|
Definition at line 95 of file analyzer_sparx.h. Referenced by set_params(). |
1.3.9.1