From 943d3038553f82378567d3b651969146716e5862 Mon Sep 17 00:00:00 2001 From: westcott Date: Tue, 22 Mar 2011 12:43:51 +0000 Subject: [PATCH] working on pca --- linearalgebra.cpp | 33 +++++++++++++++++++++++++++++++++ linearalgebra.h | 1 + pcacommand.cpp | 2 +- pcacommand.h | 2 +- pcoacommand.cpp | 38 ++------------------------------------ pcoacommand.h | 1 - 6 files changed, 38 insertions(+), 39 deletions(-) diff --git a/linearalgebra.cpp b/linearalgebra.cpp index 33464ca..6970c64 100644 --- a/linearalgebra.cpp +++ b/linearalgebra.cpp @@ -53,6 +53,39 @@ vector > LinearAlgebra::matrix_mult(vector > first /*********************************************************************************************************************************/ +void LinearAlgebra::recenter(double offset, vector > D, vector >& G){ + try { + int rank = D.size(); + + vector > A(rank); + vector > C(rank); + for(int i=0;ierrorOut(e, "LinearAlgebra", "recenter"); + exit(1); + } + +} +/*********************************************************************************************************************************/ + // This function is taken from Numerical Recipes in C++ by Press et al., 2nd edition, pg. 479 int LinearAlgebra::tred2(vector >& a, vector& d, vector& e){ diff --git a/linearalgebra.h b/linearalgebra.h index e1f6f7c..3321018 100644 --- a/linearalgebra.h +++ b/linearalgebra.h @@ -20,6 +20,7 @@ public: ~LinearAlgebra() {} vector > matrix_mult(vector >, vector >); + void recenter(double, vector >, vector >&); int tred2(vector >&, vector&, vector&); int qtli(vector&, vector&, vector >&); vector< vector > calculateEuclidianDistance(vector >&, int); //pass in axes and number of dimensions diff --git a/pcacommand.cpp b/pcacommand.cpp index 3ede67a..23c066b 100644 --- a/pcacommand.cpp +++ b/pcacommand.cpp @@ -314,7 +314,7 @@ int PCACommand::process(vector& lookupFloat){ out << endl; } - //matrix = linearCalc.matrix_mult(matrix, transposeMatrix); + matrix = linearCalc.matrix_mult(matrix, transposeMatrix); out << endl << endl << "matrix mult" << endl; for (int i = 0; i < matrix.size(); i++) { diff --git a/pcacommand.h b/pcacommand.h index cf4348c..eedfcf3 100644 --- a/pcacommand.h +++ b/pcacommand.h @@ -39,7 +39,7 @@ private: map > outputTypes; LinearAlgebra linearCalc; - vector< vector > createMatrix(vector); + //vector< vector > createMatrix(vector); int process(vector&); void output(string, vector, vector >&, vector); diff --git a/pcoacommand.cpp b/pcoacommand.cpp index 4be5ffb..3cd844a 100644 --- a/pcoacommand.cpp +++ b/pcoacommand.cpp @@ -169,12 +169,12 @@ int PCOACommand::execute(){ vector d; vector e; vector > G = D; - vector > copy_G; + //vector > copy_G; m->mothurOut("\nProcessing...\n\n"); for(int count=0;count<2;count++){ - recenter(offset, D, G); if (m->control_pressed) { return 0; } + linearCalc.recenter(offset, D, G); if (m->control_pressed) { return 0; } linearCalc.tred2(G, d, e); if (m->control_pressed) { return 0; } linearCalc.qtli(d, e, G); if (m->control_pressed) { return 0; } offset = d[d.size()-1]; @@ -230,40 +230,6 @@ void PCOACommand::get_comment(istream& f, char begin, char end){ } /*********************************************************************************************************************************/ -void PCOACommand::recenter(double offset, vector > D, vector >& G){ - try { - int rank = D.size(); - - vector > A(rank); - vector > C(rank); - for(int i=0;ierrorOut(e, "PCOACommand", "recenter"); - exit(1); - } - -} - -/*********************************************************************************************************************************/ - void PCOACommand::output(string fnameRoot, vector name_list, vector >& G, vector d) { try { int rank = name_list.size(); diff --git a/pcoacommand.h b/pcoacommand.h index 02e562e..d923006 100644 --- a/pcoacommand.h +++ b/pcoacommand.h @@ -37,7 +37,6 @@ private: LinearAlgebra linearCalc; void get_comment(istream&, char, char); - void recenter(double, vector >, vector >&); void output(string, vector, vector >&, vector); }; -- 2.39.2