EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Private Attributes
EMAN::PCAsmall Class Reference

Principal component analysis. More...

#include <analyzer_sparx.h>

Inheritance diagram for EMAN::PCAsmall:
Inheritance graph
[legend]
Collaboration diagram for EMAN::PCAsmall:
Collaboration graph
[legend]

List of all members.

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 AnalyzerNEW ()

Static Public Attributes

static const string NAME = "pca"

Protected Attributes

EMDatamask
int nvec

Private Attributes

float * covmat
int ncov
int nimages
float * eigval

Detailed Description

Principal component analysis.

Definition at line 45 of file analyzer_sparx.h.


Constructor & Destructor Documentation

EMAN::PCAsmall::PCAsmall ( ) [inline]

Definition at line 48 of file analyzer_sparx.h.

Referenced by NEW().

: mask(0), nvec(0) {}

Member Function Documentation

vector< EMData * > PCAsmall::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 362 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.

{
        float *eigvec;
        int status = 0;
//              printf("start analyzing..., ncov = %d\n", ncov);
        eigval = (float*)calloc(ncov,sizeof(float));
        eigvec = (float*)calloc(ncov*ncov,sizeof(float));
        status = Util::coveig(ncov, covmat, eigval, eigvec);
//       for (int i=1; i<=nvec; i++) printf("eigval = %11.4e\n",
//            eigval[ncov-i]);

        // pack eigenvectors into the return imagelist
        EMData *eigenimage = new EMData();
        eigenimage->set_size(ncov,1,1);
        float *rdata = eigenimage->get_data();
        for (int j = 1; j<= nvec; j++) {
            for (int i = 0; i < ncov; i++) rdata[i] = eigvec(i,ncov-j);

                EMData* recons_eigvec = Util::reconstitute_image_mask(eigenimage,mask);
                recons_eigvec->set_attr( "eigval", eigval[j-1] );
            images.push_back(recons_eigvec);
        }

        free(eigvec);
        EMDeletePtr(eigenimage);

        return images;
}
string EMAN::PCAsmall::get_desc ( ) const [inline, virtual]

Get the Analyzer's description.

Returns:
The Analyzer's description.

Implements EMAN::Analyzer.

Definition at line 64 of file analyzer_sparx.h.

                {
                        return "Principal component analysis";
                }
string EMAN::PCAsmall::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 59 of file analyzer_sparx.h.

References NAME.

                {
                        return NAME;
                }               
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.

Returns:
A dictionary containing the parameter info.

Implements EMAN::Analyzer.

Definition at line 83 of file analyzer_sparx.h.

References EMAN::EMObject::EMDATA, EMAN::EMObject::INT, and EMAN::TypeDict::put().

                {
                        TypeDict d;
                        d.put("mask", EMObject::EMDATA, "mask image");
                        d.put("nvec", EMObject::INT, "number of desired principal components");
                        return d;
                }
int PCAsmall::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 335 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.

{
        if(mask==0)
                throw NullPointerException("Null mask image pointer, set_params() first");

   EMData *maskedimage = Util::compress_image_mask(image,mask);

   int nx = maskedimage->get_xsize();
   float *imgdata = maskedimage->get_data();
   if (nx != ncov) {
      fprintf(stderr,"insert_image: something is wrong...\n");
      exit(1);
   }

   // there is a faster version of the following rank-1 update
   nimages++;
   for (int j = 1; j <= nx; j++)
       for (int i = 1; i<=nx; i++) {
           covmat(i,j) += imgdata(i)*imgdata(j);
   }

   EMDeletePtr(maskedimage);
   return 0;
}
static Analyzer* EMAN::PCAsmall::NEW ( ) [inline, static]

Definition at line 69 of file analyzer_sparx.h.

References PCAsmall().

                {
                        return new PCAsmall();
                }
void PCAsmall::set_params ( const Dict new_params) [virtual]

Set the Analyzer parameters using a key/value dictionary.

Parameters:
new_paramsA dictionary containing the new parameters.

Reimplemented from EMAN::Analyzer.

Definition at line 392 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().

{
        params = new_params;
        mask = params["mask"];
        nvec = params["nvec"];

        // count the number of pixels under the mask
        // (this is really ugly!!!)
        EMData *dummy = new EMData();

        int nx = mask->get_xsize();
        int ny = mask->get_ysize();
        int nz = mask->get_zsize();

        dummy->set_size(nx,ny,nz);

        EMData *dummy1d = Util::compress_image_mask(dummy,mask);
        ncov = dummy1d->get_xsize();
        EMDeletePtr(dummy);
        EMDeletePtr(dummy1d);

        // allocate and set up the covriance matrix
        nimages = 0;
        covmat = (float*)calloc(ncov*ncov,sizeof(float));
}

Member Data Documentation

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]

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().

const string EMAN::PCAsmall::NAME = "pca" [static]

Definition at line 91 of file analyzer_sparx.h.

Referenced by get_name().

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]

Definition at line 100 of file analyzer_sparx.h.

Referenced by insert_image(), and set_params().

int EMAN::PCAsmall::nvec [protected]

Definition at line 95 of file analyzer_sparx.h.

Referenced by analyze(), and set_params().


The documentation for this class was generated from the following files: