Changeset 295 for trunk/lib/svm
- Timestamp:
- Apr 29, 2005, 11:15:58 AM (17 years ago)
- Location:
- trunk/lib
- Files:
-
- 3 added
- 15 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/svm/ConsensusInputRanker.cc
r294 r295 2 2 3 3 4 #include "ConsensusInputRanker.h" 5 // Thep C++ Tools 6 #include "CrossValidation.h" 7 #include "InputRanker.h" 8 #include "Statistics.h" 9 #include "stl_utility.h" 4 #include <c++_tools/svm/ConsensusInputRanker.h> 10 5 11 // System includes 6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/statistics/Statistics.h> 8 #include <c++_tools/svm/CrossValidation.h> 9 #include <c++_tools/svm/InputRanker.h> 10 #include <c++_tools/utility/stl_utility.h> 11 12 #include <utility> 12 13 #include <vector> 13 14 14 15 namespace theplu { 15 namespace cpptools{16 namespace svm { 16 17 17 18 ConsensusInputRanker::ConsensusInputRanker(const gslapi::matrix& data, 18 19 const gslapi::vector& target, 19 Score& score_object,20 statistics::Score& score_object, 20 21 const size_t rounds, 21 22 const size_t k) … … 43 44 //sort medians and assign id_ and rank_ 44 45 sort(median.begin(), median.end(), 45 pair_value_compare<size_t, double>());46 cpptools::pair_value_compare<size_t, double>()); 46 47 id_.resize(data.rows()); 47 48 rank_.resize(data.rows()); … … 56 57 const gslapi::vector& target, 57 58 const gslapi::matrix& weight, 58 Score& score_object,59 statistics::Score& score_object, 59 60 const size_t rounds, 60 61 const size_t k) … … 80 81 //sort medians and assign id_ and rank_ 81 82 sort(median.begin(), median.end(), 82 pair_value_compare<size_t, double>());83 cpptools::pair_value_compare<size_t, double>()); 83 84 id_.resize(data.rows()); 84 85 rank_.resize(data.rows()); … … 91 92 92 93 93 }} // of namespace cpptoolsand namespace theplu94 }} // of namespace svm and namespace theplu -
trunk/lib/svm/ConsensusInputRanker.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_consensusinputranker_4 #define _theplu_ cpptools_consensusinputranker_3 #ifndef _theplu_svm_consensusinputranker_ 4 #define _theplu_svm_consensusinputranker_ 5 5 6 // C++ tools include 7 ///////////////////// 8 #include "InputRanker.h" 9 #include "matrix.h" 10 #include "Score.h" 11 #include "vector.h" 12 13 // Standard C++ includes 14 //////////////////////// 15 6 #include <c++_tools/svm/InputRanker.h> 16 7 17 8 namespace theplu { 18 namespace cpptools { 9 class gslapi::matrix; 10 class gslapi::vector; 11 class statistics::Score; 12 namespace svm { 19 13 20 14 /// … … 34 28 ConsensusInputRanker(const gslapi::matrix& data, 35 29 const gslapi::vector& target, 36 Score&,30 statistics::Score&, 37 31 const size_t n = 1 , 38 32 const size_t k = 3 ); … … 46 40 const gslapi::vector& target, 47 41 const gslapi::matrix& weight, 48 Score&,42 statistics::Score&, 49 43 const size_t n = 1 , 50 44 const size_t k = 3 ); … … 71 65 }; 72 66 73 }} // of namespace cpptoolsand namespace theplu67 }} // of namespace svm and namespace theplu 74 68 75 69 #endif -
trunk/lib/svm/CrossValidation.cc
r294 r295 1 1 // $Id$ 2 2 3 // System includes 3 4 #include <c++_tools/gslapi/vector.h> 5 #include <c++_tools/svm/CrossValidation.h> 6 #include <c++_tools/utility/random_singleton.h> 7 4 8 #include <vector> 5 9 6 // Thep C++ Tools7 #include "random_singleton.h"8 #include "CrossValidation.h"9 10 10 namespace theplu { 11 namespace cpptools{11 namespace svm { 12 12 13 13 CrossValidation::CrossValidation(const theplu::gslapi::vector& target, … … 24 24 } 25 25 26 my_uniform_rng a;26 cpptools::my_uniform_rng a; 27 27 random_shuffle(index_negative_.begin(), index_negative_.end(), a); 28 28 random_shuffle(index_positive_.begin(), index_positive_.end(), a); … … 33 33 if (count_==k_){ 34 34 count_=0; 35 my_uniform_rng a;35 cpptools::my_uniform_rng a; 36 36 random_shuffle(index_negative_.begin(), index_negative_.end(), a); 37 37 random_shuffle(index_positive_.begin(), index_positive_.end(), a); -
trunk/lib/svm/CrossValidation.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_crossvalidation_4 #define _theplu_ cpptools_crossvalidation_3 #ifndef _theplu_svm_crossvalidation_ 4 #define _theplu_svm_crossvalidation_ 5 5 6 // C++ tools include7 /////////////////////8 #include "vector.h"9 10 // Standard C++ includes11 ////////////////////////12 6 #include <vector> 13 7 14 8 namespace theplu { 15 namespace cpptools { 9 namespace gslapi { 10 class vector; 11 } 12 namespace svm { 16 13 17 14 /// … … 24 21 public: 25 22 /// 26 /// Constructor taking \a target and \ k for k-fold cross validation23 /// Constructor taking \a target and \a k for k-fold cross validation 27 24 /// 28 25 CrossValidation(const theplu::gslapi::vector& target, const size_t k = 3); … … 46 43 }; 47 44 48 }} // of namespace cpptoolsand namespace theplu45 }} // of namespace svm and namespace theplu 49 46 50 47 #endif -
trunk/lib/svm/GaussianKernelFunction.cc
r294 r295 1 1 // $Id$ 2 2 3 // System 3 #include <c++_tools/svm/GaussianKernelFunction.h> 4 5 #include <c++_tools/svm/KernelFunction.h> 6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/gslapi/vector.h> 8 4 9 #include <math.h> 5 10 6 7 // Thep C++ Tools8 #include "GaussianKernelFunction.h"9 #include "matrix.h"10 #include "vector.h"11 12 11 namespace theplu { 13 namespace cpptools{12 namespace svm { 14 13 15 14 GaussianKernelFunction::GaussianKernelFunction(double sigma) … … 53 52 } 54 53 55 }} // of namespace cpptoolsand namespace theplu54 }} // of namespace svn and namespace theplu -
trunk/lib/svm/GaussianKernelFunction.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_gaussian_kernel_function_4 #define _theplu_ cpptools_gaussian_kernel_function_3 #ifndef _theplu_svm_gaussian_kernel_function_ 4 #define _theplu_svm_gaussian_kernel_function_ 5 5 6 #include "KernelFunction.h" 7 #include "vector.h" 6 #include <c++_tools/gslapi/vector.h> 7 #include <c++_tools/svm/KernelFunction.h> 8 9 #include <cmath> 8 10 9 11 namespace theplu { 12 class gslapi::vector; 10 13 11 namespace gslapi { 12 class vector; 13 } 14 15 namespace cpptools { 14 namespace svm { 16 15 17 16 /// 18 17 /// Class for Gaussian kernel calculations. 19 18 /// 20 21 19 22 20 class GaussianKernelFunction : public KernelFunction … … 41 39 inline double operator()(const gslapi::vector& a1, 42 40 const gslapi::vector& a2) 43 {return exp(-(a1-a2)*(a1-a2)/ pow(sigma_,2));}41 {return exp(-(a1-a2)*(a1-a2)/(sigma_*sigma_));} 44 42 43 /// 45 44 ///returning the scalar product of two vectors in feature space using the 46 45 ///Gaussian kernel with weights. … … 52 51 53 52 /// 54 /// @ kernel matrix53 /// @return kernel matrix 55 54 /// 56 55 const gslapi::matrix& operator()(theplu::gslapi::matrix& kernel, … … 62 61 }; // class GaussianKernelFunction 63 62 64 }} // of namespace cpptoolsand namespace theplu63 }} // of namespace svm and namespace theplu 65 64 66 65 #endif -
trunk/lib/svm/InputRanker.cc
r294 r295 1 1 // $Id$ 2 2 3 // Thep C++ Tools 4 #include "InputRanker.h" 5 #include "ROC.h"6 #include "matrix.h"7 #include "vector.h"8 #include "stl_utility.h"3 #include <c++_tools/svm/InputRanker.h> 4 5 #include <c++_tools/gslapi/matrix.h> 6 #include <c++_tools/gslapi/vector.h> 7 #include <c++_tools/statistics/ROC.h> 8 #include <c++_tools/utility/stl_utility.h> 9 9 10 10 #include <vector> … … 12 12 13 13 namespace theplu { 14 namespace cpptools{14 namespace svm { 15 15 16 16 InputRanker::InputRanker() … … 24 24 InputRanker::InputRanker(const gslapi::matrix& data, 25 25 const gslapi::vector& target, 26 Score& score_object,26 statistics::Score& score_object, 27 27 const std::vector<size_t>& train_set) 28 28 :train_set_(train_set), … … 49 49 //sort the scores and assign id_ and rank_ 50 50 sort(score.begin(), score.end(), 51 pair_value_compare<size_t, double>());51 cpptools::pair_value_compare<size_t, double>()); 52 52 53 53 for (size_t i=0; i<nof_genes; i++){ … … 60 60 const gslapi::vector& target, 61 61 const gslapi::matrix& weight, 62 Score& score_object,62 statistics::Score& score_object, 63 63 const std::vector<size_t>& train_set) 64 64 :train_set_(train_set), … … 84 84 //sort the scores and assign id_ and rank_ 85 85 sort(score.begin(), score.end(), 86 pair_value_compare<size_t, double>());86 cpptools::pair_value_compare<size_t, double>()); 87 87 88 88 for (size_t i=0; i<nof_genes; i++){ … … 92 92 } 93 93 94 }} // of namespace cpptoolsand namespace theplu94 }} // of namespace svm and namespace theplu -
trunk/lib/svm/InputRanker.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_inputranker_4 #define _theplu_ cpptools_inputranker_3 #ifndef _theplu_svm_inputranker_ 4 #define _theplu_svm_inputranker_ 5 5 6 // C++ tools include 7 ///////////////////// 8 #include "vector.h" 9 #include "matrix.h" 10 #include "Score.h" 11 12 // Standard C++ includes 13 //////////////////////// 14 6 #include <vector> 15 7 16 8 namespace theplu { 17 namespace cpptools { 9 namespace gslapi { 10 class matrix; 11 class vector; 12 } 13 namespace statistics { 14 class Score; 15 } 16 namespace svm { 18 17 /// 19 18 /// Class for ranking rows in a matrix, using a Score and a … … 36 35 InputRanker(const gslapi::matrix&, 37 36 const gslapi::vector&, 38 Score&,37 statistics::Score&, 39 38 const std::vector<size_t>& = std::vector<size_t>()); 40 39 … … 47 46 const gslapi::vector&, 48 47 const gslapi::matrix&, 49 Score&,48 statistics::Score&, 50 49 const std::vector<size_t>& = std::vector<size_t>()); 51 50 … … 71 70 }; 72 71 73 }} // of namespace cpptoolsand namespace theplu72 }} // of namespace svm and namespace theplu 74 73 75 74 #endif -
trunk/lib/svm/Kernel.cc
r294 r295 1 1 // $Id$ 2 2 3 // Thep C++ Tools 4 #include "Kernel.h" 5 #include "KernelFunction.h"6 #include "matrix.h"7 #include "vector.h"3 #include <c++_tools/svm/Kernel.h> 4 5 #include <c++_tools/svm/KernelFunction.h> 6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/gslapi/vector.h> 8 8 9 9 namespace theplu { 10 namespace cpptools{10 namespace svm { 11 11 12 12 Kernel::Kernel(const gslapi::matrix& data, const KernelFunction& kf) … … 32 32 } 33 33 34 }} // of namespace cpptoolsand namespace theplu34 }} // of namespace svm and namespace theplu -
trunk/lib/svm/Kernel.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_kernel_4 #define _theplu_ cpptools_kernel_3 #ifndef _theplu_svm_kernel_ 4 #define _theplu_svm_kernel_ 5 5 6 #include "matrix.h"6 #include <c++_tools/gslapi/matrix.h> 7 7 8 8 namespace theplu { 9 namespace cpptools{9 namespace svm { 10 10 11 11 class KernelFunction; … … 42 42 private: 43 43 gslapi::matrix k_; 44 const theplu::cpptools::KernelFunction* kf_;44 const KernelFunction* kf_; 45 45 bool weighted_; 46 46 47 47 }; // class Kernel 48 48 49 }} // of namespace cpptoolsand namespace theplu49 }} // of namespace svm and namespace theplu 50 50 51 51 #endif -
trunk/lib/svm/KernelFunction.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_kernel_function_4 #define _theplu_ cpptools_kernel_function_3 #ifndef _theplu_svm_kernel_function_ 4 #define _theplu_svm_kernel_function_ 5 5 6 6 namespace theplu { … … 11 11 } 12 12 13 namespace cpptools{13 namespace svm { 14 14 15 15 /// … … 30 30 virtual ~KernelFunction(void) {}; 31 31 32 /// 33 /// @return scalar product of two vector in feature space. 34 /// 32 35 virtual double operator()(const gslapi::vector&, 33 36 const gslapi::vector&) const = 0; 34 37 38 /// 39 /// @return scalar product of two vector in feature space. 40 /// 35 41 virtual double operator()(const gslapi::vector&, 36 42 const gslapi::vector&, … … 38 44 const gslapi::vector&) const = 0; 39 45 46 /// 47 /// @return kernel matrix 48 /// 40 49 virtual const theplu::gslapi::matrix& operator() 41 50 (theplu::gslapi::matrix& k, const gslapi::matrix& data) const = 0; … … 43 52 }; // class KernelFunction 44 53 45 }} // of namespace cpptoolsand namespace theplu54 }} // of namespace svm and namespace theplu 46 55 47 56 #endif -
trunk/lib/svm/PolynomialKernelFunction.cc
r294 r295 1 1 // $Id$ 2 2 3 // System 3 4 #include <c++_tools/svm/PolynomialKernelFunction.h> 5 6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/gslapi/vector.h> 8 4 9 #include <math.h> 5 6 // Thep C++ Tools7 #include "PolynomialKernelFunction.h"8 #include "matrix.h"9 #include "vector.h"10 10 11 11 12 12 namespace theplu { 13 namespace cpptools{13 namespace svm { 14 14 15 15 PolynomialKernelFunction::PolynomialKernelFunction(int order) … … 48 48 const theplu::gslapi::matrix& data) const 49 49 { 50 theplu::gslapi::matrix data_transposed(data.transpose());50 gslapi::matrix data_transposed(data.transpose()); 51 51 kernel = data_transposed*data; 52 52 if (order_>1) -
trunk/lib/svm/PolynomialKernelFunction.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_polynomial_kernel_function_4 #define _theplu_ cpptools_polynomial_kernel_function_3 #ifndef _theplu_svm_polynomial_kernel_function_ 4 #define _theplu_svm_polynomial_kernel_function_ 5 5 6 #include "KernelFunction.h"6 #include <c++_tools/svm/KernelFunction.h> 7 7 8 8 namespace theplu { … … 12 12 } 13 13 14 namespace cpptools{14 namespace svm { 15 15 16 16 /// … … 49 49 50 50 /// 51 /// @ kernel matrix51 /// @return kernel matrix 52 52 /// 53 53 const gslapi::matrix& operator()(theplu::gslapi::matrix& kernel, … … 59 59 }; // class PolynomialKernelFunction 60 60 61 }} // of namespace cpptoolsand namespace theplu61 }} // of namespace svm and namespace theplu 62 62 63 63 #endif -
trunk/lib/svm/SVM.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "SVM.h" 4 5 // System includes 3 4 #include <c++_tools/svm/SVM.h> 5 6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/gslapi/vector.h> 8 #include <c++_tools/statistics/Averager.h> 9 #include <c++_tools/utility/random_singleton.h> 10 6 11 #include <cmath> 7 12 #include <limits.h> … … 9 14 #include <vector> 10 15 11 // Thep C++ Tools12 #include "Averager.h"13 #include "matrix.h"14 #include "random_singleton.h"15 #include "vector.h"16 17 18 16 19 17 namespace theplu { 20 namespace cpptools{18 namespace svm { 21 19 22 20 SVM::SVM(const Kernel& kernel, … … 76 74 for (size_t i=0; i<E.size(); i++) 77 75 tmp[i]=i; 78 my_uniform_rng a;76 cpptools::my_uniform_rng a; 79 77 random_shuffle(tmp.begin(), tmp.end(), a); 80 78 for (size_t i=0; i<tmp.size(); i++){ -
trunk/lib/svm/SVM.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_svm_4 #define _theplu_ cpptools_svm_3 #ifndef _theplu_svm_svm_ 4 #define _theplu_svm_svm_ 5 5 6 // C++ tools include 7 ///////////////////// 8 #include "Kernel.h" 9 #include "matrix.h" 10 #include "vector.h" 6 #include <c++_tools/svm/Kernel.h> 7 #include <c++_tools/gslapi/vector.h> 11 8 12 13 // Standard C++ includes14 ////////////////////////15 9 #include <utility> 16 10 #include <vector> … … 18 12 19 13 namespace theplu { 20 namespace cpptools{14 namespace svm { 21 15 /// 22 16 /// Class for SVM using Keerthi's second modification of Platt's SMO. Also … … 35 29 /// Constructor taking the kernel matrix and the target vector as input 36 30 /// 37 SVM(const Kernel&, const gslapi::vector&, 31 SVM(const Kernel&, 32 const gslapi::vector&, 38 33 const std::vector<size_t>& = std::vector<size_t>()); 39 34 … … 90 85 double bias_; 91 86 double c_; 92 Kernel kernel_; 87 Kernel kernel_; // Peter, const ref? 93 88 unsigned long int max_epochs_; 94 gslapi::vector target_; 89 gslapi::vector target_; // Peter, const ref? 95 90 bool trained_; 96 91 std::vector<size_t> train_set_; … … 116 111 117 112 118 }} // of namespace cpptoolsand namespace theplu113 }} // of namespace svm and namespace theplu 119 114 120 115 #endif
Note: See TracChangeset
for help on using the changeset viewer.