Changeset 470 for branches/peters_vector
- Timestamp:
- Dec 19, 2005, 8:46:50 PM (18 years ago)
- Location:
- branches/peters_vector
- Files:
-
- 29 edited
- 8 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/peters_vector/lib/classifier/ConsensusInputRanker.cc
r469 r470 5 5 6 6 #include <c++_tools/classifier/CrossSplitting.h> 7 #include <c++_tools/classifier/ DataView.h>7 #include <c++_tools/classifier/MatrixLookup.h> 8 8 #include <c++_tools/classifier/InputRanker.h> 9 9 #include <c++_tools/classifier/Target.h> … … 19 19 20 20 ConsensusInputRanker::ConsensusInputRanker 21 (const DataView& data, const Target& target,21 (const MatrixLookup& data, const Target& target, 22 22 statistics::Score& score_object, CrossSplitting& sampler, 23 23 const size_t n) … … 27 27 for (size_t i=0; i<n; i++){ 28 28 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), 30 30 Target(target,index), 31 31 score_object) ); … … 55 55 56 56 ConsensusInputRanker::ConsensusInputRanker 57 (const DataView& data, const Target& target, const DataView& weight,57 (const MatrixLookup& data, const Target& target, const MatrixLookup& weight, 58 58 statistics::Score& score_object, CrossSplitting& sampler,const size_t n) 59 59 : nof_rankers_(n) … … 62 62 for (size_t i=0; i<n; i++){ 63 63 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), 65 65 Target(target,index), 66 66 score_object, 67 DataView(weight,index)));67 MatrixLookup(weight,index))); 68 68 } 69 69 -
branches/peters_vector/lib/classifier/ConsensusInputRanker.h
r469 r470 11 11 12 12 class CrossSplitting; 13 class DataView;13 class MatrixLookup; 14 14 class Target; 15 15 … … 28 28 /// manner, and in total there is \a n times \a k ranklists. 29 29 /// 30 ConsensusInputRanker(const DataView& data,30 ConsensusInputRanker(const MatrixLookup& data, 31 31 const Target& target, 32 statistics::Score&, CrossSplitting&, 33 const size_t k = 3 ); 32 statistics::Score&, 33 CrossSplitting&, 34 const size_t n); 34 35 35 36 /// … … 38 39 /// manner, and in total there is \a n times \a k ranklists. 39 40 /// 40 ConsensusInputRanker(const DataView& data,41 ConsensusInputRanker(const MatrixLookup& data, 41 42 const Target& target, 42 const DataView& weight,43 const MatrixLookup& weight, 43 44 statistics::Score&, 44 45 CrossSplitting&, 45 const size_t n = 1);46 const size_t n); 46 47 47 48 /// -
branches/peters_vector/lib/classifier/DataLookup1D.cc
r469 r470 1 1 // $Id$ 2 2 3 #include <c++_tools/classifier/VectorView.h> 4 #include <c++_tools/classifier/VectorAbstract.h> 3 #include <c++_tools/classifier/DataLookup1D.h> 5 4 6 5 namespace theplu { 7 6 namespace classifier { 8 7 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) 11 11 { 12 12 } -
branches/peters_vector/lib/classifier/DataLookup1D.h
r469 r470 1 1 // $Id$ 2 2 3 #ifndef _theplu_classifier_ vectorview_4 #define _theplu_classifier_ vectorview_3 #ifndef _theplu_classifier_dataLookup1D_ 4 #define _theplu_classifier_dataLookup1D_ 5 5 6 #include <c++_tools/classifier/ VectorAbstract.h>6 #include <c++_tools/classifier/DataLookup2D.h> 7 7 8 8 #include <vector> … … 11 11 namespace classifier { 12 12 13 class MatrixView;13 class DataLookup2D; 14 14 15 15 /// … … 17 17 /// 18 18 19 class VectorView : public VectorAbstract19 class DataLookup1D 20 20 { 21 21 … … 25 25 /// Constructor 26 26 /// 27 VectorView(const MatrixView&, const size_t, const bool row);27 DataLookup1D(const DataLookup2D&, const size_t, const bool row); 28 28 29 29 /// 30 30 /// 31 31 /// 32 size_t size(void) const; 32 inline size_t size(void) const 33 { return column_vector_ ? matrix_->rows() : matrix_->columns(); } 33 34 34 35 /// 35 36 /// 36 37 /// 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); } 38 40 39 41 private: 40 VectorView();42 DataLookup1D(); 41 43 42 44 const bool column_vector_; 43 45 const size_t index_; 44 const MatrixView* matrix_;46 const DataLookup2D* matrix_; 45 47 46 48 }; -
branches/peters_vector/lib/classifier/DataLookup2D.cc
r469 r470 1 1 // $Id$ 2 2 3 #include <c++_tools/classifier/ MatrixView.h>3 #include <c++_tools/classifier/DataLookup2D.h> 4 4 5 5 #include <vector> … … 9 9 10 10 11 MatrixView::MatrixView(const MatrixView& m,11 DataLookup2D::DataLookup2D(const DataLookup2D& m, 12 12 const std::vector<size_t>& row, 13 13 const std::vector<size_t>& col) … … 21 21 22 22 23 MatrixView::MatrixView(const MatrixView& m,23 DataLookup2D::DataLookup2D(const DataLookup2D& m, 24 24 const std::vector<size_t>& index, 25 25 const bool row) … … 36 36 37 37 38 MatrixView::MatrixView(const std::vector<size_t>& row,38 DataLookup2D::DataLookup2D(const std::vector<size_t>& row, 39 39 const std::vector<size_t>& col) 40 40 : row_index_(row),column_index_(col) … … 44 44 45 45 46 MatrixView::MatrixView(const std::vector<size_t>& index, bool row)46 DataLookup2D::DataLookup2D(const std::vector<size_t>& index, bool row) 47 47 { 48 48 } 49 49 50 50 51 MatrixView::MatrixView(const MatrixView& mv)51 DataLookup2D::DataLookup2D(const DataLookup2D& mv) 52 52 : row_index_(mv.row_index_),column_index_(mv.column_index_) 53 53 { -
branches/peters_vector/lib/classifier/DataLookup2D.h
r469 r470 1 1 // $Id$ 2 2 3 #ifndef _theplu_classifier_ matrixview_4 #define _theplu_classifier_ matrixview_3 #ifndef _theplu_classifier_DataLookup2D_ 4 #define _theplu_classifier_DataLookup2D_ 5 5 6 6 #include <vector> … … 13 13 /// 14 14 15 class MatrixView15 class DataLookup2D 16 16 { 17 17 … … 22 22 /// as input. 23 23 /// 24 MatrixView(const std::vector<size_t>&, const std::vector<size_t>&);24 DataLookup2D(const std::vector<size_t>&, const std::vector<size_t>&); 25 25 26 26 /// … … 28 28 /// column index vector (default) 29 29 /// 30 MatrixView(const std::vector<size_t>&, bool row=false);30 DataLookup2D(const std::vector<size_t>&, bool row=false); 31 31 32 32 … … 34 34 /// Copy constructor. 35 35 /// 36 MatrixView(const MatrixView&);36 DataLookup2D(const DataLookup2D&); 37 37 38 38 /// 39 39 /// 40 40 /// 41 MatrixView(const MatrixView&, const std::vector<size_t>& row,41 DataLookup2D(const DataLookup2D&, const std::vector<size_t>& row, 42 42 const std::vector<size_t>& col); 43 43 … … 45 45 /// 46 46 /// 47 MatrixView(const MatrixView&, const std::vector<size_t>& index,47 DataLookup2D(const DataLookup2D&, const std::vector<size_t>& index, 48 48 const bool row); 49 49 … … 52 52 /// Destructor 53 53 /// 54 virtual ~ MatrixView() {};54 virtual ~DataLookup2D() {}; 55 55 56 56 /// … … 76 76 /// Default constructor. 77 77 /// 78 MatrixView() {};78 DataLookup2D() {}; 79 79 80 80 }; -
branches/peters_vector/lib/classifier/InputRanker.cc
r469 r470 3 3 #include <c++_tools/classifier/InputRanker.h> 4 4 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> 7 7 #include <c++_tools/classifier/Target.h> 8 8 #include <c++_tools/statistics/ROC.h> … … 16 16 17 17 18 InputRanker::InputRanker(const DataView& data,18 InputRanker::InputRanker(const MatrixLookup& data, 19 19 const Target& target, 20 20 statistics::Score& score_object) 21 21 { 22 22 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(); 29 24 30 25 //scoring each input 31 26 std::vector<std::pair<size_t, double> > score; 32 27 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)); 34 29 std::pair<size_t, double> tmp(i,area); 35 30 score.push_back(tmp); … … 48 43 49 44 50 InputRanker::InputRanker(const DataView& data,45 InputRanker::InputRanker(const MatrixLookup& data, 51 46 const Target& target, 52 47 statistics::Score& score_object, 53 const DataView& weight)48 const MatrixLookup& weight) 54 49 { 55 50 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 62 53 //scoring each input 63 54 std::vector<std::pair<size_t, double> > score; 64 55 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)); 67 58 std::pair<size_t, double> tmp(i,area); 68 59 score.push_back(tmp); -
branches/peters_vector/lib/classifier/InputRanker.h
r469 r470 16 16 namespace classifier { 17 17 18 class DataView;18 class MatrixLookup; 19 19 class Target; 20 20 … … 32 32 /// use all samples) 33 33 /// 34 InputRanker(const DataView&, const Target&, statistics::Score&);34 InputRanker(const MatrixLookup&, const Target&, statistics::Score&); 35 35 36 36 … … 40 40 /// use all samples) 41 41 /// 42 InputRanker(const DataView&, const Target&, statistics::Score&,43 const DataView&);42 InputRanker(const MatrixLookup&, const Target&, statistics::Score&, 43 const MatrixLookup&); 44 44 45 45 … … 58 58 59 59 private: 60 std::vector<size_t> train_set_;61 60 std::vector<size_t> id_; 62 61 std::vector<size_t> rank_; -
branches/peters_vector/lib/classifier/KernelLookup.cc
r468 r470 1 1 // $Id$ 2 2 3 #include <c++_tools/classifier/Kernel View.h>4 #include <c++_tools/classifier/ MatrixView.h>3 #include <c++_tools/classifier/KernelLookup.h> 4 #include <c++_tools/classifier/DataLookup2D.h> 5 5 6 6 … … 8 8 namespace classifier { 9 9 10 Kernel View::KernelView(const Kernel& kernel)11 : MatrixView(), kernel_(&kernel)10 KernelLookup::KernelLookup(const Kernel& kernel) 11 : DataLookup2D(), kernel_(&kernel) 12 12 { 13 13 for(size_t i=0;i<(*kernel_).size();i++) … … 16 16 } 17 17 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, 25 19 const std::vector<size_t>& row, 26 20 const std::vector<size_t>& column) 27 : MatrixView(row,column), kernel_(&kernel)21 : DataLookup2D(row,column), kernel_(&kernel) 28 22 { 29 23 } -
branches/peters_vector/lib/classifier/KernelLookup.h
r468 r470 1 1 // $Id$ 2 2 3 #ifndef _theplu_classifier_kernel_ view_4 #define _theplu_classifier_kernel_ view_3 #ifndef _theplu_classifier_kernel_lookup_ 4 #define _theplu_classifier_kernel_lookup_ 5 5 6 6 #include <c++_tools/classifier/Kernel.h> 7 #include <c++_tools/classifier/ MatrixView.h>7 #include <c++_tools/classifier/DataLookup2D.h> 8 8 #include <vector> 9 9 … … 16 16 /// @brief View into sub Kernel 17 17 /// 18 class Kernel View : public MatrixView18 class KernelLookup : public DataLookup2D 19 19 { 20 20 … … 24 24 /// Constructor 25 25 /// 26 Kernel View(const Kernel&);26 KernelLookup(const Kernel&); 27 27 28 ///29 /// Contructor taking the Kernel to view into, index30 /// vector. Equivalent to KernelView(kernel, index, index).31 ///32 /// @note For training usage row index shall always be equal to33 /// column index.34 ///35 KernelView(const Kernel& kernel, const std::vector<size_t>& index);36 37 28 /// 38 29 /// Contructor taking the Kernel to view into, row index vector, … … 42 33 /// column index. 43 34 /// 44 Kernel View(const Kernel& kernel, const std::vector<size_t>& row,35 KernelLookup(const Kernel& kernel, const std::vector<size_t>& row, 45 36 const std::vector<size_t>& column); 46 37 … … 48 39 /// Copy constructor 49 40 /// 50 Kernel View(const KernelView&);41 KernelLookup(const KernelLookup&); 51 42 52 43 /// … … 63 54 /// Default constructor. Not implemented. 64 55 /// 65 Kernel View(void);56 KernelLookup(void); 66 57 67 58 const Kernel* kernel_; 68 59 69 }; // class Kernel View60 }; // class KernelLookup 70 61 71 62 }} // of namespace classifier and namespace theplu -
branches/peters_vector/lib/classifier/Makefile.am
r469 r470 11 11 ConsensusInputRanker.cc \ 12 12 CrossSplitting.cc \ 13 DataView.cc \ 13 DataLookup1D.cc \ 14 DataLookup2D.cc \ 14 15 GaussianKernelFunction.cc \ 15 16 InputRanker.cc \ 16 17 Kernel_MEV.cc \ 17 18 Kernel_SEV.cc \ 18 Kernel View.cc \19 Matrix View.cc \19 KernelLookup.cc \ 20 MatrixLookup.cc \ 20 21 NCC.cc \ 21 22 PolynomialKernelFunction.cc \ 22 23 SVM.cc \ 23 Target.cc \ 24 VectorView.cc 24 Target.cc 25 25 26 26 … … 30 30 ConsensusInputRanker.h \ 31 31 CrossSplitting.h \ 32 Data View.h \32 DataLookup2D.h \ 33 33 GaussianKernelFunction.h \ 34 34 InputRanker.h \ … … 37 37 Kernel_MEV.h \ 38 38 Kernel_SEV.h \ 39 Kernel View.h \40 Matrix View.h \39 KernelLookup.h \ 40 MatrixLookup.h \ 41 41 NCC.h \ 42 42 PolynomialKernelFunction.h \ 43 43 SVM.h \ 44 44 Target.h \ 45 VectorView.h45 DataLookup1D.h -
branches/peters_vector/lib/classifier/MatrixLookup.cc
r469 r470 1 1 // $Id$ 2 2 3 #include <c++_tools/classifier/ DataView.h>3 #include <c++_tools/classifier/MatrixLookup.h> 4 4 5 5 namespace theplu { 6 6 namespace classifier { 7 7 8 DataView::DataView(const gslapi::matrix& data)9 : MatrixView(), data_(&data)8 MatrixLookup::MatrixLookup(const gslapi::matrix& data) 9 : DataLookup2D(), data_(&data) 10 10 { 11 11 for(size_t i=0;i<(*data_).rows();i++) … … 17 17 18 18 19 DataView::DataView(const gslapi::matrix& data,19 MatrixLookup::MatrixLookup(const gslapi::matrix& data, 20 20 const std::vector<size_t>& row, 21 21 const std::vector<size_t>& col) 22 : MatrixView(row,col), data_(&data)22 : DataLookup2D(row,col), data_(&data) 23 23 { 24 24 } … … 26 26 27 27 28 DataView::DataView(const DataView& data,28 MatrixLookup::MatrixLookup(const MatrixLookup& data, 29 29 const std::vector<size_t>& row, 30 30 const std::vector<size_t>& col) 31 : MatrixView(row,col), data_(data.data_)31 : DataLookup2D(row,col), data_(data.data_) 32 32 { 33 33 } … … 35 35 36 36 37 DataView::DataView(const gslapi::matrix& data,37 MatrixLookup::MatrixLookup(const gslapi::matrix& data, 38 38 const std::vector<size_t>& index, 39 39 const bool row) 40 : MatrixView(index, row), data_(&data)40 : DataLookup2D(index, row), data_(&data) 41 41 { 42 42 } … … 44 44 45 45 46 DataView::DataView(const DataView& data,46 MatrixLookup::MatrixLookup(const MatrixLookup& data, 47 47 const std::vector<size_t>& index, bool row) 48 : MatrixView(index, row), data_(data.data_)48 : DataLookup2D(index, row), data_(data.data_) 49 49 { 50 50 if(row){ … … 65 65 66 66 67 DataView::DataView(const DataView& dv)68 : MatrixView(dv), data_(dv.data_)67 MatrixLookup::MatrixLookup(const MatrixLookup& dv) 68 : DataLookup2D(dv), data_(dv.data_) 69 69 { 70 70 } -
branches/peters_vector/lib/classifier/MatrixLookup.h
r469 r470 1 1 // $Id$ 2 2 3 #ifndef _theplu_classifier_ dataview_4 #define _theplu_classifier_ dataview_3 #ifndef _theplu_classifier_matrix_lookup_ 4 #define _theplu_classifier_matrix_lookup_ 5 5 6 #include <c++_tools/classifier/ MatrixView.h>6 #include <c++_tools/classifier/DataLookup2D.h> 7 7 #include <c++_tools/gslapi/matrix.h> 8 8 … … 17 17 /// 18 18 19 class DataView : public MatrixView19 class MatrixLookup : public DataLookup2D 20 20 { 21 21 … … 26 26 /// Constructor 27 27 /// 28 DataView(const gslapi::matrix&);28 MatrixLookup(const gslapi::matrix&); 29 29 30 30 /// … … 32 32 /// as input. 33 33 /// 34 DataView(const gslapi::matrix&, const std::vector<size_t>&,34 MatrixLookup(const gslapi::matrix&, const std::vector<size_t>&, 35 35 const std::vector<size_t>&); 36 36 … … 39 39 /// as input. 40 40 /// 41 DataView(const gslapi::matrix&, const std::vector<size_t>&,41 MatrixLookup(const gslapi::matrix&, const std::vector<size_t>&, 42 42 bool row=false); 43 43 … … 45 45 /// Copy constructor. 46 46 /// 47 DataView(const DataView&);47 MatrixLookup(const MatrixLookup&); 48 48 49 49 /// … … 51 51 /// as input. 52 52 /// 53 DataView(const DataView&, const std::vector<size_t>&,53 MatrixLookup(const MatrixLookup&, const std::vector<size_t>&, 54 54 const std::vector<size_t>&); 55 55 … … 58 58 /// as input. 59 59 /// 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); 61 61 62 62 /// 63 63 /// Destructor 64 64 /// 65 ~ DataView() {};65 ~MatrixLookup() {}; 66 66 67 67 -
branches/peters_vector/lib/classifier/NCC.cc
r469 r470 3 3 #include <c++_tools/classifier/NCC.h> 4 4 5 #include <c++_tools/classifier/ DataView.h>5 #include <c++_tools/classifier/MatrixLookup.h> 6 6 #include <c++_tools/classifier/Target.h> 7 7 #include <c++_tools/gslapi/vector.h> … … 18 18 namespace classifier { 19 19 20 NCC::NCC(const DataView& data, const Target& target)20 NCC::NCC(const MatrixLookup& data, const Target& target) 21 21 { 22 22 Target sorted_target(target); 23 sorted_target.sort(); // if targets contain NaN => infinite loop23 sorted_target.sort(); 24 24 25 25 // Find the classes of targets -
branches/peters_vector/lib/classifier/NCC.h
r469 r470 18 18 namespace classifier { 19 19 20 class DataView;20 class MatrixLookup; 21 21 class Score; 22 22 class Target; 23 class VectorView;23 class DataLookup1D; 24 24 25 25 /// … … 40 40 /// input. Performs the training of the NCC. 41 41 /// 42 NCC(const DataView&, const Target&);42 NCC(const MatrixLookup&, const Target&); 43 43 44 44 /// -
branches/peters_vector/lib/classifier/SVM.cc
r469 r470 4 4 #include <c++_tools/classifier/SVM.h> 5 5 6 #include <c++_tools/classifier/Kernel View.h>6 #include <c++_tools/classifier/KernelLookup.h> 7 7 #include <c++_tools/gslapi/matrix.h> 8 8 #include <c++_tools/gslapi/vector.h> … … 137 137 } 138 138 139 SVM::SVM(const Kernel View& kernel, const Target& target)139 SVM::SVM(const KernelLookup& kernel, const Target& target) 140 140 : alpha_(target.size(),0), 141 141 bias_(0), -
branches/peters_vector/lib/classifier/SVM.h
r469 r470 4 4 #define _theplu_classifier_svm_ 5 5 6 #include <c++_tools/classifier/Kernel View.h>6 #include <c++_tools/classifier/KernelLookup.h> 7 7 #include <c++_tools/classifier/Target.h> 8 8 #include <c++_tools/gslapi/vector.h> … … 107 107 /// the SVM is no longer defined. 108 108 /// 109 SVM(const Kernel View&, const Target&);109 SVM(const KernelLookup&, const Target&); 110 110 111 111 /// … … 206 206 double bias_; 207 207 double C_inverse_; 208 const Kernel View& kernel_;208 const KernelLookup& kernel_; 209 209 unsigned long int max_epochs_; 210 210 gslapi::vector output_; -
branches/peters_vector/lib/gslapi/vector.cc
r469 r470 5 5 #include <c++_tools/utility/stl_utility.h> 6 6 #include <c++_tools/utility/utility.h> 7 #include <c++_tools/classifier/DataLookup1D.h> 7 8 8 9 #include <sstream> … … 138 139 139 140 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 140 152 vector::~vector(void) 141 153 { … … 178 190 179 191 180 double VectorAbstract::sum(void) const192 double vector::sum(void) const 181 193 { 182 194 double sum = 0; … … 198 210 199 211 200 double VectorAbstract::operator*( const VectorAbstract&other ) const212 double vector::operator*( const vector &other ) const 201 213 { 202 214 double res = 0.0;; -
branches/peters_vector/lib/gslapi/vector.h
r469 r470 14 14 15 15 namespace theplu { 16 namespace classifier { 17 class DataLookup1D; 18 } 16 19 namespace gslapi { 17 20 … … 154 157 /// 155 158 explicit vector(std::istream &, char sep='\0') throw (utility::IO_error,std::exception); 159 160 /// 161 /// 162 /// 163 explicit vector(const classifier::DataLookup1D&); 156 164 157 165 /// -
branches/peters_vector/lib/statistics/Fisher.cc
r469 r470 111 111 112 112 double Fisher::score(const classifier::Target& target, 113 const classifier::VectorAbstract& value)113 const gslapi::vector& value) 114 114 { 115 115 weighted_=false; … … 137 137 138 138 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) 141 141 { 142 142 weighted_=true; -
branches/peters_vector/lib/statistics/Fisher.h
r469 r470 105 105 /// 106 106 double score(const classifier::Target& target, 107 const classifier::VectorAbstract& value);107 const gslapi::vector& value); 108 108 109 109 /// … … 117 117 /// 118 118 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); 121 121 122 122 /// -
branches/peters_vector/lib/statistics/FoldChange.cc
r469 r470 32 32 33 33 double FoldChange::score(const classifier::Target& target, 34 const classifier::VectorAbstract& value)34 const gslapi::vector& value) 35 35 { 36 36 weighted_=false; … … 50 50 51 51 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) 54 54 { 55 55 weighted_=true; -
branches/peters_vector/lib/statistics/FoldChange.h
r469 r470 8 8 namespace theplu { 9 9 10 class classifier::VectorAbstract;10 class gslapi::vector; 11 11 12 12 … … 34 34 /// 35 35 double score(const classifier::Target& target, 36 const classifier::VectorAbstract& value);36 const gslapi::vector& value); 37 37 38 38 /// … … 46 46 /// 47 47 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); 50 50 51 51 private: -
branches/peters_vector/lib/statistics/Pearson.cc
r469 r470 41 41 42 42 double Pearson::score(const classifier::Target& target, 43 const classifier::VectorAbstract& value)43 const gslapi::vector& value) 44 44 { 45 45 weighted_=false; … … 60 60 61 61 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) 64 64 { 65 65 weighted_=true; -
branches/peters_vector/lib/statistics/Pearson.h
r469 r470 39 39 /// 40 40 double score(const classifier::Target& target, 41 const classifier::VectorAbstract& value);41 const gslapi::vector& value); 42 42 43 43 /// … … 51 51 /// 52 52 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); 55 55 56 56 /// -
branches/peters_vector/lib/statistics/ROC.cc
r469 r470 2 2 3 3 #include <c++_tools/statistics/ROC.h> 4 5 4 #include <c++_tools/utility/stl_utility.h> 6 #include <c++_tools/ classifier/VectorAbstract.h>5 #include <c++_tools/gslapi/vector.h> 7 6 8 7 #include <gsl/gsl_cdf.h> … … 15 14 16 15 namespace theplu { 17 class classifier::VectorAbstract;16 class gslapi::vector; 18 17 namespace statistics { 19 18 … … 69 68 70 69 double ROC::score(const classifier::Target& target, 71 const classifier::VectorAbstract& value)70 const gslapi::vector& value) 72 71 { 73 72 weighted_=false; … … 83 82 nof_pos_=0; 84 83 for (size_t i=0; i<n(); i++){ 85 if (class_one( target(i))){84 if (class_one(vec_pair_[i].first)){ 86 85 area_+=i; 87 86 nof_pos_++; … … 101 100 102 101 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) 105 104 { 106 105 weighted_=true; … … 118 117 119 118 for (size_t i=0; i<n(); i++){ 120 if (class_one( target(i))){119 if (class_one(vec_pair_[i].first)){ 121 120 for (size_t j=0; j<n(); j++){ 122 if (!class_one( target(j))){121 if (!class_one(vec_pair_[j].first)){ 123 122 if (value(i) > value(j)){ 124 123 area_+=weight(i)*weight(j); -
branches/peters_vector/lib/statistics/ROC.h
r469 r470 38 38 /// 39 39 double score(const classifier::Target& target, 40 const classifier::VectorAbstract& value);40 const gslapi::vector& value); 41 41 42 42 /// Function taking values, target, weight and a vector defining … … 52 52 /// 53 53 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); 56 56 57 57 -
branches/peters_vector/lib/statistics/Score.h
r469 r470 4 4 #define _theplu_statistics_score_ 5 5 6 #include <c++_tools/gslapi/vector.h> 7 6 8 namespace theplu { 7 9 namespace classifier { 8 10 class Target; 9 class VectorAbstract;11 class DataLookup1D; 10 12 } 11 13 … … 56 58 virtual double 57 59 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)); } 59 77 60 78 /// … … 75 93 virtual double 76 94 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)); } 79 118 80 119 inline bool class_one(int i) const { return i==positive_label_; } -
branches/peters_vector/lib/statistics/WilcoxonFoldChange.cc
r469 r470 2 2 3 3 #include <c++_tools/statistics/WilcoxonFoldChange.h> 4 #include <c++_tools/classifier/VectorAbstract.h>5 4 #include <c++_tools/statistics/utility.h> 6 5 #include <c++_tools/classifier/Target.h> 6 #include <c++_tools/gslapi/vector.h> 7 7 8 8 #include <cmath> … … 21 21 22 22 double WilcoxonFoldChange::score(const classifier::Target& target, 23 const classifier::VectorAbstract& value)23 const gslapi::vector& value) 24 24 { 25 25 std::vector<double> distance; … … 38 38 39 39 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) 42 42 { 43 43 return 0; -
branches/peters_vector/lib/statistics/WilcoxonFoldChange.h
r469 r470 30 30 /// 31 31 double score(const classifier::Target& target, 32 const classifier::VectorAbstract& value);32 const gslapi::vector& value); 33 33 34 34 /// … … 43 43 /// 44 44 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); 47 47 48 48 private: -
branches/peters_vector/lib/statistics/tScore.cc
r469 r470 9 9 #include <c++_tools/statistics/AveragerWeighted.h> 10 10 #include <c++_tools/classifier/Target.h> 11 #include <c++_tools/classifier/VectorAbstract.h>12 11 13 12 namespace theplu { … … 20 19 21 20 double tScore::score(const classifier::Target& target, 22 const classifier::VectorAbstract& value)21 const gslapi::vector& value) 23 22 { 24 23 weighted_=false; … … 43 42 44 43 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) 47 46 { 48 47 weighted_=true; -
branches/peters_vector/lib/statistics/tScore.h
r469 r470 38 38 /// 39 39 double score(const classifier::Target& target, 40 const classifier::VectorAbstract& value);40 const gslapi::vector& value); 41 41 42 42 /// … … 45 45 /// 46 46 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); 49 49 50 50 /// -
branches/peters_vector/test/consensus_inputranker_test.cc
r469 r470 6 6 #include <c++_tools/statistics/ROC.h> 7 7 #include <c++_tools/gslapi/matrix.h> 8 #include <c++_tools/classifier/MatrixLookup.h> 9 #include <c++_tools/classifier/CrossSplitting.h> 8 10 9 11 #include <cstdlib> … … 17 19 { 18 20 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); 20 23 is.close(); 21 24 … … 24 27 is.close(); 25 28 29 26 30 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); 28 33 29 34 if (cir.id(0)!=2 || cir.id(1)!=0 || cir.id(2)!=1){ … … 38 43 39 44 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); 41 47 42 48 if (cir2.id(0)!=2 || cir2.id(1)!=0 || cir2.id(2)!=1){ -
branches/peters_vector/test/inputranker_test.cc
r453 r470 4 4 #include <c++_tools/statistics/ROC.h> 5 5 #include <c++_tools/gslapi/matrix.h> 6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/classifier/MatrixLookup.h> 6 8 7 9 #include <cstdlib> … … 9 11 #include <iostream> 10 12 11 using namespace theplu;12 13 13 int main() 14 { 14 15 int 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 15 29 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; 17 35 is.close(); 18 36 37 *error << "Load target" << std::endl; 19 38 is.open("data/rank_target.txt"); 20 theplu::gslapi::vectortarget(is);39 classifier::Target target(is); 21 40 is.close(); 41 *error << "Done" << std::endl; 22 42 23 43 statistics::ROC roc; 44 *error << "Performing ranking" << std::endl; 24 45 classifier::InputRanker ir(data,target,roc); 25 46 *error << "first test" << std::endl; 26 47 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; 29 50 } 30 51 52 *error << "second test" << std::endl; 31 53 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; 34 56 } 35 57 36 return 0; 58 if (error!=&std::cerr) 59 delete error; 60 61 return (ok ? 0 : -1); 62 37 63 } -
branches/peters_vector/test/kernel_test.cc
r463 r470 9 9 #include <c++_tools/classifier/PolynomialKernelFunction.h> 10 10 #include <c++_tools/classifier/GaussianKernelFunction.h> 11 #include <c++_tools/classifier/Kernel View.h>11 #include <c++_tools/classifier/KernelLookup.h> 12 12 #include <c++_tools/classifier/Kernel_MEV.h> 13 13 #include <c++_tools/classifier/Kernel_SEV.h> … … 36 36 index[1]=2; 37 37 index[2]=3; 38 classifier::Kernel View kv(kernel,index);38 classifier::KernelLookup kv(kernel,index,index); 39 39 if (kv.rows()!=index.size()){ 40 *error << "Error: Kernel View(kernel, index)\n" << std::endl41 << "Size of Kernel Viewis " << kv.rows() << std::endl40 *error << "Error: KernelLookup(kernel, index)\n" << std::endl 41 << "Size of KernelLookup is " << kv.rows() << std::endl 42 42 << "expected " << index.size() << std::endl; 43 43 44 44 return false; 45 45 } 46 classifier::Kernel Viewkv2(kernel);46 classifier::KernelLookup kv2(kernel); 47 47 if (kv2.rows()!=kernel.size()){ 48 *error << "Error: Kernel View(kernel)\n" << std::endl49 << "Size of Kernel Viewis " << kv.rows() << std::endl48 *error << "Error: KernelLookup(kernel)\n" << std::endl 49 << "Size of KernelLookup is " << kv.rows() << std::endl 50 50 << "expected " << kernel.size() << std::endl; 51 51 … … 71 71 index[1]=2; 72 72 index[2]=3; 73 classifier::Kernel View kv(kernel,index);73 classifier::KernelLookup kv(kernel,index, index); 74 74 if (kv.rows()!=index.size()){ 75 *error << "Error: Kernel View(kernel, index)\n" << std::endl76 << "Size of Kernel Viewis " << kv.rows() << std::endl75 *error << "Error: KernelLookup(kernel, index)\n" << std::endl 76 << "Size of KernelLookup is " << kv.rows() << std::endl 77 77 << "expected " << index.size() << std::endl; 78 78 79 79 return false; 80 80 } 81 classifier::Kernel Viewkv2(kernel);81 classifier::KernelLookup kv2(kernel); 82 82 if (kv2.rows()!=kernel.size()){ 83 *error << "Error: Kernel View(kernel)\n" << std::endl84 << "Size of Kernel Viewis " << kv.rows() << std::endl83 *error << "Error: KernelLookup(kernel)\n" << std::endl 84 << "Size of KernelLookup is " << kv.rows() << std::endl 85 85 << "expected " << kernel.size() << std::endl; 86 86 -
branches/peters_vector/test/score_test.cc
r463 r470 32 32 *error << "testing ROC" << std::endl; 33 33 gslapi::vector value(31); 34 gslapi::vectortarget(31,-1);34 classifier::Target target(31,-1); 35 35 for (unsigned int i=0; i<16; i++) 36 36 target(i) = 1; … … 40 40 double area = roc.score(target, value); 41 41 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" 43 43 << std::endl; 44 44 ok = false; … … 70 70 71 71 is.open("data/rank_target.txt"); 72 gslapi::vectortarget2(is);72 classifier::Target target2(is); 73 73 is.close(); 74 74 -
branches/peters_vector/test/svm_test.cc
r463 r470 5 5 #include <c++_tools/classifier/SVM.h> 6 6 #include <c++_tools/classifier/Kernel.h> 7 #include <c++_tools/classifier/KernelLookup.h> 7 8 #include <c++_tools/classifier/Kernel_SEV.h> 8 9 #include <c++_tools/classifier/Kernel_MEV.h> … … 38 39 data2(0,2)=1; 39 40 data2(1,2)=0; 40 gslapi::vectortarget2(3);41 classifier::Target target2(3); 41 42 target2(0)=-1; 42 43 target2(1)=1; … … 46 47 assert(kernel2.size()==3); 47 48 assert(target2.size()==3); 48 classifier::Kernel Viewkv2(kernel2);49 classifier::KernelLookup kv2(kernel2); 49 50 *error << "testing with linear kernel" << std::endl; 50 51 assert(kv2.rows()==target2.size()); … … 54 55 *error << " done." << std::endl; 55 56 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){ 57 62 *error << "condition not fullfilled" << std::endl; 58 63 return -1; … … 80 85 81 86 is.open("data/nm_target_bin.txt"); 82 theplu::gslapi::vectortarget(is);87 classifier::Target target(is); 83 88 is.close(); 84 89 … … 87 92 is.close(); 88 93 89 classifier::Kernel Viewkv(kernel);94 classifier::KernelLookup kv(kernel); 90 95 theplu::classifier::SVM svm(kv, target); 91 96 if (!svm.train()){ … … 108 113 double slack = 0; 109 114 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); 112 117 } 113 118 }
Note: See TracChangeset
for help on using the changeset viewer.