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

model::Analyzer Class Reference
[The PCG model layer]

#include <Analyzer.h>

Collaboration diagram for model::Analyzer:

Collaboration graph
[legend]
List of all members.

Public Types

enum  e_PCAMode { ALL, JACOBI, HOUSEHOLDER, OTHER }

Public Member Functions

 Analyzer ()
 Constructor for the PCA.
 ~Analyzer ()
 Analyzer (const Analyzer &other)
Analyzeroperator= (const Analyzer &other)
void mergeData (ReferenceModel refModel, vector< ExampleModel * > lmodels, int size)
void mergeData (ReferenceModel refModel, vector< ExampleModel * > lmodels)
void mean ()
 Calculates the emperical mean of a matrix.
void adjust ()
void covariance ()
void findComponents ()
void findComponents (e_PCAMode mode)
void selectComponents ()
void computeEnergy ()
void setData (Matrix data)
void transformation ()
int getInputDimension ()
ReferenceModel getModel ()
ReferenceModel getModel (Matrix input)
bool save (char *filename)
bool load (char *filename)

Private Attributes

Matrix m_ExampleData
Matrix m_mean
Matrix m_AdjustedData
Matrix m_Covariance
SymmetricMatrix m_EigenValues
Matrix m_EigenVectors
Matrix m_TotalEnergy
Matrix m_Components
Matrix m_Transformation
int N
int M
ReferenceModel m_refModel

Detailed Description

Write brief comment for Analyzer here.

Write detailed description for Analyzer here.

Remarks:
Write remarks for Analyzer here.
See also:
Separate items with the '|' character.

Definition at line 33 of file Analyzer.h.


Member Enumeration Documentation

enum model::Analyzer::e_PCAMode
 

Write brief comment for e_PCAMode here.

Write detailed description for e_PCAMode here.

Remarks:
Write remarks for e_PCAMode here.
See also:
Separate items with the '|' character.
Enumeration values:
ALL  All methods
JACOBI  Jacobi method
HOUSEHOLDER  Householder method
OTHER  Other methods

Definition at line 63 of file Analyzer.h.

00063                                { 
00064                         ALL, 
00065                         JACOBI, 
00066                         HOUSEHOLDER, 
00067                         OTHER 
00068                 };


Constructor & Destructor Documentation

Analyzer::Analyzer  ) 
 

Constructor for the PCA.

This default constructer does stuff and initiates a PCA process

Definition at line 9 of file Analyzer.cpp.

References log::write().

00010 {
00011         log::write("Analyzer Init");
00012 }

Here is the call graph for this function:

Analyzer::~Analyzer  ) 
 

Write brief comment for ~Analyzer here.

Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for ~Analyzer here.

Remarks:
Write remarks for ~Analyzer here.
See also:
Separate items with the '|' character.

Definition at line 29 of file Analyzer.cpp.

References m_AdjustedData, m_Covariance, m_EigenValues, m_EigenVectors, m_ExampleData, and m_mean.

00030 {
00031         m_ExampleData = 0;
00032         m_mean = 0;
00033         m_AdjustedData = 0;
00034         m_Covariance = 0;
00035         m_EigenValues = 0;
00036         m_EigenVectors = 0;
00037 }

Analyzer::Analyzer const Analyzer other  ) 
 

Write brief comment for Analyzer here.

Parameters:
other Description of parameter other.
Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for Analyzer here.

Remarks:
Write remarks for Analyzer here.
See also:
Separate items with the '|' character.

Definition at line 583 of file Analyzer.cpp.

References M, m_AdjustedData, m_Components, m_Covariance, m_EigenValues, m_EigenVectors, m_ExampleData, m_mean, m_refModel, m_TotalEnergy, m_Transformation, and N.

