Changeset 56


Ignore:
Timestamp:
Mar 18, 2004, 10:12:24 PM (18 years ago)
Author:
Peter
Message:

adding a choice not to train on all the samples

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SVM.cc

    r55 r56  
    2323}
    2424
    25 void SVM::train(const double C) //Peter, this should be done so one can choose to not train on all the samples
     25void SVM::train(const double C, const gslapi::vector& TrainSet)
    2626{
    2727  using namespace std;
    2828 
     29  // Defining the sub-kernel-matrix to train on
     30  if (TrainSet.size()==1)
     31    gslapi::matrix sub_kernel = kernel_;
     32  else{
     33    gslapi::matrix sub_kernel(TrainSet.size(),TrainSet.size());
     34    for (unsigned int i=0; i<TrainSet.size(); i++)
     35      for (unsigned int j=0; j<TrainSet.size(); j++)
     36        sub_kernel(i,j) = kernel_(i,j);
     37  }
     38 
     39  // Modify the diagonal of the kernel matrix
    2940  double D;
    3041  if (C>0)
     
    3647    exit(1);
    3748  }
    38 
    39   // Modify the diagonal of the kernel matrix
    4049  gslapi::matrix kernel_modified = kernel_;
    4150  for (unsigned int i=0; i<kernel_.columns(); i++)
    4251    kernel_modified(i,i) += D;
    43 
     52 
    4453  gslapi::vector E = gslapi::vector(-target_);
    45  
    4654  double upper_bound = pow(10., 32.); //Peter, should be static or is there need for an upperbound?
    4755  u_int count = 0;
  • trunk/src/SVM.h

    r55 r56  
    3535           
    3636    ///
    37     /// Training the SVM using the SMO algorithm. Input is the C-parameter,
    38     /// which is converted to \f$D=1/C\f$, since \f$1/C\f$ is what is used in
    39     /// the algorithm. Default should correspond to maximal margin
    40     /// (\f$C=\inf\f$), but since I don't trust double inf I use default
    41     /// \f$C=0\f$ and turn that into \f$D=0\f$.
     37    /// Training the SVM using the a modified version of the SMO
     38    /// algorithm. Input is the C-parameter, which is converted to
     39    /// \f$D=1/C\f$, since \f$1/C\f$ is what is used in the algorithm. Default
     40    /// should correspond to maximal margin (\f$C=\inf\f$), but since I don't
     41    /// trust double inf I use default \f$C=0\f$ and turn that into
     42    /// \f$D=0\f$. The second input defines what samples that is included in
     43    /// the training, e.g. [1,2,3] means train on samples 1, 2 and 3.
    4244    ///
    43     void train(const double = 0);
    44 
     45    void train(const double = 0,
     46               const gslapi::vector& = gslapi::vector(1,0));
     47               
    4548    ///
    4649    /// Function will return \f$\alpha\f$
Note: See TracChangeset for help on using the changeset viewer.