Changeset 42 for trunk/src/SVM.cc


Ignore:
Timestamp:
Feb 26, 2004, 4:06:20 PM (19 years ago)
Author:
Jari Häkkinen
Message:

Made a major revision of matrix and vector classes. Everything compiles
but the binaries have not been tested.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SVM.cc

    r37 r42  
    1313#include "random_singleton.h"
    1414
    15 using namespace thep_cpp_tools;
    16 using namespace std;
     15namespace theplu {
     16namespace cpptools { 
    1717
    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  
     18SVM::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)
    2524{
    2625}
    2726
    28 void SVM::train() //Should be done so one can choose to not train on all the samples
     27void SVM::train(void) //Should be done so one can choose to not train on all the samples
    2928{
    30   thep_gsl_api::vector E = thep_gsl_api::vector(-target_);
     29  using namespace std;
     30  gslapi::vector E = gslapi::vector(-target_);
    3131 
    3232  double upper_bound = pow(10., 32);
     
    3636  double u;
    3737  double v;
    38   thep_gsl_api::vector dalpha; 
     38  gslapi::vector dalpha; 
    3939 
    4040  // Stop criteria 
     
    4747       
    4848     // Choosing a pair of variables to modify (Should be done more clever)
    49      u_long index1 = rnd->get_uniform_int(kernel_.cols());
    50      u_long index2 = rnd->get_uniform_int(kernel_.cols()-1);
     49     u_long index1 = rnd->get_uniform_int(kernel_.columns());
     50     u_long index2 = rnd->get_uniform_int(kernel_.columns()-1);
    5151     if (index2 >= index1)
    5252      index2++;
     
    8080       }
    8181
    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) );
    8484     alpha_new = alpha_[index2] + target_[index2]*
    8585       (E[index1]-E[index2])/k;
     
    9393     stop_condition = stop( target_, kernel_, alpha_);
    9494     if (count>10000000){
    95       cerr << "SVM): " << "more than 10,000,000 epochs reached" << endl;
     95      cerr << "SVM): " << "more than 10,000,000 epochs reached" << endl;
    9696       exit(1);
    9797     }
     
    101101  double min_output_positive = 10000;
    102102  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_);
    104104  for (u_int i=0; i<target_.size(); i++){
    105105   if (target_[i]==1){
     
    120120}
    121121
    122 bool SVM::stop( const thep_gsl_api::vector& target_,
    123     const thep_gsl_api::matrix& kernel_,
    124     const thep_gsl_api::vector& alpha_)
     122bool SVM::stop( const gslapi::vector& target_,
     123    const gslapi::matrix& kernel_,
     124    const gslapi::vector& alpha_)
    125125{
    126126  double min_output_positive = 10000;
    127127  double max_output_negative = -10000;
    128128  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_);
    130130  for (u_int i=0; i<target_.size(); i++){
    131131   if (target_[i]==1){
     
    154154}
    155155
    156 
     156}} // of namespace cpptools and namespace theplu
    157157
    158158#endif
Note: See TracChangeset for help on using the changeset viewer.