Changeset 461


Ignore:
Timestamp:
Dec 16, 2005, 4:34:37 PM (16 years ago)
Author:
Peter
Message:

?

Location:
trunk/lib
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Makefile.am

    r452 r461  
    22##
    33## $Id$
    4 
    54
    65
  • trunk/lib/classifier/ConsensusInputRanker.cc

    r451 r461  
    66#include <c++_tools/gslapi/matrix.h>
    77#include <c++_tools/statistics/utility.h>
    8 #include <c++_tools/classifier/CrossValidation.h>
     8#include <c++_tools/classifier/CrossSplitting.h>
    99#include <c++_tools/classifier/InputRanker.h>
    1010#include <c++_tools/utility/stl_utility.h>
     
    2525
    2626  {
    27     CrossValidation cv(target, k_);
     27    CrossSplitting cv(target, k_);
    2828    for (size_t i=0; i<nof_rankers_; i++){
    2929      //InputRanker ir(data, target, score_object);
     
    6464
    6565  {
    66     CrossValidation cv(target, k_);
     66    CrossSplitting cv(target, k_);
    6767    for (size_t i=0; i<nof_rankers_; i++)
    6868      input_rankers_.push_back(InputRanker(data,target,weight,score_object,
  • trunk/lib/classifier/KernelView.cc

    r451 r461  
    22
    33#include <c++_tools/classifier/KernelView.h>
    4 
    5 #include <c++_tools/classifier/KernelFunction.h>
     4#include <c++_tools/classifier/MatrixView.h>
    65
    76
     
    98namespace classifier { 
    109
    11   KernelView::KernelView(const Kernel& kernel, const std::vector<size_t>& index)
    12     : Kernel(), kernel_(&kernel), index_(index)
     10  KernelView::KernelView(const Kernel& kernel,
     11                         const std::vector<size_t>& row,
     12                         const std::vector<size_t>& column)
     13    : MatrixView(row,column), kernel_(&kernel)
    1314  {
    1415  }
    1516 
    16   KernelView::KernelView(const KernelView& other)
    17     : Kernel(), kernel_(other.kernel_), index_(other.index_)
    18   {
    19   }
    20 
    21     KernelView::~KernelView(void)
    22   {
    23   } 
    2417
    2518}} // of namespace classifier and namespace theplu
  • trunk/lib/classifier/KernelView.h

    r451 r461  
    55
    66#include <c++_tools/classifier/Kernel.h>
     7#include <c++_tools/classifier/MatrixView.h>
    78#include <vector>
    89
     
    1415  ///
    1516  ///   @brief View into sub Kernel
    16   ///   When training
    1717  ///
    18   class KernelView : public Kernel
     18  class KernelView : public MatrixView
    1919  {
    2020   
     
    2222   
    2323    ///
    24     /// Contructor taking the Kernel to view into and a vector of the
    25     /// indeces we view into. The constructed Kernel matrix will have
    26     /// dimensions \f$NxN\f$ where \f$N\f$ is the size of \a index. If
    27     /// Kernel is a KernelView, as now it implemented to view into the
    28     /// view rather directly into the original Kernel, and may
    29     /// therefore be slow. Use instead the original Kernel and view
    30     /// directly into that.
     24    /// Contructor taking the Kernel to view into, row index vector,
     25    /// and column vector.
    3126    ///
    32     KernelView(const Kernel& kernel, const std::vector<size_t>& index);
     27    /// @note For training usage row index shall always be equal to
     28    /// column index.
     29    ///
     30    KernelView(const Kernel& kernel, const std::vector<size_t>& row,
     31               const std::vector<size_t>& column);
    3332   
    3433    ///
     
    3736    KernelView(const KernelView&);
    3837
    39     ///
    40     ///   Destructor
    41     ///
    42     virtual ~KernelView(void);
    43 
    4438    ///
    4539    /// @return element at position (\a row, \a column) in the Kernel
     
    4741    ///
    4842    inline double operator()(const size_t row,const size_t column) const
    49     { return (*kernel_)(index_[row],index_[column]); }
     43    { return (*kernel_)(row_index_[row],column_index_[column]); }
    5044
    51     ///
    52     /// @brief number of samples
    53     ///
    54     inline size_t size(void) const { return index_.size(); }
    5545   
    5646
     
    6252
    6353    const Kernel* kernel_;
    64     const std::vector<size_t>& index_;
    65 
    66 
    67     inline bool is_view(void) const { return true; }
    6854
    6955  }; // class KernelView
  • trunk/lib/classifier/SVM.cc

    r451 r461  
    44#include <c++_tools/classifier/SVM.h>
    55
    6 #include <c++_tools/classifier/Kernel.h>
     6#include <c++_tools/classifier/KernelView.h>
    77#include <c++_tools/gslapi/matrix.h>
    88#include <c++_tools/gslapi/vector.h>
     
    137137  }
    138138
    139   SVM::SVM(const Kernel& kernel, const gslapi::vector& target)
     139  SVM::SVM(const KernelView& kernel, const gslapi::vector& target)
    140140  : alpha_(target.size(),0),
    141141    bias_(0),
    142142    C_inverse_(0),
    143     kernel_(&kernel),
     143    kernel_(kernel),
    144144    max_epochs_(10000000),
    145145    output_(target.size(),0),
     
    153153  }
    154154
    155   SVM::SVM(const SVM& other)
    156   : alpha_(other.alpha_),
    157     bias_(other.bias_),
    158     C_inverse_(other.C_inverse_),
    159     kernel_(other.kernel_),
    160     max_epochs_(other.max_epochs_),
    161     output_(other.output_),
    162     sample_(other.sample_),
    163     target_(other.target_),
    164     trained_(other.trained_),
    165     tolerance_(other.tolerance_)
    166   {
    167   }
    168 
    169155  bool SVM::train(void)
    170156  {
    171157    // initializing variables for optimization
    172     assert(target_.size()==kernel_->size());
     158    assert(target_.size()==kernel_.rows());
    173159    assert(target_.size()==alpha_.size());
    174160
     
    368354      output_(i)=0;
    369355      for (size_t j=0; j<output_.size(); j++)
    370         output_(i)+=alpha_(j)*target_(j)*(*kernel_)(i,j);
     356        output_(i)+=alpha_(j)*target_(j) * kernel_(i,j);
    371357    }
    372358
  • trunk/lib/classifier/SVM.h

    r451 r461  
    44#define _theplu_classifier_svm_
    55
    6 #include <c++_tools/classifier/Kernel.h>
     6#include <c++_tools/classifier/KernelView.h>
    77#include <c++_tools/gslapi/vector.h>
    88
     
    1414namespace theplu {
    1515namespace classifier { 
    16 
    17   class Kernel;
    1816
    1917  // @internal Class keeping track of which samples are support vectors and
     
    108106    /// the SVM is no longer defined.
    109107    ///
    110     SVM(const Kernel&, const gslapi::vector&);
    111 
    112     ///
    113     /// Copy constructor.
    114     ///
    115     /// @note Copying of kernel (and the data contained in kernel) is
    116     /// copied shallow. Hence, modifying any of these objects in one
    117     /// SVM would modify it in the other SVM.
    118     ///
    119     SVM(const SVM&);
    120          
     108    SVM(const KernelView&, const gslapi::vector&);
     109
    121110    ///
    122111    /// The C-parameter is the balance term (see train()). A very
     
    173162     
    174163  private:
     164    ///
     165    /// Copy constructor. (not implemented)
     166    ///
     167    SVM(const SVM&);
     168         
    175169    ///
    176170    /// Default constructor (not implemented)
     
    206200    ///
    207201    inline double kernel_mod(const size_t i, const size_t j) const
    208     { return i!=j ? (*kernel_)(i,j) : (*kernel_)(i,j) + C_inverse_; }
     202    { return i!=j ? (kernel_)(i,j) : (kernel_)(i,j) + C_inverse_; }
    209203   
    210204    gslapi::vector alpha_;
    211205    double bias_;
    212206    double C_inverse_;
    213     const Kernel* kernel_;
     207    const KernelView& kernel_;
    214208    unsigned long int max_epochs_;
    215209    gslapi::vector output_;
  • trunk/lib/statistics/Makefile.am

    r429 r461  
    1212  LinearWeighted.cc Local.cc \
    1313  MultiDimensional.cc Naive.cc NaiveWeighted.cc OneDimensional.cc\
    14   Pearson.cc Polynomial.cc ROC.cc Score.cc tScore.cc utility.cc
     14  Pearson.cc Polynomial.cc ROC.cc Score.cc tScore.cc utility.cc \
     15  WilcoxonFoldChange.cc
    1516
    1617include_statisticsdir = $(includedir)/c++_tools/statistics
     
    2122  Local.h MultiDimensional.h Naive.h NaiveWeighted.h OneDimensional.h \
    2223  OneDimensionalWeighted.h Pearson.h Polynomial.h ROC.h Score.h tScore.h \
    23   utility.h
     24  utility.h WilcoxonFoldChange.h
Note: See TracChangeset for help on using the changeset viewer.