00583                                         {
00584         m_ExampleData = other.m_ExampleData;
00585         m_mean = other.m_mean;
00586         m_AdjustedData = other.m_AdjustedData;
00587         m_Covariance = other.m_Covariance;
00588         m_EigenValues = other.m_EigenValues;
00589         m_EigenVectors = other.m_EigenVectors;
00590         m_TotalEnergy = other.m_TotalEnergy;
00591         m_Components = other.m_Components;
00592         m_Transformation = other.m_Transformation;
00593         N = other.N;
00594         M = other.M;
00595         m_refModel = other.m_refModel;
00596 }  


Member Function Documentation

void Analyzer::adjust  ) 
 

Write brief comment for adjust here.

Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for adjust here.

Remarks:
Write remarks for adjust here.
See also:
Separate items with the '|' character.

Definition at line 179 of file Analyzer.cpp.

References m_AdjustedData, m_ExampleData, m_mean, N, and log::write().

Referenced by pcggui::Analyze(), Batch::analyzeModel(), and Batch::TestAnalyzer().

00180 {
00181         log::write("Analyzer adjust");
00182         Matrix h = Matrix(1,N);
00183         h = 1;
00184         /*cout << setw(10) << setprecision(5) << m_ExampleData;
00185         cout << setw(10) << setprecision(5) << m_mean;
00186         cout << setw(10) << setprecision(5) << h;
00187         cout << setw(10) << setprecision(5) << (m_mean * h);*/
00188         m_AdjustedData = m_ExampleData - (m_mean * h);
00189         log::write("Adjusted Data",m_AdjustedData);
00190 }

Here is the call graph for this function:

void Analyzer::computeEnergy  ) 
 

Write brief comment for computeEnergy here.

Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for computeEnergy here.

Remarks:
Write remarks for computeEnergy here.
See also:
Separate items with the '|' character.

Definition at line 301 of file Analyzer.cpp.

References M, m_EigenValues, m_TotalEnergy, and log::write().

Referenced by pcggui::Analyze(), Batch::analyzeModel(), and Batch::TestAnalyzer().

00302 {
00303         log::write("Analyzer compute energy");
00304         //Requires that EigenVectors and Values are sorted pair-wise. Should be done
00305         //by the matrix library i believe (this should be tested somehow)
00306 
00307         m_TotalEnergy = Matrix(M,1); // [ M x 1 ]
00308         m_EigenValues = m_EigenValues.Reverse();
00309         m_TotalEnergy(1,1) = m_EigenValues(1,1);
00310         for(int i=2;i<=M;i++)
00311         {
00312                 m_TotalEnergy(i,1) = m_TotalEnergy(i-1,1) + m_EigenValues(i,i);
00313         }
00314         log::write("Total Energy",m_TotalEnergy);
00315 }

Here is the call graph for this function:

void Analyzer::covariance  ) 
 

Write brief comment for covariance here.

Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for covariance here.

Remarks:
Write remarks for covariance here.
See also:
Separate items with the '|' character.

Definition at line 207 of file Analyzer.cpp.

References m_AdjustedData, m_Covariance, N, and log::write().

Referenced by pcggui::Analyze(), Batch::analyzeModel(), and Batch::TestAnalyzer().

00208 {
00209         log::write("Analyzer covariance");
00210         m_Covariance = m_AdjustedData/(N-1) * m_AdjustedData.t();
00211         log::write("Covariance",m_Covariance);
00212 }

Here is the call graph for this function:

void Analyzer::findComponents e_PCAMode  mode  ) 
 

Write brief comment for findComponents here.

Parameters:
mode Description of parameter mode.
Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for findComponents here.

Remarks:
Write remarks for findComponents here.
See also:
Separate items with the '|' character.

Definition at line 252 of file Analyzer.cpp.

References HOUSEHOLDER, JACOBI, M, m_EigenValues, m_EigenVectors, OTHER, and log::write().

