Changeset 470 for branches/peters_vector


Ignore:
Timestamp:
Dec 19, 2005, 8:46:50 PM (18 years ago)
Author:
Peter
Message:

compiling 3 tests fail

Location:
branches/peters_vector
Files:
29 edited
8 moved

Legend:

Unmodified
Added
Removed
  • branches/peters_vector/lib/classifier/ConsensusInputRanker.cc

    r469 r470  
    55
    66#include <c++_tools/classifier/CrossSplitting.h>
    7 #include <c++_tools/classifier/DataView.h>
     7#include <c++_tools/classifier/MatrixLookup.h>
    88#include <c++_tools/classifier/InputRanker.h>
    99#include <c++_tools/classifier/Target.h>
     
    1919
    2020  ConsensusInputRanker::ConsensusInputRanker
    21   (const DataView& data, const Target& target,
     21  (const MatrixLookup& data, const Target& target,
    2222   statistics::Score& score_object, CrossSplitting& sampler,
    2323   const size_t n)
     
    2727    for (size_t i=0; i<n; i++){
    2828      std::vector<size_t> index=sampler.next();
    29       input_rankers_.push_back(InputRanker(DataView(data,index),
     29      input_rankers_.push_back(InputRanker(MatrixLookup(data,index),
    3030                                           Target(target,index),
    3131                                           score_object)  );
     
    5555
    5656  ConsensusInputRanker::ConsensusInputRanker
    57   (const DataView& data, const Target& target, const DataView& weight,
     57  (const MatrixLookup& data, const Target& target, const MatrixLookup& weight,
    5858   statistics::Score& score_object, CrossSplitting& sampler,const size_t n)
    5959    : nof_rankers_(n)
     
    6262    for (size_t i=0; i<n; i++){
    6363      std::vector<size_t> index=sampler.next();
    64       input_rankers_.push_back(InputRanker(DataView(data,index),
     64      input_rankers_.push_back(InputRanker(MatrixLookup(data,index),
    6565                                           Target(target,index),
    6666                                           score_object,
    67                                            DataView(weight,index)));
     67                                           MatrixLookup(weight,index)));
    6868    }
    6969   
  • branches/peters_vector/lib/classifier/ConsensusInputRanker.h

    r469 r470  
    1111
    1212  class CrossSplitting;
    13   class DataView;
     13  class MatrixLookup;
    1414  class Target;
    1515
     
    2828    /// manner, and in total there is \a n times \a k ranklists.
    2929    ///
    30     ConsensusInputRanker(const DataView& data,
     30    ConsensusInputRanker(const MatrixLookup& data,
    3131                         const Target& target,
    32                          statistics::Score&, CrossSplitting&,
    33                          const size_t k = 3 );
     32                         statistics::Score&,
     33                         CrossSplitting&,
     34                         const size_t n);
    3435
    3536    ///
     
    3839    /// manner, and in total there is \a n times \a k ranklists.
    3940    ///
    40     ConsensusInputRanker(const DataView& data,
     41    ConsensusInputRanker(const MatrixLookup& data,
    4142                         const Target& target,
    42                          const DataView& weight,
     43                         const MatrixLookup& weight,
    4344                         statistics::Score&,
    4445                         CrossSplitting&,
    45                          const size_t n = 1 );
     46                         const size_t n);
    4647
    4748    ///
  • branches/peters_vector/lib/classifier/DataLookup1D.cc

    r469 r470  
    11// $Id$
    22
    3 #include <c++_tools/classifier/VectorView.h>
    4 #include <c++_tools/classifier/VectorAbstract.h>
     3#include <c++_tools/classifier/DataLookup1D.h>
    54
    65namespace theplu {
    76namespace classifier {
    87
    9   VectorView::VectorView(const MatrixView& m, const size_t i, bool row=false)
    10     : VectorAbstract(), column_vector_(row), index_(i), matrix_(&m)
     8  DataLookup1D::DataLookup1D(const DataLookup2D& m, const size_t i,
     9                             const bool column_vector=true)
     10    : column_vector_(column_vector), index_(i), matrix_(&m)
    1111  {
    1212  }
  • branches/peters_vector/lib/classifier/DataLookup1D.h

    r469 r470  
    11// $Id$
    22
    3 #ifndef _theplu_classifier_vectorview_
    4 #define _theplu_classifier_vectorview_
     3#ifndef _theplu_classifier_dataLookup1D_
     4#define _theplu_classifier_dataLookup1D_
    55
    6 #include <c++_tools/classifier/VectorAbstract.h>
     6#include <c++_tools/classifier/DataLookup2D.h>
    77
    88#include <vector>
     
    1111namespace classifier { 
    1212
    13   class MatrixView;
     13  class DataLookup2D;
    1414
    1515  ///
     
    1717  ///
    1818
    19   class VectorView : public VectorAbstract
     19  class DataLookup1D
    2020  {
    2121 
     
    2525    /// Constructor
    2626    ///
    27     VectorView(const MatrixView&, const size_t, const bool row);
     27    DataLookup1D(const DataLookup2D&, const size_t, const bool row);
    2828
    2929    ///
    3030    ///
    3131    ///
    32     size_t size(void) const;
     32    inline size_t size(void) const
     33      { return column_vector_ ? matrix_->rows() : matrix_->columns(); }
    3334
    3435    ///
    3536    ///
    3637    ///
    37     const double& operator()(const size_t) const;
     38    inline double operator()(const size_t i) const
     39    { return column_vector_ ? (*matrix_)(i,index_) : (*matrix_)(index_,i); }
    3840
    3941  private:
    40     VectorView();
     42    DataLookup1D();
    4143
    4244    const bool column_vector_;
    4345    const size_t index_;
    44     const MatrixView* matrix_;
     46    const DataLookup2D* matrix_;
    4547
    4648  }; 
  • branches/peters_vector/lib/classifier/DataLookup2D.cc

    r469 r470  
    11// $Id$
    22
    3 #include <c++_tools/classifier/MatrixView.h>
     3#include <c++_tools/classifier/DataLookup2D.h>
    44
    55#include <vector>
     
    99
    1010
    11   MatrixView::MatrixView(const MatrixView& m,
     11  DataLookup2D::DataLookup2D(const DataLookup2D& m,
    1212                         const std::vector<size_t>& row,
    1313                         const std::vector<size_t>& col)
     
    2121
    2222
    23   MatrixView::MatrixView(const MatrixView& m,
     23  DataLookup2D::DataLookup2D(const DataLookup2D& m,
    2424                         const std::vector<size_t>& index,
    2525                         const bool row)
     
    3636
    3737
    38   MatrixView::MatrixView(const std::vector<size_t>& row,
     38  DataLookup2D::DataLookup2D(const std::vector<size_t>& row,
    3939                         const std::vector<size_t>& col)
    4040    : row_index_(row),column_index_(col)
     
    4444
    4545
    46   MatrixView::MatrixView(const std::vector<size_t>& index, bool row)
     46  DataLookup2D::DataLookup2D(const std::vector<size_t>& index, bool row)
    4747  {
    4848  }
    4949
    5050 
    51   MatrixView::MatrixView(const MatrixView& mv)
     51  DataLookup2D::DataLookup2D(const DataLookup2D& mv)
    5252    : row_index_(mv.row_index_),column_index_(mv.column_index_)
    5353  {
  • branches/peters_vector/lib/classifier/DataLookup2D.h

    r469 r470  
    11// $Id$
    22
    3 #ifndef _theplu_classifier_matrixview_
    4 #define _theplu_classifier_matrixview_
     3#ifndef _theplu_classifier_DataLookup2D_
     4#define _theplu_classifier_DataLookup2D_
    55
    66#include <vector>
     
    1313  ///
    1414
    15   class MatrixView
     15  class DataLookup2D
    1616  {
    1717 
     
    2222    /// as input.
    2323    ///
    24     MatrixView(const std::vector<size_t>&, const std::vector<size_t>&);
     24    DataLookup2D(const std::vector<size_t>&, const std::vector<size_t>&);
    2525
    2626    ///
     
    2828    /// column index vector (default)
    2929    ///
    30     MatrixView(const std::vector<size_t>&, bool row=false);
     30    DataLookup2D(const std::vector<size_t>&, bool row=false);
    3131
    3232
     
    3434    /// Copy constructor.
    3535    ///
    36     MatrixView(const MatrixView&);
     36    DataLookup2D(const DataLookup2D&);
    3737
    3838    ///
    3939    ///
    4040    ///
    41     MatrixView(const MatrixView&, const std::vector<size_t>& row,
     41    DataLookup2D(const DataLookup2D&, const std::vector<size_t>& row,
    4242               const std::vector<size_t>& col);
    4343
     
    4545    ///
    4646    ///
    47     MatrixView(const MatrixView&, const std::vector<size_t>& index,
     47    DataLookup2D(const DataLookup2D&, const std::vector<size_t>& index,
    4848               const bool row);
    4949
     
    5252    /// Destructor
    5353    ///
    54     virtual ~MatrixView() {};
     54    virtual ~DataLookup2D() {};
    5555
    5656    ///
     
    7676    /// Default constructor.
    7777    ///
    78     MatrixView() {};
     78    DataLookup2D() {};
    7979
    8080  }; 
  • branches/peters_vector/lib/classifier/InputRanker.cc

    r469 r470  
    33#include <c++_tools/classifier/InputRanker.h>
    44
    5 #include <c++_tools/classifier/DataView.h>
    6 #include <c++_tools/classifier/VectorView.h>
     5#include <c++_tools/classifier/MatrixLookup.h>
     6#include <c++_tools/classifier/DataLookup1D.h>
    77#include <c++_tools/classifier/Target.h>
    88#include <c++_tools/statistics/ROC.h>
     
    1616
    1717
    18   InputRanker::InputRanker(const DataView& data,
     18  InputRanker::InputRanker(const MatrixLookup& data,
    1919                           const Target& target,
    2020                           statistics::Score& score_object)
    2121  {
    2222    size_t nof_genes = data.rows();
    23     size_t nof_samples = data.columns();
    24     if (!train_set_.size()){
    25       train_set_.resize(nof_samples);
    26       for (size_t i=0; i<nof_samples; i++)
    27         train_set_[i]=i; 
    28     }
     23    //    size_t nof_samples = data.columns();
    2924
    3025    //scoring each input
    3126    std::vector<std::pair<size_t, double> > score;
    3227    for (size_t i=0; i<nof_genes; i++) {
    33       double area = score_object.score(target,VectorView(data,i,false));
     28      double area = score_object.score(target,DataLookup1D(data,i,false));
    3429      std::pair<size_t, double> tmp(i,area);
    3530      score.push_back(tmp);
     
    4843
    4944
    50   InputRanker::InputRanker(const DataView& data,
     45  InputRanker::InputRanker(const MatrixLookup& data,
    5146                           const Target& target,
    5247                           statistics::Score& score_object,
    53                            const DataView& weight)
     48                           const MatrixLookup& weight)
    5449  {
    5550    size_t nof_genes = data.rows();
    56     size_t nof_samples = data.columns();
    57     if (!train_set_.size()){
    58       train_set_.resize(nof_samples);
    59       for (size_t i=0; i<nof_samples; i++)
    60         train_set_[i]=i; 
    61     }
     51    //    size_t nof_samples = data.columns();
     52
    6253    //scoring each input
    6354    std::vector<std::pair<size_t, double> > score;
    6455    for (size_t i=0; i<nof_genes; i++) {
    65       double area = score_object.score(target, VectorView(data,i,false),
    66                                        VectorView(weight,i,false));
     56      double area = score_object.score(target, DataLookup1D(data,i,false),
     57                                       DataLookup1D(weight,i,false));
    6758      std::pair<size_t, double> tmp(i,area);
    6859      score.push_back(tmp);
  • branches/peters_vector/lib/classifier/InputRanker.h

    r469 r470  
    1616namespace classifier { 
    1717
    18   class DataView;
     18  class MatrixLookup;
    1919  class Target;
    2020
     
    3232    /// use all samples)
    3333    ///
    34     InputRanker(const DataView&, const Target&, statistics::Score&);
     34    InputRanker(const MatrixLookup&, const Target&, statistics::Score&);
    3535
    3636
     
    4040    /// use all samples)
    4141    ///
    42     InputRanker(const DataView&, const Target&, statistics::Score&,
    43                 const DataView&);
     42    InputRanker(const MatrixLookup&, const Target&, statistics::Score&,
     43                const MatrixLookup&);
    4444
    4545
     
    5858
    5959  private:
    60     std::vector<size_t> train_set_;
    6160    std::vector<size_t> id_;
    6261    std::vector<size_t> rank_;
  • branches/peters_vector/lib/classifier/KernelLookup.cc

    r468 r470  
    11// $Id$
    22
    3 #include <c++_tools/classifier/KernelView.h>
    4 #include <c++_tools/classifier/MatrixView.h>
     3#include <c++_tools/classifier/KernelLookup.h>
     4#include <c++_tools/classifier/DataLookup2D.h>
    55
    66
     
    88namespace classifier { 
    99
    10   KernelView::KernelView(const Kernel& kernel)
    11     : MatrixView(), kernel_(&kernel)
     10  KernelLookup::KernelLookup(const Kernel& kernel)
     11    : DataLookup2D(), kernel_(&kernel)
    1212  {
    1313    for(size_t i=0;i<(*kernel_).size();i++)
     
    1616  }
    1717 
    18   KernelView::KernelView(const Kernel& kernel,
    19                          const std::vector<size_t>& index)
    20     : MatrixView(index,index), kernel_(&kernel)
    21   {
    22   }
    23  
    24   KernelView::KernelView(const Kernel& kernel,
     18  KernelLookup::KernelLookup(const Kernel& kernel,
    2519                         const std::vector<size_t>& row,
    2620                         const std::vector<size_t>& column)
    27     : MatrixView(row,column), kernel_(&kernel)
     21    : DataLookup2D(row,column), kernel_(&kernel)
    2822  {
    2923  }
  • branches/peters_vector/lib/classifier/KernelLookup.h

    r468 r470  
    11// $Id$
    22
    3 #ifndef _theplu_classifier_kernel_view_
    4 #define _theplu_classifier_kernel_view_
     3#ifndef _theplu_classifier_kernel_lookup_
     4#define _theplu_classifier_kernel_lookup_
    55
    66#include <c++_tools/classifier/Kernel.h>
    7 #include <c++_tools/classifier/MatrixView.h>
     7#include <c++_tools/classifier/DataLookup2D.h>
    88#include <vector>
    99
     
    1616  ///   @brief View into sub Kernel
    1717  ///
    18   class KernelView : public MatrixView
     18  class KernelLookup : public DataLookup2D
    1919  {
    2020   
     
    2424    /// Constructor
    2525    ///
    26     KernelView(const Kernel&);
     26    KernelLookup(const Kernel&);
    2727
    28     ///
    29     /// Contructor taking the Kernel to view into, index
    30     /// vector. Equivalent to KernelView(kernel, index, index).
    31     ///
    32     /// @note For training usage row index shall always be equal to
    33     /// column index.
    34     ///
    35     KernelView(const Kernel& kernel, const std::vector<size_t>& index);
    36    
    3728    ///
    3829    /// Contructor taking the Kernel to view into, row index vector,
     
    4233    /// column index.
    4334    ///
    44     KernelView(const Kernel& kernel, const std::vector<size_t>& row,
     35    KernelLookup(const Kernel& kernel, const std::vector<size_t>& row,
    4536               const std::vector<size_t>& column);
    4637   
     
    4839    /// Copy constructor
    4940    ///
    50     KernelView(const KernelView&);
     41    KernelLookup(const KernelLookup&);
    5142
    5243    ///
     
    6354    /// Default constructor. Not implemented.
    6455    ///
    65     KernelView(void);
     56    KernelLookup(void);
    6657
    6758    const Kernel* kernel_;
    6859
    69   }; // class KernelView
     60  }; // class KernelLookup
    7061
    7162}} // of namespace classifier and namespace theplu
  • branches/peters_vector/lib/classifier/Makefile.am

    r469 r470  
    1111  ConsensusInputRanker.cc \
    1212  CrossSplitting.cc \
    13   DataView.cc \
     13  DataLookup1D.cc \
     14  DataLookup2D.cc \
    1415  GaussianKernelFunction.cc \
    1516  InputRanker.cc \
    1617  Kernel_MEV.cc \
    1718  Kernel_SEV.cc \
    18   KernelView.cc \
    19   MatrixView.cc \
     19  KernelLookup.cc \
     20  MatrixLookup.cc \
    2021  NCC.cc \
    2122  PolynomialKernelFunction.cc \
    2223  SVM.cc \
    23   Target.cc \
    24   VectorView.cc
     24  Target.cc
    2525
    2626
     
    3030  ConsensusInputRanker.h \
    3131  CrossSplitting.h \
    32   DataView.h \
     32  DataLookup2D.h \
    3333  GaussianKernelFunction.h \
    3434  InputRanker.h \
     
    3737  Kernel_MEV.h \
    3838  Kernel_SEV.h \
    39   KernelView.h \
    40   MatrixView.h \
     39  KernelLookup.h \
     40  MatrixLookup.h \
    4141  NCC.h \
    4242  PolynomialKernelFunction.h \
    4343  SVM.h \
    4444  Target.h \
    45   VectorView.h
     45  DataLookup1D.h
  • branches/peters_vector/lib/classifier/MatrixLookup.cc

    r469 r470  
    11// $Id$
    22
    3 #include <c++_tools/classifier/DataView.h>
     3#include <c++_tools/classifier/MatrixLookup.h>
    44
    55namespace theplu {
    66namespace classifier {
    77
    8   DataView::DataView(const gslapi::matrix& data)
    9     : MatrixView(), data_(&data)
     8  MatrixLookup::MatrixLookup(const gslapi::matrix& data)
     9    : DataLookup2D(), data_(&data)
    1010  {
    1111    for(size_t i=0;i<(*data_).rows();i++)
     
    1717
    1818
    19   DataView::DataView(const gslapi::matrix& data,
     19  MatrixLookup::MatrixLookup(const gslapi::matrix& data,
    2020                     const std::vector<size_t>& row,
    2121                     const std::vector<size_t>& col)
    22     : MatrixView(row,col), data_(&data)
     22    : DataLookup2D(row,col), data_(&data)
    2323  {
    2424  }
     
    2626
    2727
    28   DataView::DataView(const DataView& data,
     28  MatrixLookup::MatrixLookup(const MatrixLookup& data,
    2929                     const std::vector<size_t>& row,
    3030                     const std::vector<size_t>& col)
    31     : MatrixView(row,col), data_(data.data_)
     31    : DataLookup2D(row,col), data_(data.data_)
    3232  {
    3333  }
     
    3535
    3636
    37   DataView::DataView(const gslapi::matrix& data,
     37  MatrixLookup::MatrixLookup(const gslapi::matrix& data,
    3838                     const std::vector<size_t>& index,
    3939                     const bool row)
    40     : MatrixView(index, row), data_(&data)
     40    : DataLookup2D(index, row), data_(&data)
    4141  {
    4242  }
     
    4444
    4545
    46   DataView::DataView(const DataView& data,
     46  MatrixLookup::MatrixLookup(const MatrixLookup& data,
    4747                     const std::vector<size_t>& index, bool row)
    48     : MatrixView(index, row), data_(data.data_)
     48    : DataLookup2D(index, row), data_(data.data_)
    4949  {
    5050    if(row){
     
    6565
    6666
    67   DataView::DataView(const DataView& dv)
    68     : MatrixView(dv), data_(dv.data_)
     67  MatrixLookup::MatrixLookup(const MatrixLookup& dv)
     68    : DataLookup2D(dv), data_(dv.data_)
    6969  {
    7070  }
  • branches/peters_vector/lib/classifier/MatrixLookup.h

    r469 r470  
    11// $Id$
    22
    3 #ifndef _theplu_classifier_dataview_
    4 #define _theplu_classifier_dataview_
     3#ifndef _theplu_classifier_matrix_lookup_
     4#define _theplu_classifier_matrix_lookup_
    55
    6 #include <c++_tools/classifier/MatrixView.h>
     6#include <c++_tools/classifier/DataLookup2D.h>
    77#include <c++_tools/gslapi/matrix.h>
    88
     
    1717  ///
    1818
    19   class DataView : public MatrixView
     19  class MatrixLookup : public DataLookup2D
    2020  {
    2121 
     
    2626    /// Constructor
    2727    ///
    28     DataView(const gslapi::matrix&);
     28    MatrixLookup(const gslapi::matrix&);
    2929
    3030    ///
     
    3232    /// as input.
    3333    ///
    34     DataView(const gslapi::matrix&, const std::vector<size_t>&,
     34    MatrixLookup(const gslapi::matrix&, const std::vector<size_t>&,
    3535             const std::vector<size_t>&);
    3636
     
    3939    /// as input.
    4040    ///
    41     DataView(const gslapi::matrix&, const std::vector<size_t>&,
     41    MatrixLookup(const gslapi::matrix&, const std::vector<size_t>&,
    4242             bool row=false);
    4343
     
    4545    /// Copy constructor.
    4646    ///
    47     DataView(const DataView&);
     47    MatrixLookup(const MatrixLookup&);
    4848
    4949    ///
     
    5151    /// as input.
    5252    ///
    53     DataView(const DataView&, const std::vector<size_t>&,
     53    MatrixLookup(const MatrixLookup&, const std::vector<size_t>&,
    5454             const std::vector<size_t>&);
    5555
     
    5858    /// as input.
    5959    ///
    60     DataView(const DataView&, const std::vector<size_t>&, const bool row=false);
     60    MatrixLookup(const MatrixLookup&, const std::vector<size_t>&, const bool row=false);
    6161
    6262    ///
    6363    /// Destructor
    6464    ///
    65     ~DataView() {};
     65    ~MatrixLookup() {};
    6666
    6767   
  • branches/peters_vector/lib/classifier/NCC.cc

    r469 r470  
    33#include <c++_tools/classifier/NCC.h>
    44
    5 #include <c++_tools/classifier/DataView.h>
     5#include <c++_tools/classifier/MatrixLookup.h>
    66#include <c++_tools/classifier/Target.h>
    77#include <c++_tools/gslapi/vector.h>
     
    1818namespace classifier {
    1919
    20   NCC::NCC(const DataView& data, const Target& target)
     20  NCC::NCC(const MatrixLookup& data, const Target& target)
    2121  {
    2222    Target sorted_target(target);
    23     sorted_target.sort(); // if targets contain NaN => infinite loop
     23    sorted_target.sort();
    2424   
    2525    // Find the classes of targets
  • branches/peters_vector/lib/classifier/NCC.h

    r469 r470  
    1818namespace classifier { 
    1919
    20   class DataView;
     20  class MatrixLookup;
    2121  class Score;
    2222  class Target;
    23   class VectorView;
     23  class DataLookup1D;
    2424
    2525  ///
     
    4040    /// input. Performs the training of the NCC.
    4141    ///
    42     NCC(const DataView&, const Target&);
     42    NCC(const MatrixLookup&, const Target&);
    4343
    4444    ///
  • branches/peters_vector/lib/classifier/SVM.cc

    r469 r470  
    44#include <c++_tools/classifier/SVM.h>
    55
    6 #include <c++_tools/classifier/KernelView.h>
     6#include <c++_tools/classifier/KernelLookup.h>
    77#include <c++_tools/gslapi/matrix.h>
    88#include <c++_tools/gslapi/vector.h>
     
    137137  }
    138138
    139   SVM::SVM(const KernelView& kernel, const Target& target)
     139  SVM::SVM(const KernelLookup& kernel, const Target& target)
    140140  : alpha_(target.size(),0),
    141141    bias_(0),
  • branches/peters_vector/lib/classifier/SVM.h

    r469 r470  
    44#define _theplu_classifier_svm_
    55
    6 #include <c++_tools/classifier/KernelView.h>
     6#include <c++_tools/classifier/KernelLookup.h>
    77#include <c++_tools/classifier/Target.h>
    88#include <c++_tools/gslapi/vector.h>
     
    107107    /// the SVM is no longer defined.
    108108    ///
    109     SVM(const KernelView&, const Target&);
     109    SVM(const KernelLookup&, const Target&);
    110110
    111111    ///
     
    206206    double bias_;
    207207    double C_inverse_;
    208     const KernelView& kernel_;
     208    const KernelLookup& kernel_;
    209209    unsigned long int max_epochs_;
    210210    gslapi::vector output_;
  • branches/peters_vector/lib/gslapi/vector.cc

    r469 r470  
    55#include <c++_tools/utility/stl_utility.h>
    66#include <c++_tools/utility/utility.h>
     7#include <c++_tools/classifier/DataLookup1D.h>
    78
    89#include <sstream>
     
    138139
    139140
     141  vector::vector(const classifier::DataLookup1D& data)
     142  {
     143    v_ = gsl_vector_alloc(data.size());
     144    size_t n=0;
     145    for (size_t i=0; i<data.size(); i++)
     146      gsl_vector_set( v_, n++, data(i) );
     147   
     148  }
     149
     150
     151
    140152  vector::~vector(void)
    141153  {
     
    178190
    179191
    180   double VectorAbstract::sum(void) const
     192  double vector::sum(void) const
    181193  {
    182194    double sum = 0;
     
    198210
    199211
    200   double VectorAbstract::operator*( const VectorAbstract &other ) const
     212  double vector::operator*( const vector &other ) const
    201213  {
    202214    double res = 0.0;;
  • branches/peters_vector/lib/gslapi/vector.h

    r469 r470  
    1414
    1515namespace theplu {
     16namespace classifier {
     17  class DataLookup1D;
     18}
    1619namespace gslapi {
    1720
     
    154157    ///
    155158    explicit vector(std::istream &, char sep='\0') throw (utility::IO_error,std::exception);
     159
     160    ///
     161    ///
     162    ///
     163    explicit vector(const classifier::DataLookup1D&);
    156164
    157165    ///
  • branches/peters_vector/lib/statistics/Fisher.cc

    r469 r470  
    111111
    112112    double Fisher::score(const classifier::Target& target,
    113                          const classifier::VectorAbstract& value)
     113                         const gslapi::vector& value)
    114114  {
    115115    weighted_=false;
     
    137137 
    138138    double Fisher::score(const classifier::Target& target,
    139                          const classifier::VectorAbstract& value,
    140                          const classifier::VectorAbstract& weighted)
     139                         const gslapi::vector& value,
     140                         const gslapi::vector& weighted)
    141141  {
    142142    weighted_=true;
  • branches/peters_vector/lib/statistics/Fisher.h

    r469 r470  
    105105    ///
    106106    double score(const classifier::Target& target,
    107                  const classifier::VectorAbstract& value);
     107                 const gslapi::vector& value);
    108108
    109109    ///
     
    117117    ///
    118118    double score(const classifier::Target& target,
    119                  const classifier::VectorAbstract& value,
    120                  const classifier::VectorAbstract& weight);
     119                 const gslapi::vector& value,
     120                 const gslapi::vector& weight);
    121121
    122122    ///
  • branches/peters_vector/lib/statistics/FoldChange.cc

    r469 r470  
    3232
    3333  double FoldChange::score(const classifier::Target& target,
    34                            const classifier::VectorAbstract& value)
     34                           const gslapi::vector& value)
    3535  {
    3636    weighted_=false;
     
    5050
    5151  double FoldChange::score(const classifier::Target& target,
    52                            const classifier::VectorAbstract& value,
    53                            const classifier::VectorAbstract& weight)
     52                           const gslapi::vector& value,
     53                           const gslapi::vector& weight)
    5454  {
    5555    weighted_=true;
  • branches/peters_vector/lib/statistics/FoldChange.h

    r469 r470  
    88namespace theplu {
    99
    10   class classifier::VectorAbstract;
     10  class gslapi::vector;
    1111
    1212
     
    3434    ///
    3535    double score(const classifier::Target& target,
    36                  const classifier::VectorAbstract& value);
     36                 const gslapi::vector& value);
    3737 
    3838    ///
     
    4646    ///
    4747    double score(const classifier::Target& target,
    48                  const classifier::VectorAbstract& value,
    49                  const classifier::VectorAbstract& weight);
     48                 const gslapi::vector& value,
     49                 const gslapi::vector& weight);
    5050 
    5151  private:
  • branches/peters_vector/lib/statistics/Pearson.cc

    r469 r470  
    4141
    4242  double Pearson::score(const classifier::Target& target,
    43                         const classifier::VectorAbstract& value)
     43                        const gslapi::vector& value)
    4444  {
    4545    weighted_=false;
     
    6060   
    6161  double Pearson::score(const classifier::Target& target,
    62                         const classifier::VectorAbstract& value,
    63                         const classifier::VectorAbstract& weight)
     62                        const gslapi::vector& value,
     63                        const gslapi::vector& weight)
    6464  {
    6565    weighted_=true;
  • branches/peters_vector/lib/statistics/Pearson.h

    r469 r470  
    3939    ///
    4040    double score(const classifier::Target& target,
    41                  const classifier::VectorAbstract& value);
     41                 const gslapi::vector& value);
    4242
    4343    ///
     
    5151    ///
    5252    double score(const classifier::Target& target,
    53                  const classifier::VectorAbstract& value,
    54                  const classifier::VectorAbstract& weight);
     53                 const gslapi::vector& value,
     54                 const gslapi::vector& weight);
    5555
    5656    ///
  • branches/peters_vector/lib/statistics/ROC.cc

    r469 r470  
    22
    33#include <c++_tools/statistics/ROC.h>
    4 
    54#include <c++_tools/utility/stl_utility.h>
    6 #include <c++_tools/classifier/VectorAbstract.h>
     5#include <c++_tools/gslapi/vector.h>
    76
    87#include <gsl/gsl_cdf.h>
     
    1514
    1615namespace theplu {
    17   class classifier::VectorAbstract;
     16  class gslapi::vector;
    1817namespace statistics { 
    1918
     
    6968
    7069  double ROC::score(const classifier::Target& target,
    71                     const classifier::VectorAbstract& value)
     70                    const gslapi::vector& value)
    7271  {
    7372    weighted_=false;
     
    8382    nof_pos_=0;
    8483    for (size_t i=0; i<n(); i++){
    85       if (class_one(target(i))){
     84      if (class_one(vec_pair_[i].first)){
    8685        area_+=i;
    8786        nof_pos_++;
     
    101100
    102101  double ROC::score(const classifier::Target& target,
    103                     const classifier::VectorAbstract& value,
    104                     const classifier::VectorAbstract& weight)
     102                    const gslapi::vector& value,
     103                    const gslapi::vector& weight)
    105104  {
    106105    weighted_=true;
     
    118117
    119118    for (size_t i=0; i<n(); i++){
    120       if (class_one(target(i))){
     119      if (class_one(vec_pair_[i].first)){
    121120        for (size_t j=0; j<n(); j++){
    122           if (!class_one(target(j))){
     121          if (!class_one(vec_pair_[j].first)){
    123122            if (value(i) > value(j)){
    124123              area_+=weight(i)*weight(j);
  • branches/peters_vector/lib/statistics/ROC.h

    r469 r470  
    3838    ///
    3939    double score(const classifier::Target& target,
    40                  const classifier::VectorAbstract& value);
     40                 const gslapi::vector& value);
    4141   
    4242    /// Function taking values, target, weight and a vector defining
     
    5252    ///
    5353    double score(const classifier::Target& target,
    54                  const classifier::VectorAbstract& value,
    55                  const classifier::VectorAbstract& weight);
     54                 const gslapi::vector& value,
     55                 const gslapi::vector& weight);
    5656       
    5757
  • branches/peters_vector/lib/statistics/Score.h

    r469 r470  
    44#define _theplu_statistics_score_
    55
     6#include <c++_tools/gslapi/vector.h>
     7
    68namespace theplu {
    79namespace classifier {
    810  class Target;
    9   class VectorAbstract;
     11  class DataLookup1D;
    1012}
    1113
     
    5658    virtual double
    5759    score(const classifier::Target& target,
    58           const classifier::VectorAbstract& value) = 0;
     60          const gslapi::vector& value) = 0;
     61 
     62    ///
     63    /// Function calculating the score. In absolute mode, also the
     64    /// score using negated class labels is calculated, and the
     65    /// largest of the two scores are calculated. Absolute mode should
     66    /// be used when two-tailed test is wanted.
     67    ///
     68    /// @return statistica.
     69    ///
     70    /// @param target vector of targets (most often +1 -1)
     71    /// @param value vector of the values
     72    ///
     73    inline double
     74    score(const classifier::Target& target,
     75          const classifier::DataLookup1D& value)
     76    { return score(target,gslapi::vector(value)); }
    5977 
    6078    ///
     
    7593    virtual double
    7694    score(const classifier::Target& target,
    77           const classifier::VectorAbstract& value,
    78           const classifier::VectorAbstract& weight) = 0;
     95          const gslapi::vector& value,
     96          const gslapi::vector& weight) = 0;
     97
     98    ///
     99    /// Function calculating the weighted version of score. In
     100    /// absolute mode, also the score using negated class labels is
     101    /// calculated, and the largest of the two scores are
     102    /// calculated. Absolute mode should be used when two-tailed test
     103    /// is wanted.
     104    ///
     105    /// @return statistica (weighted version)
     106    ///
     107    /// @param target is +1 or -1
     108    /// @param value vector of the values
     109    /// @param weight vector of accompanied weight to the values
     110    /// @train_set defining which values to use (number of values used
     111    /// in the calculation is equal to size of \a train_set)
     112    ///
     113    inline double
     114    score(const classifier::Target& target,
     115          const classifier::DataLookup1D& value,
     116          const classifier::DataLookup1D& weight)
     117    { return score(target, gslapi::vector(value), gslapi::vector(weight)); }
    79118
    80119    inline bool class_one(int i) const { return i==positive_label_; }
  • branches/peters_vector/lib/statistics/WilcoxonFoldChange.cc

    r469 r470  
    22
    33#include <c++_tools/statistics/WilcoxonFoldChange.h>
    4 #include <c++_tools/classifier/VectorAbstract.h>
    54#include <c++_tools/statistics/utility.h>
    65#include <c++_tools/classifier/Target.h>
     6#include <c++_tools/gslapi/vector.h>
    77
    88#include <cmath>
     
    2121
    2222  double WilcoxonFoldChange::score(const classifier::Target& target,
    23                                    const classifier::VectorAbstract& value)
     23                                   const gslapi::vector& value)
    2424  {
    2525    std::vector<double> distance;
     
    3838
    3939  double WilcoxonFoldChange::score(const classifier::Target& target,
    40                                    const classifier::VectorAbstract& value,
    41                                    const classifier::VectorAbstract& weight)
     40                                   const gslapi::vector& value,
     41                                   const gslapi::vector& weight)
    4242  {
    4343    return 0;
  • branches/peters_vector/lib/statistics/WilcoxonFoldChange.h

    r469 r470  
    3030    ///
    3131    double score(const classifier::Target& target,
    32                  const classifier::VectorAbstract& value);
     32                 const gslapi::vector& value);
    3333 
    3434    ///
     
    4343    ///
    4444    double score(const classifier::Target& target,
    45                  const classifier::VectorAbstract& value,
    46                  const classifier::VectorAbstract& weight);
     45                 const gslapi::vector& value,
     46                 const gslapi::vector& weight);
    4747 
    4848  private:
  • branches/peters_vector/lib/statistics/tScore.cc

    r469 r470  
    99#include <c++_tools/statistics/AveragerWeighted.h>
    1010#include <c++_tools/classifier/Target.h>
    11 #include <c++_tools/classifier/VectorAbstract.h>
    1211
    1312namespace theplu {
     
    2019
    2120  double tScore::score(const classifier::Target& target,
    22                        const classifier::VectorAbstract& value)
     21                       const gslapi::vector& value)
    2322  {
    2423    weighted_=false;
     
    4342
    4443  double tScore::score(const classifier::Target& target,
    45                        const classifier::VectorAbstract& value,
    46                        const classifier::VectorAbstract& weight)
     44                       const gslapi::vector& value,
     45                       const gslapi::vector& weight)
    4746  {
    4847    weighted_=true;
  • branches/peters_vector/lib/statistics/tScore.h

    r469 r470  
    3838    ///
    3939    double score(const classifier::Target& target,
    40                  const classifier::VectorAbstract& value);
     40                 const gslapi::vector& value);
    4141
    4242    ///
     
    4545    ///
    4646    double score(const classifier::Target& target,
    47                  const classifier::VectorAbstract& value,
    48                  const classifier::VectorAbstract& weight);
     47                 const gslapi::vector& value,
     48                 const gslapi::vector& weight);
    4949
    5050    ///
  • branches/peters_vector/test/consensus_inputranker_test.cc

    r469 r470  
    66#include <c++_tools/statistics/ROC.h>
    77#include <c++_tools/gslapi/matrix.h>
     8#include <c++_tools/classifier/MatrixLookup.h>
     9#include <c++_tools/classifier/CrossSplitting.h>
    810
    911#include <cstdlib>
     
    1719
    1820  ifstream is("data/rank_data.txt");
    19   theplu::gslapi::matrix data(is);
     21  theplu::gslapi::matrix data_tmp(is);
     22  theplu::classifier::MatrixLookup data(data_tmp);
    2023  is.close();
    2124
     
    2427  is.close();
    2528
     29 
    2630  theplu::statistics::ROC roc;
    27   theplu::classifier::ConsensusInputRanker cir(data,target,roc,10,3);
     31  theplu::classifier::CrossSplitting sampler(3);
     32  theplu::classifier::ConsensusInputRanker cir(data,target,roc,sampler,30);
    2833
    2934  if (cir.id(0)!=2 || cir.id(1)!=0 || cir.id(2)!=1){
     
    3843
    3944  theplu::gslapi::matrix flag(data.rows(),data.columns(),1);
    40   theplu::classifier::ConsensusInputRanker cir2(data,target,flag,roc,10,3);
     45  theplu::classifier::ConsensusInputRanker
     46    cir2(data,target,flag,roc,sampler,30);
    4147
    4248  if (cir2.id(0)!=2 || cir2.id(1)!=0 || cir2.id(2)!=1){
  • branches/peters_vector/test/inputranker_test.cc

    r453 r470  
    44#include <c++_tools/statistics/ROC.h>
    55#include <c++_tools/gslapi/matrix.h>
     6#include <c++_tools/gslapi/matrix.h>
     7#include <c++_tools/classifier/MatrixLookup.h>
    68
    79#include <cstdlib>
     
    911#include <iostream>
    1012
    11 using namespace theplu;
    1213
    13 int main()
    14 
     14
     15int main(const int argc,const char* argv[])
     16{
     17  using namespace theplu;
     18  std::ostream* error;
     19  if (argc>1 && argv[1]==std::string("-v"))
     20    error = &std::cerr;
     21  else {
     22    error = new std::ofstream("/dev/null");
     23    if (argc>1)
     24      std::cout << "inputranker_test -v : for printing extra information\n";
     25  }
     26  *error << "testing inputranker" << std::endl;
     27  bool ok = true;
     28
    1529  std::ifstream is("data/rank_data.txt");
    16   gslapi::matrix data(is);
     30  *error << "load matrix" << std::endl;
     31  theplu::gslapi::matrix data_tmp(is);
     32  *error << "copy matrix" << std::endl;
     33  theplu::classifier::MatrixLookup data(data_tmp);
     34  *error << "Done" << std::endl;
    1735  is.close();
    1836
     37  *error << "Load target" << std::endl;
    1938  is.open("data/rank_target.txt");
    20   theplu::gslapi::vector target(is);
     39  classifier::Target target(is);
    2140  is.close();
     41  *error << "Done" << std::endl;
    2242
    2343  statistics::ROC roc;
     44  *error << "Performing ranking" << std::endl;
    2445  classifier::InputRanker ir(data,target,roc);
    25 
     46  *error << "first test" << std::endl;
    2647  if (ir.id(0)!=2 || ir.id(1)!=0 || ir.id(2)!=1){
    27     std::cerr << "wrong id" << std::endl;
    28     return -1;
     48    *error << "wrong id" << std::endl;
     49    ok=false;
    2950  }
    3051 
     52  *error << "second test" << std::endl;
    3153  if (ir.rank(0)!=1 || ir.rank(1)!=2 || ir.rank(2)!=0){
    32     std::cerr << "wrong rank" << std::endl;
    33     return -1;
     54    *error << "wrong rank" << std::endl;
     55    ok=false;
    3456  }
    3557 
    36   return 0;
     58  if (error!=&std::cerr)
     59    delete error;
     60
     61  return (ok ? 0 : -1);
     62
    3763}
  • branches/peters_vector/test/kernel_test.cc

    r463 r470  
    99#include <c++_tools/classifier/PolynomialKernelFunction.h>
    1010#include <c++_tools/classifier/GaussianKernelFunction.h>
    11 #include <c++_tools/classifier/KernelView.h>
     11#include <c++_tools/classifier/KernelLookup.h>
    1212#include <c++_tools/classifier/Kernel_MEV.h>
    1313#include <c++_tools/classifier/Kernel_SEV.h>
     
    3636  index[1]=2;
    3737  index[2]=3;
    38   classifier::KernelView kv(kernel,index);
     38  classifier::KernelLookup kv(kernel,index,index);
    3939  if (kv.rows()!=index.size()){
    40     *error << "Error: KernelView(kernel, index)\n" << std::endl
    41            << "Size of KernelView is " << kv.rows() << std::endl
     40    *error << "Error: KernelLookup(kernel, index)\n" << std::endl
     41           << "Size of KernelLookup is " << kv.rows() << std::endl
    4242           << "expected " << index.size() << std::endl;
    4343   
    4444    return false;
    4545  }
    46   classifier::KernelView kv2(kernel);
     46  classifier::KernelLookup kv2(kernel);
    4747  if (kv2.rows()!=kernel.size()){
    48     *error << "Error: KernelView(kernel)\n" << std::endl
    49            << "Size of KernelView is " << kv.rows() << std::endl
     48    *error << "Error: KernelLookup(kernel)\n" << std::endl
     49           << "Size of KernelLookup is " << kv.rows() << std::endl
    5050           << "expected " << kernel.size() << std::endl;
    5151   
     
    7171  index[1]=2;
    7272  index[2]=3;
    73   classifier::KernelView kv(kernel,index);
     73  classifier::KernelLookup kv(kernel,index, index);
    7474  if (kv.rows()!=index.size()){
    75     *error << "Error: KernelView(kernel, index)\n" << std::endl
    76            << "Size of KernelView is " << kv.rows() << std::endl
     75    *error << "Error: KernelLookup(kernel, index)\n" << std::endl
     76           << "Size of KernelLookup is " << kv.rows() << std::endl
    7777           << "expected " << index.size() << std::endl;
    7878   
    7979    return false;
    8080  }
    81   classifier::KernelView kv2(kernel);
     81  classifier::KernelLookup kv2(kernel);
    8282  if (kv2.rows()!=kernel.size()){
    83     *error << "Error: KernelView(kernel)\n" << std::endl
    84            << "Size of KernelView is " << kv.rows() << std::endl
     83    *error << "Error: KernelLookup(kernel)\n" << std::endl
     84           << "Size of KernelLookup is " << kv.rows() << std::endl
    8585           << "expected " << kernel.size() << std::endl;
    8686   
  • branches/peters_vector/test/score_test.cc

    r463 r470  
    3232  *error << "testing ROC" << std::endl;
    3333  gslapi::vector value(31);
    34   gslapi::vector target(31,-1);
     34  classifier::Target target(31,-1);
    3535  for (unsigned int i=0; i<16; i++)
    3636    target(i) = 1;
     
    4040  double area = roc.score(target, value);
    4141  if (area!=1.0){
    42     *error << "test_roc a: area is " << area << " should be 1.0"
     42    *error << "test_roc: area is " << area << " should be 1.0"
    4343           << std::endl;
    4444    ok = false;
     
    7070
    7171  is.open("data/rank_target.txt");
    72   gslapi::vector target2(is);
     72  classifier::Target target2(is);
    7373  is.close();
    7474 
  • branches/peters_vector/test/svm_test.cc

    r463 r470  
    55#include <c++_tools/classifier/SVM.h>
    66#include <c++_tools/classifier/Kernel.h>
     7#include <c++_tools/classifier/KernelLookup.h>
    78#include <c++_tools/classifier/Kernel_SEV.h>
    89#include <c++_tools/classifier/Kernel_MEV.h>
     
    3839  data2(0,2)=1;
    3940  data2(1,2)=0;
    40   gslapi::vector target2(3);
     41  classifier::Target target2(3);
    4142  target2(0)=-1;
    4243  target2(1)=1;
     
    4647  assert(kernel2.size()==3);
    4748  assert(target2.size()==3);
    48   classifier::KernelView kv2(kernel2);
     49  classifier::KernelLookup kv2(kernel2);
    4950  *error << "testing with linear kernel" << std::endl;
    5051  assert(kv2.rows()==target2.size());
     
    5455  *error << " done." << std::endl;
    5556
    56   if (classifier2.alpha()*target2){
     57  double tmp=0;
     58  for (size_t i=0; i<target2.size(); i++)
     59    tmp += classifier2.alpha()(i)*target2(i);
     60 
     61  if (tmp){
    5762    *error << "condition not fullfilled" << std::endl;
    5863    return -1;
     
    8085
    8186  is.open("data/nm_target_bin.txt");
    82   theplu::gslapi::vector target(is);
     87  classifier::Target target(is);
    8388  is.close();
    8489
     
    8792  is.close();
    8893
    89   classifier::KernelView kv(kernel);
     94  classifier::KernelLookup kv(kernel);
    9095  theplu::classifier::SVM svm(kv, target);
    9196  if (!svm.train()){
     
    108113  double slack = 0;
    109114  for (unsigned int i=0; i<target.size(); i++){
    110     if (output[i]*target[i] < 1){
    111       slack += 1 - output[i]*target[i];
     115    if (output(i)*target(i) < 1){
     116      slack += 1 - output(i)*target(i);
    112117    }
    113118  }
Note: See TracChangeset for help on using the changeset viewer.