Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::SVDAnalyzer Class Reference

Singular Value Decomposition from GSL. More...

#include <analyzer.h>

Inheritance diagram for EMAN::SVDAnalyzer:

[legend]
Collaboration diagram for EMAN::SVDAnalyzer:
[legend]
List of all members.

Public Member Functions

 SVDAnalyzer ()
virtual int insert_image (EMData *image)
 insert a image to the list of input images
virtual int insert_images_list (vector< EMData * > image_list)
 insert a list of images 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

AnalyzerNEW ()

Static Public Attributes

const string NAME = "svd_gsl"

Protected Attributes

EMDatamask
int nvec
int pixels
int nimg

Private Attributes

int nsofar
gsl_matrix * A

Detailed Description

Singular Value Decomposition from GSL.

Comparable to pca

Parameters:
mask mask image
nvec number of desired basis vectors
nimg total number of input images, required even with insert_image()

Definition at line 204 of file analyzer.h.


Constructor & Destructor Documentation

EMAN::SVDAnalyzer::SVDAnalyzer  )  [inline]
 

Definition at line 207 of file analyzer.h.

00207 : mask(0), nvec(0), nimg(0), A(NULL) {}


Member Function Documentation

vector< EMData * > SVDAnalyzer::analyze  )  [virtual]
 

main function for Analyzer, analyze input images and create output images

Returns:
vector<EMData *> result os images analysis

Implements EMAN::Analyzer.

Definition at line 756 of file analyzer.cpp.

References A, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), mask, nimg, EMAN::EMData::set_attr(), EMAN::EMData::set_size(), V, and X.

00757 {
00758 // Allocate the working space
00759 gsl_vector *work=gsl_vector_alloc(nimg);
00760 gsl_vector *S=gsl_vector_alloc(nimg);
00761 gsl_matrix *V=gsl_matrix_alloc(nimg,nimg);
00762 gsl_matrix *X=gsl_matrix_alloc(nimg,nimg);
00763 
00764 
00765 // Do the decomposition. All the real work is here
00766 gsl_linalg_SV_decomp_mod (A,X, V, S, work);
00767 //else gsl_linalg_SV_decomp_jacobi(A,V,S);
00768 
00769 vector<EMData*> ret;
00770 //unpack the results and write the output file
00771 float *md=mask->get_data();
00772 size_t totpix=mask->get_xsize()*mask->get_ysize()*mask->get_zsize();
00773 for (int k=0; k<nvec; k++) {
00774         EMData *img = new EMData;
00775         img->set_size(mask->get_xsize(),mask->get_ysize(),mask->get_zsize());
00776 
00777         float  *d=img->get_data();
00778         for (size_t i=0,j=0; i<totpix; ++i) {
00779                 if (md[i]) {
00780                         d[i]=(float)gsl_matrix_get(A,j,k);
00781                         j++;
00782                 }
00783         }
00784         img->set_attr( "eigval", gsl_vector_get(S,k));
00785         ret.push_back(img);
00786 }
00787 
00788 gsl_vector_free(work);
00789 gsl_vector_free(S);
00790 gsl_matrix_free(V);
00791 gsl_matrix_free(X);
00792 
00793 gsl_matrix_free(A);
00794 A=NULL;
00795 mask=NULL;
00796 
00797 return ret;
00798 }

string EMAN::SVDAnalyzer::get_desc  )  const [inline, virtual]
 

Get the Analyzer's description.

Returns:
The Analyzer's description.

Implements EMAN::Analyzer.

Definition at line 226 of file analyzer.h.

00227                 {
00228                         return "Singular Value Decomposition from GSL. Comparable to pca";
00229                 }

string EMAN::SVDAnalyzer::get_name  )  const [inline, virtual]
 

Get the Analyzer's name.

Each Analyzer is identified by a unique name.

Returns:
The Analyzer's name.

Implements EMAN::Analyzer.

Definition at line 221 of file analyzer.h.

00222                 {
00223                         return NAME;
00224                 }

TypeDict EMAN::SVDAnalyzer::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.

Returns:
A dictionary containing the parameter info.

Implements EMAN::Analyzer.

Definition at line 238 of file analyzer.h.

References EMAN::TypeDict::put().

