Changeset 513
- Timestamp:
- Feb 18, 2006, 5:02:43 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/classifier/Kernel.h
r512 r513 4 4 #define _theplu_classifier_kernel_ 5 5 6 #include <c++_tools/gslapi/matrix.h> 7 6 8 #include <cctype> 7 9 8 10 namespace theplu { 9 10 namespace gslapi {11 class matrix;12 }13 14 11 namespace classifier { 15 12 … … 33 30 34 31 /// 35 /// Default constructor36 ///37 //Kernel(void) {};38 39 ///40 /// Copy constructor (not implemented)41 ///42 Kernel(const Kernel&);43 44 ///45 32 /// Constructor taking the data matrix and KernelFunction as 46 33 /// input.Each column in the data matrix corresponds to one 47 /// sample. @note Can not handle NaNs. 34 /// sample. 35 /// 36 /// @note Can not handle NaNs. 48 37 /// 49 38 Kernel(const gslapi::matrix& data, const KernelFunction& kf) 50 39 : data_(data), kf_(&kf) {}; 51 40 41 /// 42 /// Constructor using weights 43 /// 44 Kernel(const gslapi::matrix& data, const KernelFunction& kf, 45 const gslapi::matrix& weights) 46 : data_(data), kf_(&kf) {}; 47 52 48 /// 53 49 /// Destructor … … 64 60 /// @brief number of samples 65 61 /// 66 virtual size_t size(void) const=0;67 62 inline size_t size(void) const { return data_.columns(); } 63 68 64 protected: 69 65 const gslapi::matrix& data_; 70 66 const KernelFunction* kf_; 67 68 private: 69 /// 70 /// Copy constructor (not implemented) 71 /// 72 Kernel(const Kernel&); 73 71 74 72 75 }; // class Kernel -
trunk/lib/classifier/Kernel_MEV.h
r512 r513 37 37 38 38 /// 39 /// @todoConstructor taking the \a data matrix, the KernelFunction and a39 /// Constructor taking the \a data matrix, the KernelFunction and a 40 40 /// \a weight matrix as input. Each column in the data matrix 41 41 /// corresponds to one sample. 42 Kernel_MEV(const gslapi::matrix& data, const KernelFunction&, 43 const gslapi::matrix& weight); 44 45 /// 46 /// Copy constructor (not implemented) 47 /// 48 Kernel_MEV(const Kernel_MEV&); 42 inline Kernel_MEV(const gslapi::matrix& data, const KernelFunction& kf, 43 const gslapi::matrix& weight) 44 : Kernel(data,kf,weight) {} 49 45 50 46 /// … … 61 57 gslapi::vector(data_,column,false)); } 62 58 59 private: 63 60 /// 64 /// @brief number of samples61 /// Copy constructor (not implemented) 65 62 /// 66 inline size_t size(void) const { return data_.columns(); } 67 68 private: 63 Kernel_MEV(const Kernel_MEV&); 69 64 70 65 }; // class Kernel_MEV -
trunk/lib/classifier/Kernel_SEV.h
r512 r513 57 57 { return kernel_matrix_(row,column); } 58 58 59 ///60 /// @brief number of samples61 ///62 inline size_t size(void) const { return kernel_matrix_.columns(); }63 64 59 private: 65 60 gslapi::matrix kernel_matrix_; -
trunk/lib/classifier/Makefile.am
r507 r513 16 16 GaussianKernelFunction.cc \ 17 17 InputRanker.cc \ 18 Kernel_MEV.cc \19 18 Kernel_SEV.cc \ 20 19 KernelLookup.cc \ 21 20 MatrixLookup.cc \ 21 KernelWeighted_SEV.cc \ 22 22 NCC.cc \ 23 23 PolynomialKernelFunction.cc \ … … 42 42 Kernel_SEV.h \ 43 43 KernelLookup.h \ 44 KernelWeighted_MEV.h \ 45 KernelWeighted_SEV.h \ 44 46 MatrixLookup.h \ 45 47 NCC.h \ -
trunk/test/kernel_test.cc
r482 r513 12 12 #include <c++_tools/classifier/Kernel_MEV.h> 13 13 #include <c++_tools/classifier/Kernel_SEV.h> 14 #include <c++_tools/classifier/KernelWeighted_MEV.h> 15 #include <c++_tools/classifier/KernelWeighted_SEV.h> 14 16 15 17 #include <cmath> … … 23 25 bool test_MEV(const gslapi::matrix& data, const classifier::KernelFunction* kf, 24 26 const gslapi::matrix& control, const double error_bound, 25 std::ostream* error) 26 { 27 classifier::Kernel_MEV kernel(data,*kf); 28 for(u_int i=0;i<control.rows();i++) 29 for(u_int j=0;j<control.columns();j++) 30 if (fabs(kernel(i,j)-control(i,j))>error_bound) 31 return false; 32 33 // checking view 34 std::vector<size_t> index(3); 35 index[0]=1; 36 index[1]=2; 37 index[2]=3; 38 classifier::KernelLookup kv_raw(kernel); 39 classifier::KernelLookup kv(kv_raw,index,index); 40 if (kv.rows()!=index.size()){ 41 *error << "Error: KernelLookup(kernel, index)\n" << std::endl 42 << "Size of KernelLookup is " << kv.rows() << std::endl 43 << "expected " << index.size() << std::endl; 44 45 return false; 46 } 47 classifier::KernelLookup kv2(kernel); 48 if (kv2.rows()!=kernel.size()){ 49 *error << "Error: KernelLookup(kernel)\n" << std::endl 50 << "Size of KernelLookup is " << kv.rows() << std::endl 51 << "expected " << kernel.size() << std::endl; 52 53 return false; 54 } 55 56 return true; 57 } 27 std::ostream* error); 58 28 59 29 bool test_SEV(const gslapi::matrix& data, const classifier::KernelFunction* kf, 60 30 const gslapi::matrix& control, const double error_bound, 61 std::ostream* error) 62 { 63 classifier::Kernel_SEV kernel(data,*kf); 64 for(u_int i=0;i<control.rows();i++) 65 for(u_int j=0;j<control.columns();j++) 66 if (fabs(kernel(i,j)-control(i,j))>error_bound) 67 return false; 68 69 // checking view 70 std::vector<size_t> index(3); 71 index[0]=1; 72 index[1]=2; 73 index[2]=3; 74 classifier::KernelLookup kv(classifier::KernelLookup(kernel),index, index); 75 if (kv.rows()!=index.size()){ 76 *error << "Error: KernelLookup(kernel, index)\n" << std::endl 77 << "Size of KernelLookup is " << kv.rows() << std::endl 78 << "expected " << index.size() << std::endl; 79 80 return false; 81 } 82 classifier::KernelLookup kv2(kernel); 83 if (kv2.rows()!=kernel.size()){ 84 *error << "Error: KernelLookup(kernel)\n" << std::endl 85 << "Size of KernelLookup is " << kv.rows() << std::endl 86 << "expected " << kernel.size() << std::endl; 87 88 return false; 89 } 90 return true; 91 } 31 std::ostream* error); 92 32 93 33 … … 142 82 return -1; 143 83 } 84 85 bool test_MEV(const gslapi::matrix& data, const classifier::KernelFunction* kf, 86 const gslapi::matrix& control, const double error_bound, 87 std::ostream* error) 88 { 89 // at least testing constructors 90 classifier::KernelWeighted_MEV kernel_weighted(data,*kf,data); 91 92 classifier::Kernel_MEV kernel(data,*kf); 93 for(u_int i=0;i<control.rows();i++) 94 for(u_int j=0;j<control.columns();j++) 95 if (fabs(kernel(i,j)-control(i,j))>error_bound) 96 return false; 97 98 // checking view 99 std::vector<size_t> index(3); 100 index[0]=1; 101 index[1]=2; 102 index[2]=3; 103 classifier::KernelLookup kv_raw(kernel); 104 classifier::KernelLookup kv(kv_raw,index,index); 105 if (kv.rows()!=index.size()){ 106 *error << "Error: KernelLookup(kernel, index)\n" << std::endl 107 << "Size of KernelLookup is " << kv.rows() << std::endl 108 << "expected " << index.size() << std::endl; 109 110 return false; 111 } 112 classifier::KernelLookup kv2(kernel); 113 if (kv2.rows()!=kernel.size()){ 114 *error << "Error: KernelLookup(kernel)\n" << std::endl 115 << "Size of KernelLookup is " << kv.rows() << std::endl 116 << "expected " << kernel.size() << std::endl; 117 118 return false; 119 } 120 121 return true; 122 } 123 124 bool test_SEV(const gslapi::matrix& data, const classifier::KernelFunction* kf, 125 const gslapi::matrix& control, const double error_bound, 126 std::ostream* error) 127 { 128 // at least testing constructors 129 classifier::KernelWeighted_MEV kernel_weighted(data,*kf,data); 130 131 classifier::Kernel_SEV kernel(data,*kf); 132 for(u_int i=0;i<control.rows();i++) 133 for(u_int j=0;j<control.columns();j++) 134 if (fabs(kernel(i,j)-control(i,j))>error_bound) 135 return false; 136 137 // checking view 138 std::vector<size_t> index(3); 139 index[0]=1; 140 index[1]=2; 141 index[2]=3; 142 classifier::KernelLookup kv(classifier::KernelLookup(kernel),index, index); 143 if (kv.rows()!=index.size()){ 144 *error << "Error: KernelLookup(kernel, index)\n" << std::endl 145 << "Size of KernelLookup is " << kv.rows() << std::endl 146 << "expected " << index.size() << std::endl; 147 148 return false; 149 } 150 classifier::KernelLookup kv2(kernel); 151 if (kv2.rows()!=kernel.size()){ 152 *error << "Error: KernelLookup(kernel)\n" << std::endl 153 << "Size of KernelLookup is " << kv.rows() << std::endl 154 << "expected " << kernel.size() << std::endl; 155 156 return false; 157 } 158 return true; 159 } 160 161
Note: See TracChangeset
for help on using the changeset viewer.