Changeset 295 for trunk/lib/svm


Ignore:
Timestamp:
Apr 29, 2005, 11:15:58 AM (17 years ago)
Author:
Peter
Message:

file structure modifications. NOTE, this revision is not working, please wait for the next...

Location:
trunk/lib
Files:
3 added
15 moved

Legend:

Unmodified
Added
Removed
  • trunk/lib/svm/ConsensusInputRanker.cc

    r294 r295  
    22
    33
    4 #include "ConsensusInputRanker.h"
    5 // Thep C++ Tools
    6 #include "CrossValidation.h"
    7 #include "InputRanker.h"
    8 #include "Statistics.h"
    9 #include "stl_utility.h"
     4#include <c++_tools/svm/ConsensusInputRanker.h>
    105
    11 // System includes
     6#include <c++_tools/gslapi/matrix.h>
     7#include <c++_tools/statistics/Statistics.h>
     8#include <c++_tools/svm/CrossValidation.h>
     9#include <c++_tools/svm/InputRanker.h>
     10#include <c++_tools/utility/stl_utility.h>
     11
     12#include <utility>
    1213#include <vector>
    1314
    1415namespace theplu {
    15 namespace cpptools
     16namespace svm
    1617
    1718  ConsensusInputRanker::ConsensusInputRanker(const gslapi::matrix& data,
    1819                                             const gslapi::vector& target,
    19                                              Score& score_object,
     20                                             statistics::Score& score_object,
    2021                                             const size_t rounds,
    2122                                             const size_t k)
     
    4344    //sort medians and assign id_ and rank_
    4445    sort(median.begin(), median.end(),
    45          pair_value_compare<size_t, double>());
     46         cpptools::pair_value_compare<size_t, double>());
    4647    id_.resize(data.rows());
    4748    rank_.resize(data.rows());
     
    5657                                             const gslapi::vector& target,
    5758                                             const gslapi::matrix& weight,
    58                                              Score& score_object,
     59                                             statistics::Score& score_object,
    5960                                             const size_t rounds,
    6061                                             const size_t k)
     
    8081    //sort medians and assign id_ and rank_
    8182    sort(median.begin(), median.end(),
    82          pair_value_compare<size_t, double>());
     83         cpptools::pair_value_compare<size_t, double>());
    8384    id_.resize(data.rows());
    8485    rank_.resize(data.rows());
     
    9192   
    9293
    93 }} // of namespace cpptools and namespace theplu
     94}} // of namespace svm and namespace theplu
  • trunk/lib/svm/ConsensusInputRanker.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_consensusinputranker_
    4 #define _theplu_cpptools_consensusinputranker_
     3#ifndef _theplu_svm_consensusinputranker_
     4#define _theplu_svm_consensusinputranker_
    55
    6 // C++ tools include
    7 /////////////////////
    8 #include "InputRanker.h"
    9 #include "matrix.h"
    10 #include "Score.h"
    11 #include "vector.h"
    12 
    13 // Standard C++ includes
    14 ////////////////////////
    15 
     6#include <c++_tools/svm/InputRanker.h>
    167
    178namespace theplu {
    18 namespace cpptools { 
     9  class gslapi::matrix;
     10  class gslapi::vector;
     11  class statistics::Score;
     12namespace svm { 
    1913
    2014  ///
     
    3428    ConsensusInputRanker(const gslapi::matrix& data,
    3529                         const gslapi::vector& target,
    36                          Score&,
     30                         statistics::Score&,
    3731                         const size_t n = 1 ,
    3832                         const size_t k = 3 );
     
    4640                         const gslapi::vector& target,
    4741                         const gslapi::matrix& weight,
    48                          Score&,
     42                         statistics::Score&,
    4943                         const size_t n = 1 ,
    5044                         const size_t k = 3 );
     
    7165  };
    7266
    73 }} // of namespace cpptools and namespace theplu
     67}} // of namespace svm and namespace theplu
    7468
    7569#endif
  • trunk/lib/svm/CrossValidation.cc

    r294 r295  
    11// $Id$
    22
    3 // System includes
     3
     4#include <c++_tools/gslapi/vector.h>
     5#include <c++_tools/svm/CrossValidation.h>
     6#include <c++_tools/utility/random_singleton.h>
     7
    48#include <vector>
    59
    6 // Thep C++ Tools
    7 #include "random_singleton.h"
    8 #include "CrossValidation.h"
    9 
    1010namespace theplu {
    11 namespace cpptools
     11namespace svm
    1212
    1313  CrossValidation::CrossValidation(const theplu::gslapi::vector& target,
     
    2424    }
    2525
    26     my_uniform_rng a;
     26    cpptools::my_uniform_rng a;
    2727    random_shuffle(index_negative_.begin(), index_negative_.end(), a);
    2828    random_shuffle(index_positive_.begin(), index_positive_.end(), a);
     
    3333    if (count_==k_){
    3434      count_=0;
    35       my_uniform_rng a;
     35      cpptools::my_uniform_rng a;
    3636      random_shuffle(index_negative_.begin(), index_negative_.end(), a);
    3737      random_shuffle(index_positive_.begin(), index_positive_.end(), a);
  • trunk/lib/svm/CrossValidation.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_crossvalidation_
    4 #define _theplu_cpptools_crossvalidation_
     3#ifndef _theplu_svm_crossvalidation_
     4#define _theplu_svm_crossvalidation_
    55
    6 // C++ tools include
    7 /////////////////////
    8 #include "vector.h"
    9 
    10 // Standard C++ includes
    11 ////////////////////////
    126#include <vector>
    137
    148namespace theplu {
    15 namespace cpptools { 
     9namespace gslapi {
     10  class vector;
     11}
     12namespace svm { 
    1613
    1714  ///
     
    2421  public:
    2522    ///
    26     /// Constructor taking \a target and \k for k-fold cross validation
     23    /// Constructor taking \a target and \a k for k-fold cross validation
    2724    ///
    2825    CrossValidation(const theplu::gslapi::vector& target, const size_t k = 3);
     
    4643  };
    4744
    48 }} // of namespace cpptools and namespace theplu
     45}} // of namespace svm and namespace theplu
    4946
    5047#endif
  • trunk/lib/svm/GaussianKernelFunction.cc

    r294 r295  
    11// $Id$
    22
    3 // System
     3#include <c++_tools/svm/GaussianKernelFunction.h>
     4
     5#include <c++_tools/svm/KernelFunction.h>
     6#include <c++_tools/gslapi/matrix.h>
     7#include <c++_tools/gslapi/vector.h>
     8
    49#include <math.h>
    510
    6 
    7 // Thep C++ Tools
    8 #include "GaussianKernelFunction.h"
    9 #include "matrix.h"
    10 #include "vector.h"
    11 
    1211namespace theplu {
    13 namespace cpptools
     12namespace svm
    1413
    1514GaussianKernelFunction::GaussianKernelFunction(double sigma)
     
    5352}
    5453
    55 }} // of namespace cpptools and namespace theplu
     54}} // of namespace svn and namespace theplu
  • trunk/lib/svm/GaussianKernelFunction.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_gaussian_kernel_function_
    4 #define _theplu_cpptools_gaussian_kernel_function_
     3#ifndef _theplu_svm_gaussian_kernel_function_
     4#define _theplu_svm_gaussian_kernel_function_
    55
    6 #include "KernelFunction.h"
    7 #include "vector.h"
     6#include <c++_tools/gslapi/vector.h>
     7#include <c++_tools/svm/KernelFunction.h>
     8
     9#include <cmath>
    810
    911namespace theplu {
     12class gslapi::vector;
    1013
    11 namespace gslapi {
    12   class vector;
    13 }
    14 
    15 namespace cpptools {
     14namespace svm {
    1615
    1716  ///
    1817  /// Class for Gaussian kernel calculations.
    1918  ///
    20 
    2119 
    2220  class GaussianKernelFunction : public KernelFunction
     
    4139    inline double operator()(const gslapi::vector& a1,
    4240                             const gslapi::vector& a2)
    43       {return exp(-(a1-a2)*(a1-a2)/pow(sigma_,2));}
     41      {return exp(-(a1-a2)*(a1-a2)/(sigma_*sigma_));}
    4442
     43    ///
    4544    ///returning the scalar product of two vectors in feature space using the
    4645    ///Gaussian kernel with weights.
     
    5251         
    5352    ///
    54     /// @kernel matrix
     53    /// @return kernel matrix
    5554    ///
    5655    const gslapi::matrix& operator()(theplu::gslapi::matrix& kernel,
     
    6261  }; // class GaussianKernelFunction
    6362
    64 }} // of namespace cpptools and namespace theplu
     63}} // of namespace svm and namespace theplu
    6564
    6665#endif
  • trunk/lib/svm/InputRanker.cc

    r294 r295  
    11// $Id$
    22
    3 // Thep C++ Tools
    4 #include "InputRanker.h"
    5 #include "ROC.h"
    6 #include "matrix.h"
    7 #include "vector.h"
    8 #include "stl_utility.h"
     3#include <c++_tools/svm/InputRanker.h>
     4
     5#include <c++_tools/gslapi/matrix.h>
     6#include <c++_tools/gslapi/vector.h>
     7#include <c++_tools/statistics/ROC.h>
     8#include <c++_tools/utility/stl_utility.h>
    99
    1010#include <vector>
     
    1212
    1313namespace theplu {
    14 namespace cpptools
     14namespace svm
    1515
    1616  InputRanker::InputRanker()
     
    2424  InputRanker::InputRanker(const gslapi::matrix& data,
    2525                           const gslapi::vector& target,
    26                            Score& score_object,
     26                           statistics::Score& score_object,
    2727                           const std::vector<size_t>& train_set)
    2828    :train_set_(train_set),
     
    4949    //sort the scores and assign id_ and rank_
    5050    sort(score.begin(), score.end(),
    51          pair_value_compare<size_t, double>());
     51         cpptools::pair_value_compare<size_t, double>());
    5252   
    5353    for (size_t i=0; i<nof_genes; i++){
     
    6060                           const gslapi::vector& target,
    6161                           const gslapi::matrix& weight,
    62                            Score& score_object,
     62                           statistics::Score& score_object,
    6363                           const std::vector<size_t>& train_set)
    6464    :train_set_(train_set),
     
    8484    //sort the scores and assign id_ and rank_
    8585    sort(score.begin(), score.end(),
    86          pair_value_compare<size_t, double>());
     86         cpptools::pair_value_compare<size_t, double>());
    8787
    8888    for (size_t i=0; i<nof_genes; i++){
     
    9292  }
    9393 
    94 }} // of namespace cpptools and namespace theplu
     94}} // of namespace svm and namespace theplu
  • trunk/lib/svm/InputRanker.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_inputranker_
    4 #define _theplu_cpptools_inputranker_
     3#ifndef _theplu_svm_inputranker_
     4#define _theplu_svm_inputranker_
    55
    6 // C++ tools include
    7 /////////////////////
    8 #include "vector.h"
    9 #include "matrix.h"
    10 #include "Score.h"
    11 
    12 // Standard C++ includes
    13 ////////////////////////
    14 
     6#include <vector>
    157
    168namespace theplu {
    17 namespace cpptools { 
     9namespace gslapi {
     10  class matrix;
     11  class vector;
     12}
     13namespace statistics {
     14  class Score;
     15}
     16namespace svm { 
    1817  ///
    1918  /// Class for ranking rows in a matrix, using a Score and a
     
    3635    InputRanker(const gslapi::matrix&,
    3736                const gslapi::vector&,
    38                 Score&,
     37                statistics::Score&,
    3938                const std::vector<size_t>& = std::vector<size_t>());
    4039
     
    4746                const gslapi::vector&,
    4847                const gslapi::matrix&,
    49                 Score&,
     48                statistics::Score&,
    5049                const std::vector<size_t>& = std::vector<size_t>());
    5150
     
    7170  };
    7271
    73 }} // of namespace cpptools and namespace theplu
     72}} // of namespace svm and namespace theplu
    7473
    7574#endif
  • trunk/lib/svm/Kernel.cc

    r294 r295  
    11// $Id$
    22
    3 // Thep C++ Tools
    4 #include "Kernel.h"
    5 #include "KernelFunction.h"
    6 #include "matrix.h"
    7 #include "vector.h"
     3#include <c++_tools/svm/Kernel.h>
     4
     5#include <c++_tools/svm/KernelFunction.h>
     6#include <c++_tools/gslapi/matrix.h>
     7#include <c++_tools/gslapi/vector.h>
    88
    99namespace theplu {
    10 namespace cpptools
     10namespace svm
    1111
    1212Kernel::Kernel(const gslapi::matrix& data, const KernelFunction& kf)
     
    3232
    3333
    34 }} // of namespace cpptools and namespace theplu
     34}} // of namespace svm and namespace theplu
  • trunk/lib/svm/Kernel.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_kernel_
    4 #define _theplu_cpptools_kernel_
     3#ifndef _theplu_svm_kernel_
     4#define _theplu_svm_kernel_
    55
    6 #include "matrix.h"
     6#include <c++_tools/gslapi/matrix.h>
    77
    88namespace theplu {
    9 namespace cpptools {
     9namespace svm {
    1010
    1111  class KernelFunction;
     
    4242  private:
    4343    gslapi::matrix k_;
    44     const theplu::cpptools::KernelFunction* kf_;
     44    const KernelFunction* kf_;
    4545    bool weighted_;
    4646
    4747  }; // class Kernel
    4848
    49 }} // of namespace cpptools and namespace theplu
     49}} // of namespace svm and namespace theplu
    5050
    5151#endif
  • trunk/lib/svm/KernelFunction.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_kernel_function_
    4 #define _theplu_cpptools_kernel_function_
     3#ifndef _theplu_svm_kernel_function_
     4#define _theplu_svm_kernel_function_
    55
    66namespace theplu {
     
    1111}
    1212
    13 namespace cpptools {
     13namespace svm {
    1414
    1515  ///
     
    3030    virtual ~KernelFunction(void) {};
    3131   
     32    ///
     33    /// @return scalar product of two vector in feature space.
     34    ///
    3235    virtual double operator()(const gslapi::vector&,
    3336                              const gslapi::vector&) const = 0;
    3437   
     38    ///
     39    /// @return scalar product of two vector in feature space.
     40    ///
    3541    virtual double operator()(const gslapi::vector&,
    3642                              const gslapi::vector&,
     
    3844                              const gslapi::vector&) const = 0;
    3945   
     46    ///
     47    /// @return kernel matrix
     48    ///
    4049    virtual const theplu::gslapi::matrix& operator()
    4150      (theplu::gslapi::matrix& k, const gslapi::matrix& data) const = 0;
     
    4352  }; // class KernelFunction
    4453
    45 }} // of namespace cpptools and namespace theplu
     54}} // of namespace svm and namespace theplu
    4655
    4756#endif
  • trunk/lib/svm/PolynomialKernelFunction.cc

    r294 r295  
    11// $Id$
    22
    3 // System
     3
     4#include <c++_tools/svm/PolynomialKernelFunction.h>
     5
     6#include <c++_tools/gslapi/matrix.h>
     7#include <c++_tools/gslapi/vector.h>
     8
    49#include <math.h>
    5 
    6 // Thep C++ Tools
    7 #include "PolynomialKernelFunction.h"
    8 #include "matrix.h"
    9 #include "vector.h"
    1010
    1111
    1212namespace theplu {
    13 namespace cpptools
     13namespace svm
    1414
    1515PolynomialKernelFunction::PolynomialKernelFunction(int order)
     
    4848                                     const theplu::gslapi::matrix& data) const
    4949{
    50   theplu::gslapi::matrix data_transposed(data.transpose());
     50  gslapi::matrix data_transposed(data.transpose());
    5151  kernel = data_transposed*data;
    5252  if (order_>1)
  • trunk/lib/svm/PolynomialKernelFunction.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_polynomial_kernel_function_
    4 #define _theplu_cpptools_polynomial_kernel_function_
     3#ifndef _theplu_svm_polynomial_kernel_function_
     4#define _theplu_svm_polynomial_kernel_function_
    55
    6 #include "KernelFunction.h"
     6#include <c++_tools/svm/KernelFunction.h>
    77
    88namespace theplu {
     
    1212}
    1313
    14 namespace cpptools {
     14namespace svm {
    1515
    1616  ///
     
    4949   
    5050    ///
    51     /// @kernel matrix
     51    /// @return kernel matrix
    5252    ///
    5353    const gslapi::matrix& operator()(theplu::gslapi::matrix& kernel,
     
    5959  }; // class PolynomialKernelFunction
    6060
    61 }} // of namespace cpptools and namespace theplu
     61}} // of namespace svm and namespace theplu
    6262
    6363#endif
  • trunk/lib/svm/SVM.cc

    r294 r295  
    11// $Id$
    22
    3 #include "SVM.h"
    4 
    5 // System includes
     3
     4#include <c++_tools/svm/SVM.h>
     5
     6#include <c++_tools/gslapi/matrix.h>
     7#include <c++_tools/gslapi/vector.h>
     8#include <c++_tools/statistics/Averager.h>
     9#include <c++_tools/utility/random_singleton.h>
     10
    611#include <cmath>
    712#include <limits.h>
     
    914#include <vector>
    1015
    11 // Thep C++ Tools
    12 #include "Averager.h"
    13 #include "matrix.h"
    14 #include "random_singleton.h"
    15 #include "vector.h"
    16 
    17 
    1816
    1917namespace theplu {
    20 namespace cpptools
     18namespace svm
    2119
    2220  SVM::SVM(const Kernel& kernel,
     
    7674    for (size_t i=0; i<E.size(); i++)
    7775      tmp[i]=i;
    78     my_uniform_rng a;
     76    cpptools::my_uniform_rng a;
    7977    random_shuffle(tmp.begin(), tmp.end(), a);
    8078    for (size_t i=0; i<tmp.size(); i++){
  • trunk/lib/svm/SVM.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_svm_
    4 #define _theplu_cpptools_svm_
     3#ifndef _theplu_svm_svm_
     4#define _theplu_svm_svm_
    55
    6 // C++ tools include
    7 /////////////////////
    8 #include "Kernel.h"
    9 #include "matrix.h"
    10 #include "vector.h"
     6#include <c++_tools/svm/Kernel.h>
     7#include <c++_tools/gslapi/vector.h>
    118
    12 
    13 // Standard C++ includes
    14 ////////////////////////
    159#include <utility>
    1610#include <vector>
     
    1812
    1913namespace theplu {
    20 namespace cpptools
     14namespace svm
    2115  ///
    2216  /// Class for SVM using Keerthi's second modification of Platt's SMO. Also
     
    3529    /// Constructor taking the kernel matrix and the target vector as input
    3630    ///
    37     SVM(const Kernel&, const gslapi::vector&,
     31    SVM(const Kernel&,
     32        const gslapi::vector&,
    3833        const std::vector<size_t>& = std::vector<size_t>());
    3934         
     
    9085    double bias_;
    9186    double c_;
    92     Kernel kernel_;
     87    Kernel kernel_; // Peter, const ref?
    9388    unsigned long int max_epochs_;
    94     gslapi::vector target_;
     89    gslapi::vector target_; // Peter, const ref?
    9590    bool trained_;
    9691    std::vector<size_t> train_set_;
     
    116111
    117112
    118 }} // of namespace cpptools and namespace theplu
     113}} // of namespace svm and namespace theplu
    119114
    120115#endif
Note: See TracChangeset for help on using the changeset viewer.