Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SVM.cc
r36 r37 20 20 kernel_(kernel), 21 21 target_(target), 22 alpha_(target.size(),true,true) 22 alpha_(target.size(),true,true), 23 bias_(0) 24 23 25 { 24 26 } … … 38 40 // Stop criteria 39 41 bool stop_condition = false; 40 while( count<100000 &&!stop_condition)42 while(!stop_condition) 41 43 { 42 44 count++; … … 90 92 alpha_[index2]=alpha_new; 91 93 stop_condition = stop( target_, kernel_, alpha_); 94 if (count>10000000){ 95 cerr << "SVM): " << "more than 10,000,000 epochs reached" << endl; 96 exit(1); 97 } 92 98 } 99 100 // Calculating the bias 101 double min_output_positive = 10000; 102 double max_output_negative = -10000; 103 thep_gsl_api::vector output_unbiased = kernel_ * alpha_.mul_elements(target_); 104 for (u_int i=0; i<target_.size(); i++){ 105 if (target_[i]==1){ 106 if (output_unbiased[i] < min_output_positive) 107 min_output_positive = output_unbiased[i]; 108 } 109 else if( output_unbiased[i] > max_output_negative ) 110 max_output_negative = output_unbiased[i]; 93 111 112 } 113 cout << max_output_negative << endl; 114 cout << min_output_positive << endl; 115 116 bias_ = ( -min_output_positive - max_output_negative )/2; 117 cout << "bias:" << bias_ << endl; 118 94 119 trained_= true; 95 120 } … … 101 126 double min_output_positive = 10000; 102 127 double max_output_negative = -10000; 103 double epsilon = 0.00 1; // used twice, should perhaps be two different values128 double epsilon = 0.000001; // used twice, should perhaps be two different values 104 129 thep_gsl_api::vector output_unbiased = kernel_ * alpha_.mul_elements(target_); 105 130 for (u_int i=0; i<target_.size(); i++){ -
trunk/src/SVM.h
r36 r37 8 8 #include "vector.h" 9 9 #include "matrix.h" 10 10 11 11 12 // Standard C++ includes … … 34 35 */ 35 36 inline thep_gsl_api::vector get_alpha() const; 37 38 /** 39 Function will return the output from SVM 40 */ 41 inline thep_gsl_api::vector get_output() const; 42 36 43 37 44 … … 41 48 thep_gsl_api::vector target_; 42 49 thep_gsl_api::vector alpha_; 50 double bias_; 43 51 44 52 /** 45 Private function that determines when to stop the training 53 Private function that determines when to stop the training. 54 The test is done in two steps. First, we check that the 55 functional margin is at least 2 - epsilon. Second, we check 56 that the gap between the primal and the dual object is less 57 than epsilon. 58 46 59 */ 47 60 bool SVM::stop(const thep_gsl_api::vector& target_, … … 55 68 return alpha_; 56 69 } 70 71 thep_gsl_api::vector SVM::get_output() const 72 { 73 thep_gsl_api::vector bias(target_.size(), false, false); 74 bias.set_all(bias_); 75 return kernel_ * alpha_.mul_elements(target_) + bias; 76 77 } 57 78 }; // namespace thep_c++_tools 58 79 -
trunk/src/vector.cc
r36 r37 247 247 { 248 248 double sum = 0; 249 for ( int i=0; i<size(); i++)249 for (u_int i=0; i<size(); i++) 250 250 sum += gsl_vector_get( v_, i ); 251 251 return( sum );
Note: See TracChangeset
for help on using the changeset viewer.