00239                 {
00240                         TypeDict d;
00241                         d.put("mask", EMObject::EMDATA, "mask image");
00242                         d.put("nvec", EMObject::INT, "number of desired basis vectors");
00243                         d.put("nimg", EMObject::INT, "total number of input images, required even with insert_image()");
00244                         return d;
00245                 }

int SVDAnalyzer::insert_image EMData image  )  [virtual]
 

insert a image to the list of input images

Parameters:
image 
Returns:
int 0 for success, <0 for fail

Implements EMAN::Analyzer.

Definition at line 734 of file analyzer.cpp.

References A, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), mask, nsofar, and NullPointerException.

00735 {
00736         if (mask==0)
00737                 throw NullPointerException("Null mask image pointer, set_params() first");
00738 
00739         // count pixels under mask
00740         size_t totpix=mask->get_xsize()*mask->get_ysize()*mask->get_zsize();
00741         float  *d=image->get_data();
00742         float *md=mask ->get_data();
00743         for (size_t i=0,j=0; i<totpix; ++i) {
00744                 if (md[i]) {
00745                         gsl_matrix_set(A,j,nsofar,d[i]);
00746                         j++;
00747                 }
00748         }
00749         nsofar++;
00750 
00751    return 0;
00752 }

virtual int EMAN::SVDAnalyzer::insert_images_list vector< EMData * >  image_list  )  [inline, virtual]
 

insert a list of images to the list of input images

Parameters:
image_list 
Returns:
int 0 for success, <0 for fail

Reimplemented from EMAN::Analyzer.

Definition at line 211 of file analyzer.h.

References images.

00211                                                                             {
00212                         vector<EMData*>::const_iterator iter;
00213                         for(iter=image_list.begin(); iter!=image_list.end(); ++iter) {
00214                                 images.push_back(*iter);
00215                         }
00216                         return 0;
00217                 }

Analyzer* EMAN::SVDAnalyzer::NEW  )  [inline, static]
 

Definition at line 231 of file analyzer.h.

00232                 {
00233                         return new SVDAnalyzer();
00234                 }

void SVDAnalyzer::set_params const Dict new_params  )  [virtual]
 

Set the Analyzer parameters using a key/value dictionary.

Parameters:
new_params A dictionary containing the new parameters.

Reimplemented from EMAN::Analyzer.

Definition at line 800 of file analyzer.cpp.

References A, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), mask, nimg, nsofar, nvec, and pixels.

00801 {
00802         params = new_params;
00803         mask = params["mask"];
00804         nvec = params["nvec"];
00805         nimg = params["nimg"];
00806 
00807         // count pixels under mask
00808         pixels=0;
00809         size_t totpix=mask->get_xsize()*mask->get_ysize()*mask->get_zsize();
00810         float *d=mask->get_data();
00811         for (size_t i=0; i<totpix; ++i) if (d[i]) ++pixels;
00812 
00813         printf("%d,%d\n",pixels,nimg);
00814         A=gsl_matrix_alloc(pixels,nimg);
00815         nsofar=0;
00816 }


Member Data Documentation

gsl_matrix* EMAN::SVDAnalyzer::A [private]
 

Definition at line 257 of file analyzer.h.

Referenced by analyze(), insert_image(), and set_params().

EMData* EMAN::SVDAnalyzer::mask [protected]
 

Definition at line 250 of file analyzer.h.

Referenced by analyze(), insert_image(), and set_params().

const string EMAN::SVDAnalyzer::NAME = "svd_gsl" [static]
 

Definition at line 55 of file analyzer.cpp.

int EMAN::SVDAnalyzer::nimg [protected]
 

Definition at line 253 of file analyzer.h.

Referenced by analyze(), and set_params().

int EMAN::SVDAnalyzer::nsofar [private]
 

Definition at line 256 of file analyzer.h.

Referenced by insert_image(), and set_params().

int EMAN::SVDAnalyzer::nvec [protected]
 

Definition at line 251 of file analyzer.h.

Referenced by set_params().

int EMAN::SVDAnalyzer::pixels [protected]
 

Definition at line 252 of file analyzer.h.

Referenced by set_params().


The documentation for this class was generated from the following files:
Generated on Fri Apr 30 15:39:13 2010 for EMAN2 by  doxygen 1.3.9.1