Changeset 42 for trunk/src/SVM.cc
- Timestamp:
- Feb 26, 2004, 4:06:20 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SVM.cc
r37 r42 13 13 #include "random_singleton.h" 14 14 15 using namespace thep_cpp_tools; 16 using namespace std; 15 namespace theplu { 16 namespace cpptools { 17 17 18 SVM::SVM(const thep_gsl_api::matrix& kernel, 19 const thep_gsl_api::vector& target) : trained_(false), 20 kernel_(kernel), 21 target_(target), 22 alpha_(target.size(),true,true), 23 bias_(0) 24 18 SVM::SVM(const gslapi::matrix& kernel, const gslapi::vector& target) 19 : trained_(false), 20 kernel_(kernel), 21 target_(target), 22 alpha_(target.size()), 23 bias_(0) 25 24 { 26 25 } 27 26 28 void SVM::train( ) //Should be done so one can choose to not train on all the samples27 void SVM::train(void) //Should be done so one can choose to not train on all the samples 29 28 { 30 thep_gsl_api::vector E = thep_gsl_api::vector(-target_); 29 using namespace std; 30 gslapi::vector E = gslapi::vector(-target_); 31 31 32 32 double upper_bound = pow(10., 32); … … 36 36 double u; 37 37 double v; 38 thep_gsl_api::vector dalpha;38 gslapi::vector dalpha; 39 39 40 40 // Stop criteria … … 47 47 48 48 // Choosing a pair of variables to modify (Should be done more clever) 49 u_long index1 = rnd->get_uniform_int(kernel_.col s());50 u_long index2 = rnd->get_uniform_int(kernel_.col s()-1);49 u_long index1 = rnd->get_uniform_int(kernel_.columns()); 50 u_long index2 = rnd->get_uniform_int(kernel_.columns()-1); 51 51 if (index2 >= index1) 52 52 index2++; … … 80 80 } 81 81 82 double k = kernel_.get(index1, index1) + kernel_.get(index2, index2) -83 2*kernel_.get(index1, index2);82 double k = ( kernel_(index1, index1) + kernel_(index2, index2) - 83 2*kernel_(index1, index2) ); 84 84 alpha_new = alpha_[index2] + target_[index2]* 85 85 (E[index1]-E[index2])/k; … … 93 93 stop_condition = stop( target_, kernel_, alpha_); 94 94 if (count>10000000){ 95 95 cerr << "SVM): " << "more than 10,000,000 epochs reached" << endl; 96 96 exit(1); 97 97 } … … 101 101 double min_output_positive = 10000; 102 102 double max_output_negative = -10000; 103 thep_gsl_api::vector output_unbiased = kernel_ * alpha_.mul_elements(target_);103 gslapi::vector output_unbiased = kernel_ * alpha_.mul_elements(target_); 104 104 for (u_int i=0; i<target_.size(); i++){ 105 105 if (target_[i]==1){ … … 120 120 } 121 121 122 bool SVM::stop( const thep_gsl_api::vector& target_,123 const thep_gsl_api::matrix& kernel_,124 const thep_gsl_api::vector& alpha_)122 bool SVM::stop( const gslapi::vector& target_, 123 const gslapi::matrix& kernel_, 124 const gslapi::vector& alpha_) 125 125 { 126 126 double min_output_positive = 10000; 127 127 double max_output_negative = -10000; 128 128 double epsilon = 0.000001; // used twice, should perhaps be two different values 129 thep_gsl_api::vector output_unbiased = kernel_ * alpha_.mul_elements(target_);129 gslapi::vector output_unbiased = kernel_ * alpha_.mul_elements(target_); 130 130 for (u_int i=0; i<target_.size(); i++){ 131 131 if (target_[i]==1){ … … 154 154 } 155 155 156 156 }} // of namespace cpptools and namespace theplu 157 157 158 158 #endif
Note: See TracChangeset
for help on using the changeset viewer.