00253 {
00254         log::write("Analyzer find components");
00255         DiagonalMatrix dm(M);
00256         SymmetricMatrix test;
00257         test << m_Covariance;
00258         
00259         switch (mode)
00260         {
00261           case JACOBI:
00262             log::write("Calculating with Jacobi");
00263             Jacobi(test, dm, m_EigenVectors);
00264             break;
00265           case HOUSEHOLDER:
00266             log::write("Calculating with Householder");
00267             EigenValues(test, dm, m_EigenVectors);
00268             break;
00269           case OTHER:
00270             log::write("Calculating with Jacobi (matched OTHER)");
00271             Jacobi(test, dm, m_EigenVectors);
00272             break;
00273           default:
00274             log::write("Calculating with Jacobi (matched default)");
00275             Jacobi(test, dm, m_EigenVectors);
00276             break;
00277         }
00278         //Jacobi(test, dm, m_EigenVectors);
00279         //EigenValues(test, dm, m_EigenVectors);
00280         m_EigenValues << dm;
00281 
00282         log::write("Eigen Vectors",m_EigenVectors);
00283         log::write("Eigen Values",m_EigenValues);
00284 }

Here is the call graph for this function:

void Analyzer::findComponents  ) 
 

Write brief comment for findComponents here.

Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for findComponents here.

Remarks:
Write remarks for findComponents here.
See also:
Separate items with the '|' character.

Definition at line 229 of file Analyzer.cpp.

References JACOBI.

Referenced by pcggui::Analyze(), Batch::analyzeModel(), and Batch::TestAnalyzer().

00230 {
00231   findComponents(JACOBI);
00232 }

int Analyzer::getInputDimension  ) 
 

Write brief comment for getInputDimension here.

Returns:
Write description of return value here.
Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for getInputDimension here.

Remarks:
Write remarks for getInputDimension here.
See also:
Separate items with the '|' character.

Definition at line 450 of file Analyzer.cpp.

References m_Components.

Referenced by Batch::getRandomModels().

00450                                 {
00451         return m_Components.Ncols();
00452 }

ReferenceModel Analyzer::getModel Matrix  input  ) 
 

Write brief comment for getModel here.

Parameters:
input Description of parameter input.
Returns:
Write description of return value here.
Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for getModel here.

Remarks:
Write remarks for getModel here.
See also:
Separate items with the '|' character.

Definition at line 421 of file Analyzer.cpp.

References m_Components, m_mean, m_refModel, N, model::Model::updateVertices(), and log::write().

00421                                               {
00422     log::write("Analyzer::getModel\n");
00423         Matrix h = Matrix(1,N);
00424         h = 1;
00425         Matrix in = m_Components*input+(m_mean * h);
00426         log::write("Analyzer-in",in);
00427         m_refModel.updateVertices(in);
00428         log::write("Analyzer-refModel",m_refModel);
00429         return m_refModel;
00430 }

Here is the call graph for this function:

ReferenceModel Analyzer::getModel  ) 
 

Write brief comment for getModel here.

Returns:
Write description of return value here.
Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for getModel here.

Remarks:
Write remarks for getModel here.
See also:
Separate items with the '|' character.

Definition at line 393 of file Analyzer.cpp.

References m_Components, m_mean, m_refModel, m_Transformation, N, and model::Model::updateVertices().

Referenced by Batch::getRandomModels().

00393                                   {
00394         Matrix h = Matrix(1,N);
00395         h = 1;
00396         m_refModel.updateVertices(m_Components*m_Transformation+(m_mean*h));
00397         return m_refModel;
00398 }

Here is the call graph for this function:

bool Analyzer::load char *  filename  ) 
 

Write brief comment for load here.

Parameters:
filename Description of parameter filename.
Returns:
Write description of return value here.
Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for load here.

Remarks:
Write remarks for load here.
See also:
Separate items with the '|' character.

Definition at line 513 of file Analyzer.cpp.

References model::ReferenceModel::load(), m_Components, m_mean, m_refModel, and Tokenize().

Referenced by pcggui::LoadAnalyzer().

