Changeset 14 for trunk/src/PCA.cc
 Timestamp:
 Jun 25, 2003, 10:56:33 AM (19 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/PCA.cc
r13 r14 93 93 { 94 94 centered[ i ] = temp.get( i, 0 )  meanvalues_[ i ]; 95 //cout << temp.get( i, 0 ) << " " << meanvalues_[ i ] << " " << centered[ i ] << endl; 95 96 } 96 97 97 98 thep_gsl_api::vector proj( eigenvectors_ * centered ); 98 for( size_t i = 0; i < samples.cols(); ++i )99 for( size_t i = 0; i < Ncol; ++i ) 99 100 { 100 101 projs.set( i, j, proj[ i ] ); … … 136 137 { 137 138 cout << "1. Print original matrix A = \n";//Testing rowcentering of matrix\n"; 138 thep_gsl_api::matrix A( 3, 3 );139 for( size_t i = 0; i < 3; ++i )139 thep_gsl_api::matrix A( 4, 3 ); 140 for( size_t i = 0; i < 4; ++i ) 140 141 { 141 142 for( size_t j = 0; j < 3; ++j ) … … 163 164 // The eigenvalues and eigenvectors are 164 165 // from matlab using eig(A'A)/3 165 double answer_lambda[ 3 ] = { 1.8908, 0.0327, 0 };166 double answer_eigenvec[ 3 ][ 3 ] =167 {168 { 0.4763, 0.6738, 0.5649 },169 { 0.8770, 0.3182, 0.3599 },170 { 0.0627, 0.6669 , 0.7425 },171 };172 173 double ERROR_TOL = 0.0001;174 175 // error eigenvalues176 cout << "abs( lambda(i)  lambda_matlab(i) ) ) = \n( ";177 double max_err = 0;178 for( size_t i = 0; i < 3; ++i )179 {180 double err = fabs( eigenvalues_[ i ]  answer_lambda[ i ] );181 if( err > max_err ) max_err = err;182 cout << err << " ";183 }184 cout << ")\n";185 186 cerr << "max_error = " << max_err << ", to be compared with ERROR_TOL = "187 << ERROR_TOL << endl;188 if( max_err < ERROR_TOL )189 {190 cout << "ok, compared with precision in given matlabreferences!\n";191 }192 else193 {194 cerr << "Not ok, error to big!\n";195 return false;196 }197 198 // error eigenvectors199 max_err = 0;200 for( size_t i = 0; i < 3; ++i )201 {202 cout << "err_eigvec( " << i << " ) = \n";203 for( size_t j = 0; j < 3; ++j )204 {205 double err = fabs( fabs( eigenvectors_.get( i, j ) )  fabs( answer_eigenvec[ i ][ j ] ) );206 if( err > max_err ) max_err = err;207 cout << err << endl;208 }209 cout << ")\n\n";210 }211 212 cerr << "max_error = " << max_err << ", to be compared with ERROR_TOL = "213 << ERROR_TOL << endl;214 if( max_err < ERROR_TOL )215 {216 cout << "ok, compared with precision in given matlabreferences!\n";217 }218 else219 {220 cerr << "Not ok, error to big!\n";221 return false;222 }166 // double answer_lambda[ 3 ] = { 1.8908, 0.0327, 0 }; 167 // double answer_eigenvec[ 3 ][ 3 ] = 168 // { 169 // { 0.4763, 0.6738, 0.5649 }, 170 // { 0.8770, 0.3182, 0.3599 }, 171 // { 0.0627, 0.6669 , 0.7425 }, 172 // }; 173 174 // double ERROR_TOL = 0.0001; 175 176 // // error eigenvalues 177 // cout << "abs( lambda(i)  lambda_matlab(i) ) ) = \n( "; 178 // double max_err = 0; 179 // for( size_t i = 0; i < 3; ++i ) 180 // { 181 // double err = fabs( eigenvalues_[ i ]  answer_lambda[ i ] ); 182 // if( err > max_err ) max_err = err; 183 // cout << err << " "; 184 // } 185 // cout << ")\n"; 186 187 // cerr << "max_error = " << max_err << ", to be compared with ERROR_TOL = " 188 // << ERROR_TOL << endl; 189 // if( max_err < ERROR_TOL ) 190 // { 191 // cout << "ok, compared with precision in given matlabreferences!\n"; 192 // } 193 // else 194 // { 195 // cerr << "Not ok, error to big!\n"; 196 // return false; 197 // } 198 199 // // error eigenvectors 200 // max_err = 0; 201 // for( size_t i = 0; i < 3; ++i ) 202 // { 203 // cout << "err_eigvec( " << i << " ) = \n"; 204 // for( size_t j = 0; j < 3; ++j ) 205 // { 206 // double err = fabs( fabs( eigenvectors_.get( i, j ) )  fabs( answer_eigenvec[ i ][ j ] ) ); 207 // if( err > max_err ) max_err = err; 208 // cout << err << endl; 209 // } 210 // cout << ")\n\n"; 211 // } 212 213 // cerr << "max_error = " << max_err << ", to be compared with ERROR_TOL = " 214 // << ERROR_TOL << endl; 215 // if( max_err < ERROR_TOL ) 216 // { 217 // cout << "ok, compared with precision in given matlabreferences!\n"; 218 // } 219 // else 220 // { 221 // cerr << "Not ok, error to big!\n"; 222 // return false; 223 // } 223 224 224 225 cout << "\nThe following projection is obtained:\n"; 225 cout << this>projection( A ) << endl;226 226 cout << this>projection( A_ ) << endl; 227 227 228 228 229 return true;
Note: See TracChangeset
for help on using the changeset viewer.