Changeset 36 for trunk/src/SVM.cc
- Timestamp:
- Feb 12, 2004, 11:29:21 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SVM.cc
r30 r36 34 34 double u; 35 35 double v; 36 thep_gsl_api::vector dalpha; 36 37 37 38 // Stop criteria 38 ofstream myout("alpha.tst"); 39 double tmp; 40 thep_gsl_api::vector dalpha; 41 thep_gsl_api::vector one(E.size(),true,true); 42 one.set_all(1); 43 while (count<10000) 39 bool stop_condition = false; 40 while(count<100000 && !stop_condition) 44 41 { 45 42 count++; 46 43 dalpha = alpha_.mul_elements(target_); 47 E=kernel_*dalpha-target_; //should be done in another way!! 48 tmp=dalpha*(kernel_*dalpha)/2; 49 tmp=tmp-alpha_*one; 50 myout << tmp << '\n'; 44 E = kernel_*dalpha-target_; //should be done in another way!! 45 51 46 // Choosing a pair of variables to modify (Should be done more clever) 52 47 u_long index1 = rnd->get_uniform_int(kernel_.cols()); … … 94 89 alpha_[index1]+=target_[index1]*target_[index2]*(alpha_[index2]-alpha_new); 95 90 alpha_[index2]=alpha_new; 96 97 98 99 100 101 91 stop_condition = stop( target_, kernel_, alpha_); 102 92 } 103 93 104 myout.close();105 106 //thep_gsl_api::vector output = kernel_*dalpha;107 //for (int i=0; i<64; i++){108 //cout << output.get(i) << '\t';109 //cout << alpha_.get(i) << endl;110 //}111 112 94 trained_= true; 113 95 } 114 96 97 bool SVM::stop( const thep_gsl_api::vector& target_, 98 const thep_gsl_api::matrix& kernel_, 99 const thep_gsl_api::vector& alpha_) 100 { 101 double min_output_positive = 10000; 102 double max_output_negative = -10000; 103 double epsilon = 0.001; // used twice, should perhaps be two different values 104 thep_gsl_api::vector output_unbiased = kernel_ * alpha_.mul_elements(target_); 105 for (u_int i=0; i<target_.size(); i++){ 106 if (target_[i]==1){ 107 if (output_unbiased[i] < min_output_positive) 108 min_output_positive = output_unbiased[i]; 109 } 110 else if( output_unbiased[i] > max_output_negative ) 111 max_output_negative = output_unbiased[i]; 112 113 } 114 115 if (min_output_positive - max_output_negative < 2-epsilon){ 116 return false; 117 } 118 else{ 119 double primal = alpha_.mul_elements(target_) 120 * ( alpha_.mul_elements(target_) ); 121 double gap = 2 * primal - alpha_.sum(); 122 if (gap/(primal+1)<epsilon) 123 return true; 124 else 125 return false; 126 } 127 128 129 } 130 131 132 115 133 #endif
Note: See TracChangeset
for help on using the changeset viewer.