00513                                   {
00514         m_mean.CleanUp();
00515         m_Components.CleanUp();
00516         m_refModel = model::ReferenceModel();
00517 
00518         string line;
00519         vector<string> tokens;
00520         vector<string> coords;
00521 
00522         ifstream loadFile(filename);
00523         if(loadFile.is_open()) {
00524                 getline(loadFile,line);//Mean Dim
00525                 getline(loadFile,line);//Dim
00526                 tokens.clear();
00527                 Tokenize(line,tokens,",");
00528                 m_mean = Matrix(convertTo<int>(tokens[0]),convertTo<int>(tokens[1]));
00529 
00530                 for(int i=0;i<m_mean.Nrows();i++) {
00531                         getline(loadFile,line);//Data
00532                         tokens.clear();
00533                         Tokenize(line,tokens," ");
00534                         for(int n=0;n<m_mean.Ncols();n++) {
00535                                 m_mean(i+1,n+1) = convertTo<float>(tokens[n]);
00536                         }
00537                 }
00538 
00539                 getline(loadFile,line);//
00540                 getline(loadFile,line);//Components Dim
00541                 getline(loadFile,line);//Dim
00542                 tokens.clear();
00543                 Tokenize(line,tokens,",");
00544                 m_Components = Matrix(convertTo<int>(tokens[0]),convertTo<int>(tokens[1]));
00545 
00546                 for(int i=0;i<m_Components.Nrows();i++) {
00547                         getline(loadFile,line);//Data
00548                         tokens.clear();
00549                         Tokenize(line,tokens," ");
00550                         for(int n=0;n<m_Components.Ncols();n++) {
00551                                 m_Components(i+1,n+1) = convertTo<float>(tokens[n]);
00552                         }
00553                 }
00554                 
00555                 getline(loadFile,line);//
00556                 m_refModel.load(&loadFile);
00557                 loadFile.close();
00558                 return true;
00559         } else {
00560                 return false;
00561         }
00562 }

Here is the call graph for this function:

void Analyzer::mean  ) 
 

Calculates the emperical mean of a matrix.

Write brief comment for mean here.

Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for mean here.

Remarks:
Write remarks for mean here.
See also:
Separate items with the '|' character.

Definition at line 150 of file Analyzer.cpp.

References M, m_ExampleData, m_mean, N, and log::write().

Referenced by pcggui::Analyze(), Batch::analyzeModel(), and Batch::TestAnalyzer().

00151 {
00152         log::write("Analyzer mean");
00153         m_mean = Matrix(M,1); //[M x 1]
00154         for(int i=1;i <= M; i++)
00155         {
00156                 /*    printf("Integer %d\n", i);
00157                 printf("Cols: %d\n", data.Ncols()); 
00158                 printf("Sum: %f\n", data.Row(i).Sum());*/
00159                 m_mean(i,1) = 1.0/N * m_ExampleData.Row(i).Sum();
00160         }
00161         log::write("Mean",m_mean);
00162 }

Here is the call graph for this function:

void Analyzer::mergeData ReferenceModel  refModel,
vector< ExampleModel * >  lmodels
 

Write brief comment for mergeData here.

Parameters:
refModel Description of parameter refModel.
lmodels Description of parameter lmodels.
Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for mergeData here.

Remarks:
Write remarks for mergeData here.
See also:
Separate items with the '|' character.

Definition at line 60 of file Analyzer.cpp.

References mergeData().

00060                                                                                {
00061         mergeData(refModel, lmodels,(int)lmodels.size());
00062 }

Here is the call graph for this function:

void Analyzer::mergeData ReferenceModel  refModel,
vector< ExampleModel * >  lmodels,
int  size
 

Write brief comment for mergeData here.

Parameters:
refModel Description of parameter refModel.
lmodels Description of parameter lmodels.
size Description of parameter size.
Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for mergeData here.

Remarks:
Write remarks for mergeData here.
See also:
Separate items with the '|' character.

Definition at line 88 of file Analyzer.cpp.

References model::Model::getModelVertexs(), M, m_ExampleData, m_refModel, N, and log::write().

Referenced by pcggui::Analyze(), Batch::analyzeModel(), mergeData(), and Batch::TestAnalyzer().

