Changeset 527
- Timestamp:
- Mar 1, 2006, 12:23:53 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/classifier/DataLookup1D.cc
r505 r527 17 17 } 18 18 19 double DataLookup1D::operator*(const DataLookup1D& other) const 20 { 21 assert(other.size()==size()); 22 double res=0; 23 for (size_t i = 0; i<size(); i++) 24 res += (*this)(i)*other(i); 25 return res; 26 } 27 28 std::ostream& operator<< (std::ostream& os, const DataLookup1D& x) 29 { 30 os.setf(std::ios::dec); 31 os.precision(12); 32 for (size_t i = 0; i < x.size(); ++i) { 33 os << x(i); 34 if ( (i+1)<x.size() ) 35 os << " "; 36 } 37 return os; 38 } 19 39 }} // of namespace classifier and namespace theplu -
trunk/lib/classifier/DataLookup1D.h
r505 r527 7 7 8 8 #include <cassert> 9 #include <iostream> 9 10 #include <vector> 10 11 … … 27 28 /// 28 29 DataLookup1D(const DataLookup2D&, const size_t, 29 const bool column_vector=true);30 const bool row_vector=true); 30 31 31 32 /// … … 38 39 /// 39 40 inline size_t size(void) const 40 { return column_vector_ ? matrix_-> rows() : matrix_->columns(); }41 { return column_vector_ ? matrix_->columns() : matrix_->rows(); } 41 42 42 43 /// … … 45 46 inline double operator()(const size_t i) const 46 47 { assert(i<size()); 47 return column_vector_ ? (*matrix_)(i,index_) : (*matrix_)(index_,i); } 48 return column_vector_ ? (*matrix_)(index_,i) : (*matrix_)(i,index_); } 49 50 /// 51 /// scalar product 52 /// 53 double operator*(const DataLookup1D&) const; 48 54 49 55 private: … … 55 61 56 62 }; 63 /// 64 /// The output operator DataLook1D 65 /// 66 /// @todo test that output can be used from gslapi::vector istream constructor 67 std::ostream& operator<< (std::ostream& s, const DataLookup1D&); 57 68 58 69 }} // of namespace classifier and namespace theplu -
trunk/lib/classifier/GaussianKernelFunction.cc
r451 r527 4 4 5 5 #include <c++_tools/classifier/KernelFunction.h> 6 #include <c++_tools/classifier/DataLookup1D.h> 6 7 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/gslapi/vector.h> 8 8 9 9 10 #include <math.h> … … 12 13 namespace classifier { 13 14 14 GaussianKernelFunction::GaussianKernelFunction(double sigma)15 : KernelFunction(), sigma_(sigma)16 {17 }15 GaussianKernelFunction::GaussianKernelFunction(double sigma) 16 : KernelFunction(), sigma2_(sigma*sigma) 17 { 18 } 18 19 19 double GaussianKernelFunction::operator()(const gslapi::vector& a1,20 const gslapi::vector& a2,21 const gslapi::vector& w1,22 const gslapi::vector& w2) const23 { 24 double distance = 0;25 double normalization_factor = 0;26 for (size_t i=0; i<a1.size(); i++) { 27 distance += w1(i) * w2(i) * (a1(i)-a2(i)) * (a1(i)-a2(i));28 normalization_factor += w1(i) * w2(i);20 double GaussianKernelFunction::operator()(const DataLookup1D& x, 21 const DataLookup1D& y) const 22 { 23 assert(x.size()==y.size()); 24 double d2 = 0; 25 for (size_t i=0; i<x.size(); i++){ 26 double d = x(i)-y(i); 27 d2 += d*d; 28 } 29 return exp(-d2/sigma2_); 29 30 } 30 // to make it coherent with no weight case31 normalization_factor /= a1.size();32 return exp(distance/normalization_factor/pow(sigma_,2));33 }34 31 32 double GaussianKernelFunction::operator()(const DataLookup1D& a1, 33 const DataLookup1D& a2, 34 const DataLookup1D& w1, 35 const DataLookup1D& w2) const 36 { 37 assert(a1.size()==a2.size()); 38 assert(w1.size()==w2.size()); 39 assert(a1.size()==w1.size()); 40 double d2 = 0; 41 double normalization_factor = 0; 42 for (size_t i=0; i<a1.size(); i++) { 43 // ignoring Nan with accompanied weight zero 44 if (w1(i) && w2(i)){ 45 d2 += w1(i) * w2(i) * (a1(i)-a2(i)) * (a1(i)-a2(i)); 46 normalization_factor += w1(i) * w2(i); 47 } 48 } 49 // to make it coherent with no weight case 50 normalization_factor /= a1.size(); 51 return exp(d2/normalization_factor/sigma2_); 52 } 53 35 54 36 55 -
trunk/lib/classifier/GaussianKernelFunction.h
r451 r527 6 6 #include <c++_tools/gslapi/vector.h> 7 7 #include <c++_tools/classifier/KernelFunction.h> 8 #include <c++_tools/classifier/DataLookup1D.h> 8 9 9 10 #include <cmath> 10 11 11 12 namespace theplu { 12 class gslapi::vector;13 14 13 namespace classifier { 15 14 … … 37 36 /// Gaussian kernel. @return \f$ exp((x - y)^{2}/\sigma^2) \f$ \n 38 37 /// 39 inline double operator()(const gslapi::vector& a1, 40 const gslapi::vector& a2) const 41 { gslapi::vector a(a1); return exp(-((a-=a2)*a)/(sigma_*sigma_)); } 38 double operator()(const DataLookup1D& a1, 39 const DataLookup1D& a2) const; 42 40 43 41 /// … … 45 43 ///Gaussian kernel with weights. 46 44 /// 47 double operator()(const gslapi::vector& a1,48 const gslapi::vector& a2,49 const gslapi::vector& w1,50 const gslapi::vector& w2) const;45 double operator()(const DataLookup1D& a1, 46 const DataLookup1D& a2, 47 const DataLookup1D& w1, 48 const DataLookup1D& w2) const; 51 49 52 50 private: 53 double sigma _;51 double sigma2_; 54 52 55 53 }; // class GaussianKernelFunction -
trunk/lib/classifier/InputRanker.cc
r482 r527 28 28 std::vector<std::pair<double, size_t> > score; 29 29 for (size_t i=0; i<nof_genes; i++) { 30 DataLookup1D vector_value(data,i,false); 31 double area = score_object.score(target,vector_value); 32 //double area = score_object.score(target,DataLookup1D(data,i,false)); 30 double area = score_object.score(target,DataLookup1D(data,i,true)); 31 // Peter, remove stupid tmp 33 32 std::pair<double, size_t> tmp(area,i); 34 33 score.push_back(tmp); … … 58 57 std::vector<std::pair<double, size_t> > score; 59 58 for (size_t i=0; i<nof_genes; i++) { 60 double area = score_object.score(target, DataLookup1D(data,i, false),61 DataLookup1D(weight,i, false));59 double area = score_object.score(target, DataLookup1D(data,i,true), 60 DataLookup1D(weight,i,true)); 62 61 std::pair<double, size_t> tmp(area,i); 63 62 score.push_back(tmp); -
trunk/lib/classifier/Kernel.h
r523 r527 7 7 #include <c++_tools/gslapi/vector.h> 8 8 #include <c++_tools/classifier/KernelFunction.h> 9 #include <c++_tools/classifier/MatrixLookup.h> 9 10 10 11 #include <cctype> … … 36 37 /// @note Can not handle NaNs. 37 38 /// 38 Kernel(const gslapi::matrix& data, const KernelFunction& kf)39 Kernel(const MatrixLookup& data, const KernelFunction& kf) 39 40 : data_(data), kf_(&kf) {}; 40 41 41 ///42 /// Constructor using weights43 ///44 Kernel(const gslapi::matrix& data, const KernelFunction& kf,45 const gslapi::matrix& weights)46 : data_(data), kf_(&kf) {};47 48 42 /// 49 43 /// Destructor … … 55 49 /// matrix 56 50 /// 57 virtual double operator()(const size_t row, const size_t column) const=0;51 virtual double operator()(const size_t row, const size_t column) const=0; 58 52 59 53 /// … … 63 57 64 58 65 virtual double element(const gslapi::vector& vec, const size_t i) const=0;59 //virtual double element(const gslapi::vector& vec, const size_t i) const=0; 66 60 67 61 protected: 68 const gslapi::matrix& data_; 62 // Peter should be a copy 63 const MatrixLookup& data_; 69 64 const KernelFunction* kf_; 70 65 -
trunk/lib/classifier/KernelFunction.h
r451 r527 5 5 6 6 namespace theplu { 7 8 namespace gslapi {9 class vector;10 class matrix;11 }12 13 7 namespace classifier { 8 class DataLookup1D; 14 9 15 10 /// … … 33 28 /// @return scalar product of two vector in feature space. 34 29 /// 35 virtual double operator()(const gslapi::vector&,36 const gslapi::vector&) const = 0;30 virtual double operator()(const DataLookup1D&, 31 const DataLookup1D&) const = 0; 37 32 38 33 /// 39 34 /// @return scalar product of two vector in feature space. 40 35 /// 41 virtual double operator()(const gslapi::vector&,42 const gslapi::vector&,43 const gslapi::vector&,44 const gslapi::vector&) const = 0;36 virtual double operator()(const DataLookup1D&, 37 const DataLookup1D&, 38 const DataLookup1D&, 39 const DataLookup1D&) const = 0; 45 40 46 41 }; // class KernelFunction -
trunk/lib/classifier/KernelLookup.h
r523 r527 84 84 { return (*kernel_)(row_index_[row],column_index_[column]); } 85 85 86 inline double element(const gslapi::vector& vec, const size_t i) const87 { return kernel_->element(vec, row_index_[i]); }86 //inline double element(const gslapi::vector& vec, const size_t i) const 87 //{ return kernel_->element(vec, row_index_[i]); } 88 88 89 89 private: -
trunk/lib/classifier/KernelWeighted_MEV.h
r523 r527 5 5 6 6 #include <c++_tools/classifier/Kernel.h> 7 8 #include <c++_tools/classifier/DataLookup1D.h> 7 9 #include <c++_tools/classifier/KernelFunction.h> 8 #include <c++_tools/ gslapi/vector.h>9 #include <c++_tools/gslapi/matrix.h>10 #include <c++_tools/classifier/MatrixLookup.h> 11 //#include <c++_tools/gslapi/matrix.h> 10 12 11 13 namespace theplu { … … 36 38 /// behaviour of the object is undefined 37 39 /// 38 inline KernelWeighted_MEV(const gslapi::matrix& data,40 inline KernelWeighted_MEV(const MatrixLookup& data, 39 41 const KernelFunction& kf, 40 const gslapi::matrix& weights)42 const MatrixLookup& weights) 41 43 : Kernel(data,kf), weights_(weights) {} 42 44 … … 45 47 /// matrix 46 48 /// 47 inline double operator()(const size_t row, const size_t column) const 48 { return (*kf_)(gslapi::vector(data_,row,false), 49 gslapi::vector(data_,column,false), 50 gslapi::vector(weights_,row,false), 51 gslapi::vector(weights_,column,false)); } 49 double operator()(const size_t row, const size_t column) const; 52 50 53 51 /// 54 52 /// @return kernel element between data @a ve and training sample @a i 55 53 /// 56 inline double element(const gslapi::vector& vec, const size_t i) const57 {58 return (*kf_)(vec, gslapi::vector(data_,i),59 gslapi::vector(vec.size(),1.0),60 gslapi::vector(weights_,i));61 }54 //inline double element(const gslapi::vector& vec, const size_t i) const 55 //{ 56 // return (*kf_)(vec, gslapi::vector(data_,i), 57 // gslapi::vector(vec.size(),1.0), 58 // gslapi::vector(weights_,i)); 59 //} 62 60 63 61 private: … … 67 65 KernelWeighted_MEV(const KernelWeighted_MEV&); 68 66 69 const gslapi::matrix& weights_;67 const MatrixLookup& weights_; 70 68 71 69 }; -
trunk/lib/classifier/KernelWeighted_SEV.cc
r513 r527 3 3 #include <c++_tools/classifier/KernelWeighted_SEV.h> 4 4 5 #include <c++_tools/classifier/DataLookup1D.h> 5 6 #include <c++_tools/classifier/Kernel.h> 6 7 #include <c++_tools/classifier/KernelFunction.h> 8 #include <c++_tools/classifier/MatrixLookup.h> 7 9 #include <c++_tools/gslapi/matrix.h> 8 10 #include <c++_tools/gslapi/vector.h> … … 12 14 13 15 14 KernelWeighted_SEV::KernelWeighted_SEV(const gslapi::matrix& data,16 KernelWeighted_SEV::KernelWeighted_SEV(const MatrixLookup& data, 15 17 const KernelFunction& kf, 16 const gslapi::matrix& weights)18 const MatrixLookup& weights) 17 19 : Kernel(data,kf), weights_(weights) 18 20 { … … 21 23 for (size_t j=i; j<kernel_matrix_.columns(); j++) 22 24 kernel_matrix_(i,j) = kernel_matrix_(j,i) = 23 (*kf_)(gslapi::vector(data_,i,false),gslapi::vector(data_,j,false), 24 gslapi::vector(weights_,i,false), 25 gslapi::vector(weights_,j,false)); 25 (*kf_)(DataLookup1D(data_,i,false), 26 DataLookup1D(data_,j,false), 27 DataLookup1D(weights_,i,false), 28 DataLookup1D(weights_,j,false)); 26 29 } 27 30 -
trunk/lib/classifier/KernelWeighted_SEV.h
r523 r527 4 4 #define _theplu_classifier_kernel_weighted_sev_ 5 5 6 #include <c++_tools/classifier/DataLookup1D.h> 6 7 #include <c++_tools/classifier/Kernel.h> 8 #include <c++_tools/classifier/MatrixLookup.h> 7 9 #include <c++_tools/gslapi/matrix.h> 8 10 #include <c++_tools/gslapi/vector.h> … … 38 40 /// behaviour of the object is undefined 39 41 /// 40 KernelWeighted_SEV(const gslapi::matrix& data, const KernelFunction& kf,41 const gslapi::matrix& weights);42 KernelWeighted_SEV(const MatrixLookup& data, const KernelFunction& kf, 43 const MatrixLookup& weights); 42 44 43 45 … … 52 54 /// @return kernel element between data @a ve and training sample @a i 53 55 /// 54 inline double element(const gslapi::vector& vec, const size_t i) const55 {56 return (*kf_)(vec, gslapi::vector(data_,i),57 gslapi::vector(vec.size(),1.0),58 gslapi::vector(weights_,i));59 }56 //inline double element(const DataLookup1D& vec, const size_t i) const 57 //{ 58 // return (*kf_)(vec, DataLookup1D(data_,i), 59 // DataLookup1D(vec.size(),1.0), 60 // DataLookup1D(weights_,i)); 61 //} 60 62 61 63 … … 65 67 66 68 gslapi::matrix kernel_matrix_; 67 const gslapi::matrix& weights_;69 const MatrixLookup& weights_; 68 70 69 71 }; // class Kernel_SEV -
trunk/lib/classifier/Kernel_MEV.h
r523 r527 4 4 #define _theplu_classifier_kernel_mev_ 5 5 6 #include <c++_tools/classifier/DataLookup1D.h> 6 7 #include <c++_tools/classifier/Kernel.h> 7 8 #include <c++_tools/classifier/KernelFunction.h> … … 33 34 /// sample. @note Can not handle NaNs. 34 35 /// 35 inline Kernel_MEV(const gslapi::matrix& data, const KernelFunction& kf)36 inline Kernel_MEV(const MatrixLookup& data, const KernelFunction& kf) 36 37 : Kernel(data,kf) {} 37 38 ///39 /// Constructor taking the \a data matrix, the KernelFunction and a40 /// \a weight matrix as input. Each column in the data matrix41 /// corresponds to one sample.42 inline Kernel_MEV(const gslapi::matrix& data, const KernelFunction& kf,43 const gslapi::matrix& weight)44 : Kernel(data,kf,weight) {}45 38 46 39 /// … … 53 46 /// matrix 54 47 /// 55 inline double operator()(const size_t row, const size_t column) const 56 { return (*kf_)(gslapi::vector(data_,row,false), 57 gslapi::vector(data_,column,false)); } 58 48 double operator()(const size_t row, const size_t column) const; 49 59 50 /// 60 51 /// @return kernel element between data @a ve and training sample @a i 61 52 /// 62 inline double element(const gslapi::vector& vec, const size_t i) const63 { return kf_->operator()(vec, gslapi::vector(data_,i)); }53 //inline double element(const gslapi::vector& vec, const size_t i) const 54 //{ return kf_->operator()(vec, gslapi::vector(data_,i)); } 64 55 65 56 -
trunk/lib/classifier/Kernel_SEV.cc
r523 r527 3 3 #include <c++_tools/classifier/Kernel_SEV.h> 4 4 5 #include <c++_tools/classifier/DataLookup1D.h> 5 6 #include <c++_tools/classifier/Kernel.h> 6 7 #include <c++_tools/classifier/KernelFunction.h> 8 #include <c++_tools/classifier/MatrixLookup.h> 7 9 #include <c++_tools/gslapi/matrix.h> 8 10 #include <c++_tools/gslapi/vector.h> … … 12 14 13 15 14 Kernel_SEV::Kernel_SEV(const gslapi::matrix& data, const KernelFunction& kf)16 Kernel_SEV::Kernel_SEV(const MatrixLookup& data, const KernelFunction& kf) 15 17 : Kernel(data,kf) 16 18 { 17 19 kernel_matrix_ = gslapi::matrix(data.columns(),data.columns()); 18 20 for (size_t i=0; i<kernel_matrix_.rows(); i++) 19 for (size_t j=i; j<kernel_matrix_.columns(); j++) 21 for (size_t j=i; j<kernel_matrix_.columns(); j++) 20 22 kernel_matrix_(i,j) = kernel_matrix_(j,i) = 21 (*kf_)( gslapi::vector(data_,i,false),gslapi::vector(data_,j,false));23 (*kf_)(DataLookup1D(data_,i,false),DataLookup1D(data_,j,false)); 22 24 } 23 24 double Kernel_SEV::element(const gslapi::vector& vec, const size_t i) const 25 double Kernel_SEV::element(const DataLookup1D& vec, const size_t i) const 25 26 { 26 return kf_->operator()(vec, gslapi::vector(data_,i));27 return kf_->operator()(vec, DataLookup1D(data_,i)); 27 28 } 28 29 -
trunk/lib/classifier/Kernel_SEV.h
r523 r527 11 11 namespace classifier { 12 12 13 class DataLookup1D; 13 14 class KernelFunction; 14 15 … … 38 39 /// input. @note Can not handle NaNs. When dealing with missing values, 39 40 /// use constructor taking a weight matrix. 40 Kernel_SEV(const gslapi::matrix&, const KernelFunction&);41 Kernel_SEV(const MatrixLookup&, const KernelFunction&); 41 42 42 43 /// … … 60 61 /// @return kernel element between data @a ve and training sample @a i 61 62 /// 62 double element(const gslapi::vector& vec, const size_t i) const;63 double element(const DataLookup1D& vec, const size_t i) const; 63 64 64 65 -
trunk/lib/classifier/Makefile.am
r513 r527 16 16 GaussianKernelFunction.cc \ 17 17 InputRanker.cc \ 18 Kernel_MEV.cc \ 18 19 Kernel_SEV.cc \ 19 20 KernelLookup.cc \ 21 KernelWeighted_MEV.cc \ 22 KernelWeighted_SEV.cc \ 20 23 MatrixLookup.cc \ 21 KernelWeighted_SEV.cc \22 24 NCC.cc \ 23 25 PolynomialKernelFunction.cc \ -
trunk/lib/classifier/MatrixLookup.h
r482 r527 26 26 /// Constructor 27 27 /// 28 MatrixLookup(const gslapi::matrix&);28 explicit MatrixLookup(const gslapi::matrix&); 29 29 30 30 /// -
trunk/lib/classifier/NCC.cc
r526 r527 119 119 prediction=gslapi::matrix(centroids_.columns(), input.columns()); 120 120 for(size_t j=0; j<input.columns();j++) { 121 DataLookup1D in(input,j, true);121 DataLookup1D in(input,j,false); 122 122 gslapi::vector out; 123 123 predict(in,out); -
trunk/lib/classifier/PolynomialKernelFunction.cc
r524 r527 3 3 4 4 #include <c++_tools/classifier/PolynomialKernelFunction.h> 5 #include <c++_tools/classifier/DataLookup1D.h> 5 6 6 7 #include <c++_tools/gslapi/matrix.h> … … 19 20 } 20 21 21 double PolynomialKernelFunction::operator()(const gslapi::vector& a1,22 const gslapi::vector& a2,23 const gslapi::vector& w1,24 const gslapi::vector& w2) const22 double PolynomialKernelFunction::operator()(const DataLookup1D& a1, 23 const DataLookup1D& a2, 24 const DataLookup1D& w1, 25 const DataLookup1D& w2) const 25 26 { 26 27 statistics::AveragerPairWeighted averager; 27 averager.add(a1,a2,w1,w2); 28 for (size_t i=0; i<a1.size(); i++) 29 averager.add(a1(i),a2(i),w1(i),w2(i)); 28 30 29 31 // a1.size() term to make it coherent with no weight case -
trunk/lib/classifier/PolynomialKernelFunction.h
r524 r527 5 5 6 6 #include <c++_tools/classifier/KernelFunction.h> 7 #include <c++_tools/gslapi/vector.h> 7 #include <c++_tools/classifier/DataLookup1D.h> 8 8 9 9 10 #include <cmath> … … 38 39 ///y)^{order} \f$ \n If order is one (linear): \f$ x \cdot y \f$ 39 40 /// 40 inline double operator()(const gslapi::vector& a1,41 const gslapi::vector& a2) const42 41 inline double operator()(const DataLookup1D& a1, 42 const DataLookup1D& a2) const 43 { return ((order_>1) ? pow(1+a1*a2,order_) : a1*a2); } 43 44 44 45 … … 53 54 /// 54 55 /// 55 double operator()(const gslapi::vector& x, const gslapi::vector& y,56 const gslapi::vector& wx, const gslapi::vector& wy) const;56 double operator()(const DataLookup1D& x, const DataLookup1D& y, 57 const DataLookup1D& wx, const DataLookup1D& wy) const; 57 58 58 59 private: -
trunk/lib/classifier/SVM.cc
r523 r527 61 61 double SVM::predict(const gslapi::vector& x) const 62 62 { 63 // predict won't work until kernel::element is working 64 assert(0); 63 65 double y=0; 64 for (size_t i=0; i<alpha_.size(); i++)65 y += alpha_(i)*target_(i)*kernel_->element(x,i);66 //for (size_t i=0; i<alpha_.size(); i++) 67 //y += alpha_(i)*target_(i)*kernel_->element(x,i); 66 68 67 69 return y+bias_; -
trunk/lib/classifier/SVM.h
r523 r527 106 106 /// input. 107 107 /// 108 /// @note @a target must be a KernelLookup if the target orkernel109 /// is destroyed the SVM is no longerdefined.110 /// 111 SVM(const KernelLookup& , const Target&);108 /// @note if the @a target or @a kernel 109 /// is destroyed the behaviour is undefined. 110 /// 111 SVM(const KernelLookup& kernel, const Target& target); 112 112 113 113 /// -
trunk/lib/gslapi/vector.cc
r475 r527 7 7 #include <c++_tools/classifier/DataLookup1D.h> 8 8 9 #include <iostream> 9 10 #include <sstream> 10 11 #include <vector> -
trunk/test/ensemble_test.cc
r521 r527 9 9 #include <c++_tools/classifier/Kernel_SEV.h> 10 10 #include <c++_tools/classifier/Kernel_MEV.h> 11 #include <c++_tools/classifier/MatrixLookup.h> 11 12 #include <c++_tools/classifier/PolynomialKernelFunction.h> 12 13 #include <c++_tools/classifier/SVM.h> … … 36 37 37 38 std::ifstream is("data/nm_data_centralized.txt"); 38 gslapi::matrix data (is);39 gslapi::matrix data_core(is); 39 40 is.close(); 40 41 42 classifier::MatrixLookup data(data_core); 41 43 classifier::KernelFunction* kf = new classifier::PolynomialKernelFunction(); 42 44 classifier::Kernel_SEV kernel(data,*kf); -
trunk/test/kernel_test.cc
r513 r527 23 23 using namespace theplu; 24 24 25 bool test_MEV(const gslapi::matrix& data, const classifier::KernelFunction* kf, 25 bool test_MEV(const classifier::MatrixLookup& data, 26 const classifier::KernelFunction* kf, 26 27 const gslapi::matrix& control, const double error_bound, 27 28 std::ostream* error); 28 29 29 bool test_SEV(const gslapi::matrix& data, const classifier::KernelFunction* kf, 30 bool test_SEV(const classifier::MatrixLookup& data, 31 const classifier::KernelFunction* kf, 30 32 const gslapi::matrix& control, const double error_bound, 31 33 std::ostream* error); … … 46 48 bool ok = true; 47 49 50 gslapi::matrix data2_core(2,3); 51 data2_core(0,0)=0; 52 data2_core(1,0)=0; 53 data2_core(0,1)=0; 54 data2_core(1,1)=1; 55 data2_core(0,2)=1; 56 data2_core(1,2)=0; 57 classifier::MatrixLookup data2(data2_core); 58 classifier::KernelFunction* kf2 = new classifier::PolynomialKernelFunction(); 59 classifier::Kernel_SEV kernel2(data2,*kf2); 60 assert(kernel2.size()==3); 61 if(kernel2(0,0) || kernel2(0,1) || kernel2(0,2) || 62 kernel2(1,0) || kernel2(1,1)!=1 || kernel2(1,2) || 63 kernel2(2,0) || kernel2(2,1) || kernel2(2,2)!=1){ 64 ok = false; 65 *error << "Found:\n"; 66 for (size_t i=0; i<3; i++){ 67 for (size_t j=0; j<3; j++) 68 *error << kernel2(i,j) << " "; 69 *error << std::endl; 70 } 71 *error << "Expected:\n0 0 0\n0 1 0\n0 0 1" << std::endl; 72 } 73 classifier::KernelLookup kv2(kernel2); 74 delete kf2; 75 48 76 // Peter, the hardcoded number below should be changed. 49 77 double error_bound = 1e-8; 50 78 std::ifstream is("data/nm_data_centralized.txt"); 51 gslapi::matrix transposed_data(is);79 gslapi::matrix data_core(is); 52 80 is.close(); 53 // Because how the kernel is treated is changed, data must be transposed. 54 gslapi::matrix data=transposed_data;81 82 classifier::MatrixLookup data(data_core); 55 83 56 84 is.open("data/nm_kernel.txt"); … … 70 98 delete kf; 71 99 72 // Checking that a GaussianKernelFunction object can be built at 73 // compile time. 100 // Checking that a GaussianKernelFunction object can be built. 74 101 kf = new classifier::GaussianKernelFunction(); 75 102 delete kf; … … 83 110 } 84 111 85 bool test_MEV(const gslapi::matrix& data, const classifier::KernelFunction* kf, 112 bool test_MEV(const classifier::MatrixLookup& data, 113 const classifier::KernelFunction* kf, 86 114 const gslapi::matrix& control, const double error_bound, 87 115 std::ostream* error) 88 116 { 89 117 // at least testing constructors 118 *error << "testing KernelWeighted_MEV" << std::endl; 90 119 classifier::KernelWeighted_MEV kernel_weighted(data,*kf,data); 91 120 121 *error << "testing Kernel_MEV" << std::endl; 92 122 classifier::Kernel_MEV kernel(data,*kf); 93 123 for(u_int i=0;i<control.rows();i++) … … 122 152 } 123 153 124 bool test_SEV(const gslapi::matrix& data, const classifier::KernelFunction* kf, 154 bool test_SEV(const classifier::MatrixLookup& data, 155 const classifier::KernelFunction* kf, 125 156 const gslapi::matrix& control, const double error_bound, 126 157 std::ostream* error) 127 158 { 128 159 // at least testing constructors 129 classifier::KernelWeighted_MEV kernel_weighted(data,*kf,data); 160 *error << "testing KernelWeighted_SEV" << std::endl; 161 classifier::KernelWeighted_SEV kernel_weighted(data,*kf,data); 130 162 163 *error << "testing Kernel_SEV" << std::endl; 131 164 classifier::Kernel_SEV kernel(data,*kf); 132 165 for(u_int i=0;i<control.rows();i++) -
trunk/test/svm_test.cc
r514 r527 32 32 bool ok = true; 33 33 34 gslapi::matrix data2(2,3); 35 data2(0,0)=0; 36 data2(1,0)=0; 37 data2(0,1)=0; 38 data2(1,1)=1; 39 data2(0,2)=1; 40 data2(1,2)=0; 34 gslapi::matrix data2_core(2,3); 35 data2_core(0,0)=0; 36 data2_core(1,0)=0; 37 data2_core(0,1)=0; 38 data2_core(1,1)=1; 39 data2_core(0,2)=1; 40 data2_core(1,2)=0; 41 classifier::MatrixLookup data2(data2_core); 41 42 std::vector<std::string> label; 42 43 label.reserve(3); … … 49 50 assert(kernel2.size()==3); 50 51 assert(target2.size()==3); 52 for (size_t i=0; i<3; i++){ 53 for (size_t j=0; j<3; j++) 54 *error << kernel2(i,j) << " "; 55 *error << std::endl; 56 } 51 57 classifier::KernelLookup kv2(kernel2); 52 58 *error << "testing with linear kernel" << std::endl; … … 82 88 83 89 std::ifstream is("data/nm_data_centralized.txt"); 84 gslapi::matrix transposed_data(is);90 gslapi::matrix data_core(is); 85 91 is.close(); 86 // Because how the kernel is treated is changed, data must be transposed. 87 gslapi::matrix data=transposed_data;92 93 classifier::MatrixLookup data(data_core); 88 94 89 95 classifier::KernelFunction* kf = new classifier::PolynomialKernelFunction();
Note: See TracChangeset
for help on using the changeset viewer.