Changeset 30


Ignore:
Timestamp:
Jan 16, 2004, 6:40:51 PM (19 years ago)
Author:
Peter
Message:

adding SVM

Location:
trunk/src
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r29 r30  
    66
    77libc___tools_a_SOURCES = matrix.cc vector.cc SVD.cc PCA.cc \
    8   random_singleton.cc histogram.cc Kernel.cc PolynomialKernelFunction.cc \
    9   SVM.cc
     8  random_singleton.cc histogram.cc Kernel.cc\
     9  PolynomialKernelFunction.cc SVM.cc
    1010
    1111INCLUDES = -I/usr/local_bio/include -I/usr/local_bio
     12
     13AM_CXXFLAGS = -g
  • trunk/src/PolynomialKernelFunction.cc

    r25 r30  
    3131     nof_valid_datapairs++;
    3232    }
    33   cout << nof_valid_datapairs << endl;
     33  //cout << nof_valid_datapairs << endl;
    3434  if (nof_valid_datapairs == 0)
    3535    cerr << "data file error: two columns "
    3636   << " have no pair of valid data\n";
    37   tmp/=nof_valid_datapairs * a.size();
     37 
     38  tmp/=nof_valid_datapairs / a.size(); //correcting for missing values
     39 
    3840  if(order_>1)
    3941    return pow(1+tmp,order_);
  • trunk/src/PolynomialKernelFunction.h

    r26 r30  
    2727    PolynomialKernelFunction(int = 1);
    2828    /**
     29       Destructor
     30    */
     31       virtual ~PolynomialKernelFunction(void) {};
     32    /**
    2933       returning the scalar product of two vectors in feature space using
    3034       the polynomial kernel.
  • trunk/src/matrix.cc

    r29 r30  
    8585  is.clear(std::ios::goodbit);
    8686  // convert the data to a gsl matrix
    87   cout << "nof_rows: " << nof_rows << ", nof_columns: " << nof_columns
    88        << endl;
    8987  m_ = gsl_matrix_alloc ( nof_rows, nof_columns );
    9088  for(u_int i=0;i<nof_rows;i++)
     
    325323  return v_sum;
    326324}
     325
     326vector matrix::operator[]( const size_t& i ) const
     327{
     328  gsl_vector* tmp_vector = gsl_vector_calloc( cols() );
     329  assert( i >= 0 && i < rows() );
     330  gsl_matrix_get_row( tmp_vector, m_, i );
     331  return vector( tmp_vector );
     332}
     333
     334
  • trunk/src/matrix.h

    r21 r30  
    215215    friend std::ostream& operator<< ( std::ostream& s_out, const matrix& );
    216216
    217 
    218 
    219 
     217    /**
     218       Getting vector operator
     219    */
     220    vector operator[]( const size_t& i ) const;
     221 
    220222  private:
    221223    gsl_matrix* new_copy( const gsl_matrix* );
     
    232234
    233235#endif
    234 
    235 
  • trunk/src/vector.cc

    r28 r30  
    6565   while (line >> tmp_string) {
    6666    if(!is.good()) {
    67      cerr << "matrix::matrix(std::istream&): "
     67     cerr << "vector::vector(std::istream&): "
    6868    << "error reading data file!" << endl;
    6969     exit(1);
     
    8585   data_matrix.push_back(v);
    8686  }
    87 
     87 
     88  // manipulate the state of the stream to be good
     89  is.clear(std::ios::goodbit);
     90 
    8891  // convert the data to a gsl vector and check that data file is a
    8992  // column vector or a row vector
     
    166169}
    167170
    168 
     171vector vector::operator-() const
     172{
     173  vector res( *this );
     174  gsl_vector_scale (res.get_gsl_vector() , -1.);
     175  return res;
     176}
    169177double vector::operator*( const vector &other ) const
    170178{
  • trunk/src/vector.h

    r28 r30  
    114114
    115115    /**
    116        set_all( val ) will make vi = val in matrix A
     116       set_all( val ) will make vi = val in vector v
    117117       for all "i"
    118118    */
     
    153153    int operator/=( const double& c );
    154154    int operator/=( const vector& other ) const;
     155    vector operator-() const;
    155156    /**
    156157       This operator is implemented as dot-product.
Note: See TracChangeset for help on using the changeset viewer.