00089 {
00090         log::write("Analyzer merge data");
00091         log::write("Number of models",size);
00092         m_refModel = refModel;
00093         for(int i=0;i<size;i++) {
00094                 Matrix mv = lmodels[i]->getModelVertexs();
00095                 if(i==0) {
00096                         m_ExampleData = mv;
00097                 } else {
00098                         m_ExampleData = m_ExampleData | mv;
00099                 }
00100         }
00101         N = m_ExampleData.Ncols();
00102         M = m_ExampleData.Nrows();
00103         log::write("N",N);
00104         log::write("M",M);
00105         log::write("Example Data",m_ExampleData);
00106 }

Here is the call graph for this function:

Analyzer & Analyzer::operator= const Analyzer other  ) 
 

Write brief comment for operator = here.

Parameters:
other Description of parameter other.
Returns:
Write description of return value here.
Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for operator = here.

Remarks:
Write remarks for operator = here.
See also:
Separate items with the '|' character.

Definition at line 620 of file Analyzer.cpp.

References M, m_AdjustedData, m_Components, m_Covariance, m_EigenValues, m_EigenVectors, m_ExampleData, m_mean, m_refModel, m_TotalEnergy, m_Transformation, and N.

00621 {
00622     // if same object
00623     if ( this == &other )
00624         return *this;
00625         
00626         m_ExampleData = other.m_ExampleData;
00627         m_mean = other.m_mean;
00628         m_AdjustedData = other.m_AdjustedData;
00629         m_Covariance = other.m_Covariance;
00630         m_EigenValues = other.m_EigenValues;
00631         m_EigenVectors = other.m_EigenVectors;
00632         m_TotalEnergy = other.m_TotalEnergy;
00633         m_Components = other.m_Components;
00634         m_Transformation = other.m_Transformation;
00635         N = other.N;
00636         M = other.M;
00637         m_refModel = other.m_refModel;
00638 
00639     return *this;
00640 }

bool Analyzer::save char *  filename  ) 
 

Write brief comment for save here.

Parameters:
filename Description of parameter filename.
Returns:
Write description of return value here.
Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for save here.

Remarks:
Write remarks for save here.
See also:
Separate items with the '|' character.

Definition at line 475 of file Analyzer.cpp.

References m_Components, m_mean, m_refModel, and model::ReferenceModel::save().

Referenced by pcggui::SaveAnalyzer().

00475                                   {
00476         ofstream saveFile(filename);
00477         if(saveFile.is_open()) {
00478                 saveFile << "Mean Dim\n";
00479                 saveFile << m_mean.Nrows() << "," << m_mean.Ncols() << "\n";
00480                 saveFile << m_mean << "\n";
00481                 saveFile << "Components Dim\n";
00482                 saveFile << m_Components.Nrows() << "," << m_Components.Ncols() << "\n";
00483                 saveFile << m_Components << "\n";
00484                 m_refModel.save(&saveFile);
00485                 saveFile.close();
00486                 return true;
00487         } else {
00488                 return false;
00489         }
00490 }

Here is the call graph for this function:

void Analyzer::selectComponents  ) 
 

Write brief comment for selectComponents here.

Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for selectComponents here.

Remarks:
Write remarks for selectComponents here.
See also:
Separate items with the '|' character.

Definition at line 333 of file Analyzer.cpp.

References m_Components, m_EigenVectors, m_TotalEnergy, and log::write().

Referenced by pcggui::Analyze(), Batch::analyzeModel(), and Batch::TestAnalyzer().

00334 {
00335         log::write("Analyzer select Components");
00336         int index = 1;
00337         float percent = 0.0;
00338 
00339         do
00340         {
00341                 percent = ((m_TotalEnergy(1,m_TotalEnergy.Ncols()) - m_TotalEnergy(1,index)) * m_TotalEnergy(1,m_TotalEnergy.Ncols()))/100.0;
00342                 log::write("Percent calc",percent);
00343                 index++;
00344         }
00345         while(percent <= 90.0 && percent > 0.0);
00346 
00347         m_Components = m_EigenVectors.Reverse().Columns(1,index-1).Reverse();
00348         log::write("Components",m_Components);
00349 }

