Changeset 285
- Timestamp:
- Apr 21, 2005, 11:47:05 PM (18 years ago)
- Location:
- trunk/test
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/Makefile.am
r284 r285 3 3 ## $Id$ 4 4 5 check_PROGRAMS =test_alignment test_averagerpair test_consensus_inputranker \5 TESTS = test_alignment test_averagerpair test_consensus_inputranker \ 6 6 test_crossvalidation \ 7 test_inputranker test_kernel test_matrix test_merge test_nni test_pca 7 test_inputranker test_kernel test_matrix test_merge test_nni test_pca \ 8 8 test_regression_linear test_regression_local test_regression_naive \ 9 9 test_rnd test_roc \ 10 10 test_statistics test_stl_utility test_svd test_svm test_vector 11 12 check_PROGRAMS = $(TESTS) 11 13 12 14 LDADD = @top_srcdir@/$(CPP_TOOLS_LIB_LOCATION)/$(CPP_TOOLS_LIB) \ … … 16 18 17 19 AM_LDFLAGS = -g 20 21 18 22 19 23 test_alignment_SOURCES = test_alignment.cc -
trunk/test/test_alignment.cc
r261 r285 82 82 83 83 if (ok) { 84 std::cout << "test_alignment: SUCCESS\n";85 84 return 0; 86 85 } 87 std::cerr << "test_alignment: FAILED\n";88 86 return -1; 89 87 -
trunk/test/test_matrix.cc
r271 r285 22 22 if (m2!=m) 23 23 ok=false; 24 std::ofstream my_out(" tmp_test_matrix.txt");24 std::ofstream my_out("data/tmp_test_matrix.txt"); 25 25 my_out << m2; 26 26 my_out.close(); 27 27 28 std::ifstream is(" tmp_test_matrix.txt");28 std::ifstream is("data/tmp_test_matrix.txt"); 29 29 matrix m3(is); 30 30 is.close(); … … 33 33 34 34 if (ok) { 35 std::cout << "test_matrix: SUCCESS\n";36 35 return 0; 37 36 } 38 std::cerr << "test_matrix: FAILED\n";39 37 return -1; 40 38 -
trunk/test/test_merge.cc
r107 r285 1 1 // $Id$ 2 2 3 #include <iostream> 3 #include "Merge.h" 4 4 5 #include <fstream> 5 6 #include <string> 6 7 7 #include "FileIO.h"8 #include "Merge.h"9 10 // class for command line options11 class Parameter {12 public:13 Parameter(const Parameter&); // not implemented14 Parameter(const int argc,const char *argv[]);15 16 inline const std::string& data(void) const { return data_file_; }17 inline const std::string& error(void) const { return error_file_; }18 inline const std::string& annots(void) const { return annots_file_; }19 20 private:21 void analyse(void);22 void defaults(void);23 24 std::string data_file_;25 std::string error_file_;26 std::string annots_file_;27 28 };29 30 Parameter::Parameter(const int argc,const char *argv[])31 {32 using namespace std;33 // check if help requested34 for (int i=1; i<argc; i++)35 if (string(argv[i])==string("-help") || string(argv[i])==string("-h")) {36 cout << "Please write some help information\n";37 exit(0); // always exit after printing help38 }39 40 defaults();41 42 for (int i=1; i<argc; i++) {43 bool ok=false;44 string myargv(argv[i]);45 if (myargv==string("-data"))46 if ((i+1)<argc) {47 data_file_=argv[++i];48 ok=true;49 }50 if (myargv==string("-error"))51 if ((i+1)<argc) {52 error_file_=argv[++i];53 ok=true;54 }55 if (myargv==string("-annots"))56 if ((i+1)<argc) {57 annots_file_=argv[++i];58 ok=true;59 }60 61 if (!ok)62 std::cerr << "# Parameter::Parameter Invalid option: "63 << argv[i] << '\n';64 }65 66 analyse();67 }68 69 void Parameter::analyse(void)70 {71 using namespace theplu::cpptools;72 bool ok=true;73 if (FileIO().access_rights(data(),"r")) {74 std::cerr << "Cannot access data file " << data() << std::endl;75 ok=false;76 }77 if (FileIO().access_rights(error(),"r")) {78 std::cerr << "Cannot access error file " << error() << std::endl;79 ok=false;80 }if (FileIO().access_rights(annots(),"r")) {81 std::cerr << "Cannot access annotation file " << annots() << std::endl;82 ok=false;83 }84 if (!ok)85 std::exit(-1);86 }87 88 void Parameter::defaults(void)89 {90 data_file_="data/merge_matrix.data";91 error_file_="data/merge_error.data";92 annots_file_="data/merge_annots.data";93 }94 8 95 9 int main(const int argc,const char* argv[]) 96 10 { 97 Parameter option(argc,argv); 98 std::ifstream data_stream(option.data().c_str()); 99 std::ifstream error_stream(option.error().c_str()); 100 std::ifstream annots_stream(option.annots().c_str()); 11 std::ifstream data_stream("data/merge_matrix.data"); 12 std::ifstream error_stream("data/merge_error.data"); 13 std::ifstream annots_stream("data/merge_annots.data"); 101 14 theplu::cpptools::Merge merge(data_stream,error_stream,annots_stream); 102 std::cout << "data matrix" << std::endl;103 std::cout << merge.data_matrix() << std::endl;104 std::cout << "error matrix" << std::endl;105 std::cout << merge.error_matrix() << std::endl;106 15 merge.do_something(); 107 std::cout << "new data matrix" << std::endl;108 std::cout << merge.data_matrix() << std::endl;109 std::cout << "new error matrix" << std::endl;110 std::cout << merge.error_matrix() << std::endl;111 16 return 0; // normal exit 112 17 } -
trunk/test/test_nni.cc
r196 r285 50 50 // hardcoded number below should be changed. 51 51 if (fabs(control(i,j))>5e-13) { 52 std::cerr << "test_nni: kNNI FAILED, cannot reproduce test result\n";52 //std::cerr << "test_nni: kNNI FAILED, cannot reproduce test result\n"; 53 53 exit(-1); // calculation result out of accepted error bounds 54 54 } 55 55 else 56 56 if (!((control(i,j)==control(i,j)))) { 57 std::cerr << "test_nni: kNNI FAILED, nan (not a number) encountered in test\n";57 //std::cerr << "test_nni: kNNI FAILED, nan (not a number) encountered in test\n"; 58 58 exit(-1); // calucaltion error detected 59 59 } … … 76 76 // hardcoded number below should be changed. 77 77 if (fabs(control(i,j))>5e-13) { 78 std::cerr << "test_nni: WeNNI FAILED, cannot reproduce test result\n";78 //std::cerr << "test_nni: WeNNI FAILED, cannot reproduce test result\n"; 79 79 exit(-1); // calculation result out of accepted error bounds 80 80 } 81 81 else 82 82 if (!((control(i,j)==control(i,j)))) { 83 std::cerr << "test_nni: WeNNI FAILED, nan (not a number) encountered in test\n";83 //std::cerr << "test_nni: WeNNI FAILED, nan (not a number) encountered in test\n"; 84 84 exit(-1); // calucaltion error detected 85 85 } 86 86 87 std::cout << "test_nni: SUCCESS, reproducing test result\n";87 //std::cout << "test_nni: SUCCESS, reproducing test result\n"; 88 88 exit(0); // normal exit 89 89 } -
trunk/test/test_pca.cc
r42 r285 1 1 // $Id$ 2 2 3 //Test program for SVD class. 3 #include "PCA.h" 4 4 5 #include <cmath> 5 6 #include <fstream> 6 7 #include <string> 7 8 #include <vector> 8 9 9 #include "PCA.h"10 10 11 using namespace std;12 11 13 template<class T> 14 void break_line( vector<T>& collector, char* p_buff, const char& delimiter ); 15 void try_peters_test_file( const string& ); 16 12 using namespace theplu; 17 13 int main() 18 14 { 19 theplu::cpptools::PCA* mypca = new theplu::cpptools::PCA;20 if( mypca->test() ) { delete mypca; return 0; }21 else { delete mypca; return -1; } 22 // try_peters_test_file( "testdatapca/nm_trn.dat");15 gslapi::matrix A( 3, 4 ); 16 for( size_t i = 0; i < 3; ++i ) 17 for( size_t j = 0; j < 4; ++j ) 18 A(i,j)= sin( static_cast<double>(i+j+2+(i+1)*(j+1)) ); 23 19 24 // return 0; 20 cpptools::PCA pca(A); 21 22 // Print only matrix that is row-centered as PCA ( process() ) 23 // will do that before calculation 24 pca.process_transposed_problem(); 25 return true; 25 26 } 26 27 27 28 // This function run PCA on testdata from peter.29 // The last column is excluded because looks suspicious30 // (only 1s and 2s e t c ). The function use get_line31 // which will limit the lengths of a line of the file32 // to MAXLINE (defined below).33 void try_peters_test_file( const string& filename )34 {35 const size_t MAXLINE = 100000;36 char* buff = new char[ MAXLINE ];37 ifstream fin( filename.c_str() );38 vector< vector<double> > data;39 40 while( fin.peek() != EOF )41 {42 fin.getline( buff, MAXLINE );43 vector<double> row;44 break_line( row, buff, ' ' );45 row.pop_back();46 data.push_back( row );47 }48 delete[] buff;49 50 const size_t cols = data.size();51 const size_t rows = data[0].size();52 53 theplu::gslapi::matrix A( cols, rows );54 55 // Copy data into matrix A56 for( size_t i = 0; i < cols; ++i )57 for( size_t j = 0; j < rows; ++j )58 A(i,j)= data[i][j];59 60 // cout << A << endl;61 62 theplu::cpptools::PCA* mypca = new theplu::cpptools::PCA( A.transpose() );63 mypca->process();64 65 66 // The following functions print the eigenvalues with the explained67 // intensity.68 cout << "Eigenvalues \t Explained intensity\n";69 for( size_t i = 0; i < 64; ++i )70 {71 printf( "%6.6f \t %6.6f \n", mypca->get_eigenvalue( i ),72 mypca->get_explained_intensity( i ) );73 // cout << mypca->get_eigenvector( i ) << endl;74 }75 delete mypca;76 }77 78 79 80 template<class T>81 void break_line( vector<T>& row, char* p_buff, const char& delimiter )82 {83 while( true )84 {85 string number = "";86 while( *p_buff++ != '\0' )87 {88 if( *p_buff == delimiter )89 {90 if( number.size() > 0 )91 {92 row.push_back( atof( number.c_str() ) );93 break;94 }95 }96 else97 {98 number += *p_buff;99 }100 }101 102 if( *p_buff == '\0' )103 {104 // Add last number105 if( number.size() > 0 )106 {107 row.push_back( atof( number.c_str() ) );108 }109 break;110 }111 }112 } -
trunk/test/test_regression_local.cc
r279 r285 6 6 #include "RegressionLinear.h" 7 7 #include "RegressionLocal.h" 8 #include "RegressionNaive.h" 8 9 #include "vector.h" 9 10 … … 11 12 // Standard includes 12 13 //////////////////// 14 #include <cmath> 13 15 #include <fstream> 14 16 #include <iostream> 15 #include < cmath>17 #include <vector> 16 18 17 19 using namespace theplu; 20 21 bool test(statistics::Regression& r, statistics::RegressionKernel& k) 22 { 23 statistics::RegressionLocal rl(r,k); 24 for (size_t i=0; i<1000; i++){ 25 double x = i; 26 double y = 10.0; 27 rl.add(x, y); 28 } 29 30 std::ofstream myout("data/tmp.txt"); 31 rl.fit(myout,0.1,1); 32 33 std::vector<double> y = rl.y(); 34 for (size_t i=0; i<y.size(); i++) 35 if (y[i]!=10.0){ 36 return false; 37 } 38 return true; 39 } 18 40 19 41 int main() … … 22 44 bool ok=true; 23 45 24 statistics::RegressionLinear r; 25 statistics::RegressionKernelBox k; 26 statistics::RegressionLocal rl(r,k); 27 for (size_t i=0; i<1000; i++){ 28 double x = static_cast<double>(i)/100; 29 double y = sin(x); 30 rl.add(x, y); 31 } 46 statistics::RegressionNaive rn; 47 statistics::RegressionKernelBox kb; 48 ok = (ok && test(rn,kb)); 32 49 33 std::string tmp = "tmp"; 34 std::ofstream myout(tmp.c_str()); 35 rl.fit(myout,0.1,1); 36 37 if (ok) { 38 std::cout << "test_regression_local: SUCCESS\n"; 50 statistics::RegressionLinear rl; 51 ok = (ok && test(rl,kb)); 52 53 54 if (ok) 39 55 return 0; 40 }41 std::cerr << "test_regression_local: FAILED\n";42 56 return -1; 43 57 } -
trunk/test/test_regression_naive.cc
r284 r285 36 36 } 37 37 38 if (ok) { 39 std::cout << "test_regression_naive: SUCCESS\n"; 38 if (ok) 40 39 return 0; 41 }42 std::cerr << "test_regression_naive: FAILED\n";43 40 return -1; 44 41 } -
trunk/test/test_rnd.cc
r42 r285 32 32 antal[ my_rnd->get_rnd_discrete() ]++; 33 33 34 for( size_t i = 0; i < 5; ++i )35 cout << i << ": " << antal[ i ] << endl;36 37 38 34 delete my_rnd; 39 35 -
trunk/test/test_roc.cc
r196 r285 18 18 using namespace std; 19 19 20 int main() 20 int main(const int argc,const char* argv[]) 21 { 22 bool print=false; 23 if (argc>1 && argv[1]==string("-p")) 24 print=true; 21 25 22 {23 26 bool ok = true; 24 27 theplu::gslapi::vector value(31); … … 31 34 double area = roc.score(target, value); 32 35 if (area!=1.0){ 33 cerr << "test_roc a: area is " << area << " should be 1.0" << endl; 36 if (print) 37 cerr << "test_roc a: area is " << area << " should be 1.0" << endl; 34 38 ok = false; 35 39 } 36 40 area = roc.score(-target, value); 37 41 if (area!=1.0){ 38 cerr << "test_roc: area is " << area << " should be 1.0" << endl; 42 if (print) 43 cerr << "test_roc: area is " << area << " should be 1.0" << endl; 39 44 ok = false; 40 45 } … … 43 48 double p_matlab = 0.00000115; 44 49 if (p/p_matlab > 1.01 | p/p_matlab < 0.99){ 45 cerr << "get_p_approx: p-value not correct" << endl; 50 if (print) 51 cerr << "get_p_approx: p-value not correct" << endl; 46 52 ok = false; 47 53 } … … 49 55 p = roc.p_value(); 50 56 if (p > pow(10, -8.0) | p < pow(10, -9.0)){ 51 cerr << "get_p_exact: p-value not correct" << endl; 57 if (print) 58 cerr << "get_p_exact: p-value not correct" << endl; 52 59 ok = false; 53 60 } … … 71 78 area = roc.score(target2,vec); 72 79 if (area<correct_area(i)-tol || area>correct_area(i)+tol){ 73 cerr << "test_roc: area is " << area << " should be " 74 << correct_area(i) << endl; 75 return -1; 80 if (print){ 81 cerr << "test_roc: area is " << area << " should be " 82 << correct_area(i) << endl; 83 } 84 ok=false; 76 85 } 77 86 } … … 82 91 area = roc.score(target2, vec, weight); 83 92 if (area<correct_area(i)-tol || area>correct_area(i)+tol){ 84 cerr << "test_roc: weighted area is " << area << " should be " 85 << correct_area(i) << endl; 86 return -1; 93 if (print){ 94 cerr << "test_roc: weighted area is " << area << " should be " 95 << correct_area(i) << endl; 96 } 97 ok=false; 87 98 } 88 99 } -
trunk/test/test_stl_utility.cc
r269 r285 43 43 ok=false; 44 44 } 45 if (ok) { 46 std::cout << "test_stl_utility: SUCCESS\n"; 45 if (ok) 47 46 return 0; 48 }49 std::cerr << "test_stl_utility: FAILED\n";50 47 return -1; 51 48 -
trunk/test/test_svm.cc
r223 r285 59 59 60 60 // testing on non solvable problem 61 cout << "testing \n";62 61 theplu::gslapi::matrix data(3,1); 63 62 data(0,0)=-1; … … 67 66 theplu::gslapi::vector target(3,1.0); 68 67 target(2)=-1; 69 std::cout << "target:\n" << target << "\n";70 68 theplu::cpptools::KernelFunction* kf = 71 69 new theplu::cpptools::PolynomialKernelFunction(); -
trunk/test/test_vector.cc
r259 r285 55 55 ok=false; 56 56 57 if (ok) { 58 std::cout << "test_vector: SUCCESS\n"; 57 if (ok) 59 58 return 0; 60 }61 std::cerr << "test_vector: FAILED\n";62 59 return -1; 63 60 }
Note: See TracChangeset
for help on using the changeset viewer.