Here is the call graph for this function:

void Analyzer::setData Matrix  data  ) 
 

Write brief comment for setData here.

Parameters:
data Description of parameter data.
Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for setData here.

Remarks:
Write remarks for setData here.
See also:
Separate items with the '|' character.

Definition at line 126 of file Analyzer.cpp.

References m_ExampleData.

00127 {
00128         m_ExampleData = data;
00129 }

void Analyzer::transformation  ) 
 

Write brief comment for transformation here.

Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for transformation here.

Remarks:
Write remarks for transformation here.
See also:
Separate items with the '|' character.

Definition at line 367 of file Analyzer.cpp.

References m_Components, m_Transformation, and log::write().

Referenced by pcggui::Analyze(), Batch::analyzeModel(), and Batch::TestAnalyzer().

00368 {
00369         log::write("Analyzer Transformation Matrix");
00370         // m_Covariance should perhaps be normalized - see wikipedia for info.
00371         m_Transformation = m_Components.t() * m_AdjustedData;
00372         log::write("Transformation",m_Transformation);
00373 }

Here is the call graph for this function:


Member Data Documentation

int model::Analyzer::M [private]
 

Definition at line 44 of file Analyzer.h.

Referenced by Analyzer(), computeEnergy(), findComponents(), mean(), mergeData(), and operator=().

Matrix model::Analyzer::m_AdjustedData [private]
 

Definition at line 37 of file Analyzer.h.

Referenced by adjust(), Analyzer(), covariance(), operator=(), and ~Analyzer().

Matrix model::Analyzer::m_Components [private]
 

Definition at line 42 of file Analyzer.h.

Referenced by Analyzer(), getInputDimension(), getModel(), load(), operator=(), save(), selectComponents(), and transformation().

Matrix model::Analyzer::m_Covariance [private]
 

Definition at line 38 of file Analyzer.h.

Referenced by Analyzer(), covariance(), operator=(), and ~Analyzer().

SymmetricMatrix model::Analyzer::m_EigenValues [private]
 

Definition at line 39 of file Analyzer.h.

Referenced by Analyzer(), computeEnergy(), findComponents(), operator=(), and ~Analyzer().

Matrix model::Analyzer::m_EigenVectors [private]
 

Definition at line 40 of file Analyzer.h.

Referenced by Analyzer(), findComponents(), operator=(), selectComponents(), and ~Analyzer().

Matrix model::Analyzer::m_ExampleData [private]
 

Definition at line 35 of file Analyzer.h.

Referenced by adjust(), Analyzer(), mean(), mergeData(), operator=(), setData(), and ~Analyzer().

Matrix model::Analyzer::m_mean [private]
 

Definition at line 36 of file Analyzer.h.

Referenced by adjust(), Analyzer(), getModel(), load(), mean(), operator=(), save(), and ~Analyzer().

ReferenceModel model::Analyzer::m_refModel [private]
 

Definition at line 45 of file Analyzer.h.

Referenced by Analyzer(), getModel(), load(), mergeData(), operator=(), and save().

Matrix model::Analyzer::m_TotalEnergy [private]
 

Definition at line 41 of file Analyzer.h.

Referenced by Analyzer(), computeEnergy(), operator=(), and selectComponents().

Matrix model::Analyzer::m_Transformation [private]
 

Definition at line 43 of file Analyzer.h.

Referenced by Analyzer(), getModel(), operator=(), and transformation().

int model::Analyzer::N [private]
 

Definition at line 44 of file Analyzer.h.

Referenced by adjust(), Analyzer(), covariance(), getModel(), mean(), mergeData(), and operator=().


The documentation for this class was generated from the following files:
Generated on Tue Apr 17 09:39:58 2007 for PCG Library by  doxygen 1.3.9.1