- Timestamp:
- Aug 31, 2006, 10:52:02 AM (17 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 106 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/c++_tools/Makefile.am
r461 r616 6 6 INCLUDES = @local_includes@ 7 7 8 SUBDIRS = classifier gslapirandom statistics utility8 SUBDIRS = classifier random statistics utility 9 9 10 10 lib_LTLIBRARIES = libc++_tools.la … … 14 14 libc___tools_la_LIBADD = \ 15 15 classifier/libclassifier.la \ 16 gslapi/libgslapi.la \17 16 random/librandom.la \ 18 17 statistics/libstatistics.la \ -
trunk/c++_tools/classifier/ConsensusInputRanker.cc
r615 r616 1 1 // $Id$ 2 3 2 4 3 #include <c++_tools/classifier/ConsensusInputRanker.h> -
trunk/c++_tools/classifier/EnsembleBuilder.cc
r615 r616 9 9 #include <c++_tools/classifier/Target.h> 10 10 11 #include <c++_tools/ gslapi/matrix.h>11 #include <c++_tools/utility/matrix.h> 12 12 13 13 namespace theplu { … … 50 50 51 51 size_t k=0; 52 gslapi::matrix prediction;52 utility::matrix prediction; 53 53 54 54 … … 91 91 92 92 size_t k=0; 93 gslapi::matrix prediction;93 utility::matrix prediction; 94 94 while(subset_.more()) { 95 95 classifier(k++).predict(subset_.validation_data(),prediction); -
trunk/c++_tools/classifier/GaussianKernelFunction.cc
r608 r616 5 5 #include <c++_tools/classifier/KernelFunction.h> 6 6 #include <c++_tools/classifier/DataLookup1D.h> 7 #include <c++_tools/gslapi/matrix.h>8 9 7 10 8 #include <math.h> -
trunk/c++_tools/classifier/GaussianKernelFunction.h
r608 r616 1 // $Id$2 3 1 #ifndef _theplu_classifier_gaussian_kernel_function_ 4 2 #define _theplu_classifier_gaussian_kernel_function_ 5 3 6 #include <c++_tools/gslapi/vector.h> 4 // $Id$ 5 7 6 #include <c++_tools/classifier/KernelFunction.h> 8 7 #include <c++_tools/classifier/DataLookup1D.h> -
trunk/c++_tools/classifier/IGP.cc
r608 r616 7 7 #include <c++_tools/classifier/Target.h> 8 8 #include <c++_tools/classifier/utility.h> 9 #include <c++_tools/ gslapi/vector.h>9 #include <c++_tools/utility/vector.h> 10 10 #include <c++_tools/statistics/Distance.h> 11 11 … … 24 24 25 25 // Calculate IGP for each class 26 igp_= gslapi::vector(target_.nof_classes());26 igp_=utility::vector(target_.nof_classes()); 27 27 for(u_int i=0; i<target_.size(); i++) { 28 28 u_int neighbor=i; 29 29 double mindist=std::numeric_limits<double>::max(); 30 gslapi::vector a;30 utility::vector a; 31 31 convert(DataLookup1D(matrix_,i,false),a); 32 gslapi::vector wa(a.size(),0);32 utility::vector wa(a.size(),0); 33 33 for(size_t k=0; k<a.size(); k++) { // take care of missing values 34 34 if(!std::isnan(a(k))) … … 37 37 38 38 for(u_int j=0; j<target_.size(); j++) { 39 gslapi::vector b;39 utility::vector b; 40 40 convert(DataLookup1D(matrix_,j,false),b); 41 gslapi::vector wb(b.size(),0);41 utility::vector wb(b.size(),0); 42 42 for(size_t k=0; k<b.size(); k++) { // take care of missing values 43 43 if(!std::isnan(b(k))) -
trunk/c++_tools/classifier/IGP.h
r608 r616 1 // $Id$2 3 1 #ifndef _theplu_classifier_igp_ 4 2 #define _theplu_classifier_igp_ 5 3 6 #include <c++_tools/gslapi/matrix.h> 4 // $Id$ 5 6 #include <c++_tools/utility/vector.h> 7 7 8 8 namespace theplu { … … 39 39 /// @return the IGP score for each class as elements in a vector. 40 40 /// 41 const gslapi::vector& score(void) const {return igp_;}41 const utility::vector& score(void) const {return igp_;} 42 42 43 43 44 44 private: 45 gslapi::vector igp_;45 utility::vector igp_; 46 46 47 47 const statistics::Distance& distance_; -
trunk/c++_tools/classifier/Kernel.h
r608 r616 1 // $Id$2 3 1 #ifndef _theplu_classifier_kernel_ 4 2 #define _theplu_classifier_kernel_ 5 3 6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/gslapi/vector.h> 4 // $Id$ 5 8 6 #include <c++_tools/classifier/KernelFunction.h> 9 7 #include <c++_tools/classifier/MatrixLookup.h> -
trunk/c++_tools/classifier/KernelWeighted_SEV.cc
r608 r616 7 7 #include <c++_tools/classifier/KernelFunction.h> 8 8 #include <c++_tools/classifier/MatrixLookup.h> 9 #include <c++_tools/gslapi/matrix.h> 10 #include <c++_tools/gslapi/vector.h> 9 #include <c++_tools/utility/matrix.h> 11 10 12 11 #include <cassert> … … 37 36 void KernelWeighted_SEV::build_kernel(void) 38 37 { 39 kernel_matrix_ = gslapi::matrix(data_->columns(),data_->columns());38 kernel_matrix_ = utility::matrix(data_->columns(),data_->columns()); 40 39 for (size_t i=0; i<kernel_matrix_.rows(); i++) 41 40 for (size_t j=i; j<kernel_matrix_.columns(); j++) -
trunk/c++_tools/classifier/KernelWeighted_SEV.h
r608 r616 1 // $Id$2 3 1 #ifndef _theplu_classifier_kernel_weighted_sev_ 4 2 #define _theplu_classifier_kernel_weighted_sev_ 3 4 // $Id$ 5 5 6 6 #include <c++_tools/classifier/DataLookup1D.h> 7 7 #include <c++_tools/classifier/Kernel.h> 8 8 #include <c++_tools/classifier/MatrixLookup.h> 9 #include <c++_tools/gslapi/matrix.h> 10 #include <c++_tools/gslapi/vector.h> 9 #include <c++_tools/utility/matrix.h> 11 10 12 11 … … 114 113 void build_kernel(void); 115 114 116 gslapi::matrix kernel_matrix_;115 utility::matrix kernel_matrix_; 117 116 118 117 }; // class Kernel_SEV -
trunk/c++_tools/classifier/Kernel_MEV.h
r608 r616 1 // $Id$2 3 1 #ifndef _theplu_classifier_kernel_mev_ 4 2 #define _theplu_classifier_kernel_mev_ 3 4 // $Id$ 5 5 6 6 #include <c++_tools/classifier/DataLookup1D.h> 7 7 #include <c++_tools/classifier/Kernel.h> 8 8 #include <c++_tools/classifier/KernelFunction.h> 9 #include <c++_tools/gslapi/vector.h>10 #include <c++_tools/gslapi/matrix.h>11 9 12 10 namespace theplu { -
trunk/c++_tools/classifier/Kernel_SEV.cc
r608 r616 7 7 #include <c++_tools/classifier/KernelFunction.h> 8 8 #include <c++_tools/classifier/MatrixLookup.h> 9 #include <c++_tools/gslapi/matrix.h> 10 #include <c++_tools/gslapi/vector.h> 9 #include <c++_tools/utility/matrix.h> 11 10 12 11 namespace theplu { … … 30 29 void Kernel_SEV::build_kernel(void) 31 30 { 32 kernel_matrix_ = gslapi::matrix(data_->columns(),data_->columns());31 kernel_matrix_ = utility::matrix(data_->columns(),data_->columns()); 33 32 for (size_t i=0; i<kernel_matrix_.rows(); i++) 34 33 for (size_t j=i; j<kernel_matrix_.columns(); j++) -
trunk/c++_tools/classifier/Kernel_SEV.h
r608 r616 1 // $Id$2 3 1 #ifndef _theplu_classifier_kernel_sev_ 4 2 #define _theplu_classifier_kernel_sev_ 5 3 4 // $Id$ 5 6 6 #include <c++_tools/classifier/Kernel.h> 7 #include <c++_tools/ gslapi/matrix.h>7 #include <c++_tools/utility/matrix.h> 8 8 9 9 … … 89 89 void build_kernel(void); 90 90 91 gslapi::matrix kernel_matrix_;91 utility::matrix kernel_matrix_; 92 92 93 93 }; // class Kernel_SEV -
trunk/c++_tools/classifier/MatrixLookup.cc
r608 r616 2 2 3 3 #include <c++_tools/classifier/MatrixLookup.h> 4 5 #include <c++_tools/utility/matrix.h> 4 6 5 7 #ifndef NDEBUG … … 12 14 namespace classifier { 13 15 14 MatrixLookup::MatrixLookup(const gslapi::matrix& data)16 MatrixLookup::MatrixLookup(const utility::matrix& data) 15 17 : DataLookup2D(), data_(&data) 16 18 { … … 23 25 24 26 25 MatrixLookup::MatrixLookup(const gslapi::matrix& data,27 MatrixLookup::MatrixLookup(const utility::matrix& data, 26 28 const std::vector<size_t>& row, 27 29 const std::vector<size_t>& col) … … 38 40 39 41 40 MatrixLookup::MatrixLookup(const gslapi::matrix& data,42 MatrixLookup::MatrixLookup(const utility::matrix& data, 41 43 const std::vector<size_t>& index, 42 44 const bool row) … … 101 103 : DataLookup2D(rows,columns, true) 102 104 { 103 data_ = new gslapi::matrix(1,1,value);105 data_ = new utility::matrix(1,1,value); 104 106 } 105 107 … … 108 110 : DataLookup2D(true) 109 111 { 110 data_ = new gslapi::matrix(is,sep);112 data_ = new utility::matrix(is,sep); 111 113 for(size_t i=0;i<(*data_).rows();i++) 112 114 row_index_.push_back(i); -
trunk/c++_tools/classifier/MatrixLookup.h
r608 r616 1 // $Id$2 3 1 #ifndef _theplu_classifier_matrix_lookup_ 4 2 #define _theplu_classifier_matrix_lookup_ 5 3 4 // $Id$ 5 6 6 #include <c++_tools/classifier/DataLookup2D.h> 7 #include <c++_tools/ gslapi/matrix.h>7 #include <c++_tools/utility/matrix.h> 8 8 9 9 #include <cassert> … … 48 48 /// undefined. 49 49 /// 50 explicit MatrixLookup(const gslapi::matrix& matrix);50 explicit MatrixLookup(const utility::matrix& matrix); 51 51 52 52 /// … … 63 63 /// undefined. 64 64 /// 65 MatrixLookup(const gslapi::matrix& matrix, const std::vector<size_t>& row,65 MatrixLookup(const utility::matrix& matrix, const std::vector<size_t>& row, 66 66 const std::vector<size_t>& column); 67 67 … … 83 83 /// undefined. 84 84 /// 85 MatrixLookup(const gslapi::matrix& matrix,85 MatrixLookup(const utility::matrix& matrix, 86 86 const std::vector<size_t>& index, 87 87 const bool row_vectors); … … 246 246 247 247 private: 248 const gslapi::matrix* data_;248 const utility::matrix* data_; 249 249 }; 250 250 -
trunk/c++_tools/classifier/MatrixLookupWeighted.cc
r611 r616 2 2 3 3 #include <c++_tools/classifier/MatrixLookupWeighted.h> 4 5 #include <c++_tools/utility/matrix.h> 4 6 5 7 #ifndef NDEBUG … … 12 14 namespace classifier { 13 15 14 MatrixLookupWeighted::MatrixLookupWeighted(const gslapi::matrix& data,15 const gslapi::matrix& weights)16 MatrixLookupWeighted::MatrixLookupWeighted(const utility::matrix& data, 17 const utility::matrix& weights) 16 18 : DataLookup2D(), data_(&data), weights_(&weights) 17 19 { … … 26 28 27 29 28 MatrixLookupWeighted::MatrixLookupWeighted(const gslapi::matrix& data,29 const gslapi::matrix& weights,30 const std::vector<size_t>& row,31 const std::vector<size_t>& col)30 MatrixLookupWeighted::MatrixLookupWeighted(const utility::matrix& data, 31 const utility::matrix& weights, 32 const std::vector<size_t>& row, 33 const std::vector<size_t>& col) 32 34 : DataLookup2D(row,col), data_(&data), weights_(&weights) 33 35 { … … 48 50 49 51 50 MatrixLookupWeighted::MatrixLookupWeighted(const gslapi::matrix& data,51 const gslapi::matrix& weights,52 const std::vector<size_t>& index,53 const bool row)52 MatrixLookupWeighted::MatrixLookupWeighted(const utility::matrix& data, 53 const utility::matrix& weights, 54 const std::vector<size_t>& index, 55 const bool row) 54 56 : DataLookup2D(), data_(&data), weights_(&weights) 55 57 { … … 135 137 : DataLookup2D(rows,columns, true) 136 138 { 137 data_ = new gslapi::matrix(1,1,value);138 weights_ = new gslapi::matrix(1,1,1.0);139 data_ = new utility::matrix(1,1,value); 140 weights_ = new utility::matrix(1,1,1.0); 139 141 } 140 142 … … 143 145 : DataLookup2D(true) 144 146 { 145 data_ = new gslapi::matrix(is,sep);147 data_ = new utility::matrix(is,sep); 146 148 for(size_t i=0;i<(*data_).rows();i++) 147 149 row_index_.push_back(i); 148 150 for(size_t i=0;i<(*data_).columns();i++) 149 151 column_index_.push_back(i); 150 gslapi::matrix weights;152 utility::matrix weights; 151 153 data_->nan(weights); 152 weights_= new gslapi::matrix(weights);154 weights_= new utility::matrix(weights); 153 155 } 154 156 -
trunk/c++_tools/classifier/MatrixLookupWeighted.h
r608 r616 1 // $Id$2 3 1 #ifndef _theplu_classifier_matrix_lookup_weighted_ 4 2 #define _theplu_classifier_matrix_lookup_weighted_ 5 3 4 // $Id$ 5 6 6 #include <c++_tools/classifier/DataLookup2D.h> 7 #include <c++_tools/ gslapi/matrix.h>7 #include <c++_tools/utility/matrix.h> 8 8 9 9 #include <cassert> … … 45 45 /// result of further use is undefined. 46 46 /// 47 MatrixLookupWeighted(const gslapi::matrix& matrix,48 const gslapi::matrix& weights);47 MatrixLookupWeighted(const utility::matrix& matrix, 48 const utility::matrix& weights); 49 49 50 50 /// … … 63 63 /// undefined. 64 64 /// 65 MatrixLookupWeighted(const gslapi::matrix& matrix,66 const gslapi::matrix& weights,65 MatrixLookupWeighted(const utility::matrix& matrix, 66 const utility::matrix& weights, 67 67 const std::vector<size_t>& row, 68 68 const std::vector<size_t>& column); … … 86 86 /// result of further use is undefined. 87 87 /// 88 MatrixLookupWeighted(const gslapi::matrix& matrix,89 const gslapi::matrix& weights,88 MatrixLookupWeighted(const utility::matrix& matrix, 89 const utility::matrix& weights, 90 90 const std::vector<size_t>& index, 91 91 const bool row_vectors); … … 269 269 270 270 private: 271 const gslapi::matrix* data_;272 const gslapi::matrix* weights_;271 const utility::matrix* data_; 272 const utility::matrix* weights_; 273 273 }; 274 274 -
trunk/c++_tools/classifier/NCC.cc
r615 r616 9 9 #include <c++_tools/classifier/SubsetGenerator.h> 10 10 #include <c++_tools/classifier/Target.h> 11 #include <c++_tools/gslapi/vector.h> 11 #include <c++_tools/utility/matrix.h> 12 #include <c++_tools/utility/vector.h> 12 13 #include <c++_tools/statistics/Distance.h> 13 14 #include <c++_tools/utility/stl_utility.h> … … 101 102 rows=nof_inputs_; 102 103 } 103 centroids_= gslapi::matrix(rows, target_.nof_classes());104 gslapi::matrix nof_in_class(rows, target_.nof_classes());104 centroids_=utility::matrix(rows, target_.nof_classes()); 105 utility::matrix nof_in_class(rows, target_.nof_classes()); 105 106 for(size_t i=0; i<rows; i++) { 106 107 for(size_t j=0; j<matrix_.columns(); j++) { … … 124 125 125 126 void NCC::predict(const DataLookup1D& input, 126 gslapi::vector& prediction) const127 utility::vector& prediction) const 127 128 { 128 prediction= gslapi::vector(centroids_.columns());129 prediction=utility::vector(centroids_.columns()); 129 130 size_t size=input.size(); 130 131 if(ranker_) 131 132 size=nof_inputs_; 132 gslapi::vector w(size,0);133 gslapi::vector value(size,0);133 utility::vector w(size,0); 134 utility::vector value(size,0); 134 135 for(size_t i=0; i<size; i++) { // take care of missing values 135 136 value(i)=input(i); … … 140 141 } 141 142 for(size_t j=0; j<centroids_.columns(); j++) { 142 gslapi::vector centroid=gslapi::vector(centroids_,j,false);143 gslapi::vector wc(centroid.size(),0);143 utility::vector centroid=utility::vector(centroids_,j,false); 144 utility::vector wc(centroid.size(),0); 144 145 for(size_t i=0; i<centroid.size(); i++) { // take care of missing values 145 146 if(!std::isnan(centroid(i))) … … 152 153 153 154 void NCC::predict(const DataLookup2D& input, 154 gslapi::matrix& prediction) const155 utility::matrix& prediction) const 155 156 { 156 prediction= gslapi::matrix(centroids_.columns(), input.columns());157 prediction=utility::matrix(centroids_.columns(), input.columns()); 157 158 for(size_t j=0; j<input.columns();j++) { 158 159 DataLookup1D in(input,j,false); 159 gslapi::vector out;160 utility::vector out; 160 161 predict(in,out); 161 162 prediction.set_column(j,out); -
trunk/c++_tools/classifier/NCC.h
r615 r616 1 // $Id$2 3 1 #ifndef _theplu_classifier_ncc_ 4 2 #define _theplu_classifier_ncc_ 5 3 6 #include <c++_tools/gslapi/matrix.h> 4 // $Id$ 5 6 #include <c++_tools/utility/matrix.h> 7 7 8 8 #include <c++_tools/classifier/SupervisedClassifier.h> … … 11 11 12 12 namespace theplu { 13 14 namespace utlitity { 15 class vector; 16 } 13 17 14 18 namespace statistics { … … 73 77 /// @return the centroids for each class as columns in a matrix. 74 78 /// 75 const gslapi::matrix& centroids(void) const {return centroids_;}79 const utility::matrix& centroids(void) const {return centroids_;} 76 80 77 81 inline SupervisedClassifier* … … 90 94 /// Calculate the distance to each centroid for a test sample 91 95 /// 92 void predict(const DataLookup1D&, gslapi::vector&) const;96 void predict(const DataLookup1D&, utility::vector&) const; 93 97 94 98 /// 95 99 /// Calculate the distance to each centroid for test samples 96 100 /// 97 void predict(const DataLookup2D&, gslapi::matrix&) const;101 void predict(const DataLookup2D&, utility::matrix&) const; 98 102 99 103 100 104 private: 101 gslapi::matrix centroids_;105 utility::matrix centroids_; 102 106 const statistics::Distance& distance_; 103 107 const MatrixLookup& matrix_; -
trunk/c++_tools/classifier/PolynomialKernelFunction.cc
r608 r616 5 5 #include <c++_tools/classifier/DataLookup1D.h> 6 6 7 #include <c++_tools/gslapi/matrix.h>8 #include <c++_tools/gslapi/vector.h>9 7 #include <c++_tools/statistics/AveragerPairWeighted.h> 10 8 -
trunk/c++_tools/classifier/SVM.cc
r615 r616 6 6 #include <c++_tools/classifier/InputRanker.h> 7 7 #include <c++_tools/classifier/SubsetGenerator.h> 8 #include <c++_tools/gslapi/matrix.h> 9 #include <c++_tools/gslapi/vector.h> 8 #include <c++_tools/random/random.h> 10 9 #include <c++_tools/statistics/Averager.h> 11 10 #include <c++_tools/statistics/Score.h> 12 #include <c++_tools/random/random.h> 11 #include <c++_tools/utility/matrix.h> 12 #include <c++_tools/utility/vector.h> 13 13 14 14 #include <algorithm> … … 133 133 } 134 134 135 void SVM::predict(const DataLookup2D& input, gslapi::matrix& prediction) const135 void SVM::predict(const DataLookup2D& input, utility::matrix& prediction) const 136 136 { 137 137 // Peter, should check success of dynamic_cast … … 150 150 151 151 assert(input.rows()==alpha_.size()); 152 prediction = gslapi::matrix(2,input.columns(),0);152 prediction = utility::matrix(2,input.columns(),0); 153 153 for (size_t i = 0; i<input.columns(); i++){ 154 154 for (size_t j = 0; j<input.rows(); j++){ … … 192 192 193 193 sample_.init(alpha_,tolerance_); 194 gslapi::vector E(target_.size(),0);194 utility::vector E(target_.size(),0); 195 195 for (size_t i=0; i<E.size(); i++) { 196 196 for (size_t j=0; j<E.size(); j++) … … 275 275 276 276 277 bool SVM::choose(const theplu:: gslapi::vector& E)277 bool SVM::choose(const theplu::utility::vector& E) 278 278 { 279 279 // First check for violation among SVs … … 420 420 } 421 421 422 void Index::init(const gslapi::vector& alpha, const double tol)422 void Index::init(const utility::vector& alpha, const double tol) 423 423 { 424 424 nof_sv_=0; -
trunk/c++_tools/classifier/SVM.h
r615 r616 1 // $Id$2 3 1 #ifndef _theplu_classifier_svm_ 4 2 #define _theplu_classifier_svm_ 3 4 // $Id$ 5 5 6 6 #include <c++_tools/classifier/DataLookup2D.h> … … 8 8 #include <c++_tools/classifier/SupervisedClassifier.h> 9 9 #include <c++_tools/classifier/Target.h> 10 #include <c++_tools/ gslapi/vector.h>10 #include <c++_tools/utility/vector.h> 11 11 12 12 #include <cassert> … … 44 44 45 45 // synch the object against alpha 46 void init(const gslapi::vector& alpha, const double);46 void init(const utility::vector& alpha, const double); 47 47 48 48 // @return nof samples … … 144 144 /// @return \f$ \alpha \f$ 145 145 /// 146 inline const gslapi::vector& alpha(void) const { return alpha_; }146 inline const utility::vector& alpha(void) const { return alpha_; } 147 147 148 148 /// … … 175 175 /// @return output 176 176 /// 177 inline const theplu:: gslapi::vector& output(void) const { return output_; }177 inline const theplu::utility::vector& output(void) const { return output_; } 178 178 179 179 /// … … 193 193 /// @note 194 194 /// 195 void predict(const DataLookup2D& input, gslapi::matrix& predict) const;195 void predict(const DataLookup2D& input, utility::matrix& predict) const; 196 196 197 197 /// … … 211 211 /// 212 212 inline void reset(void) 213 { trained_=false; alpha_= gslapi::vector(target_.size(),0); }213 { trained_=false; alpha_=utility::vector(target_.size(),0); } 214 214 215 215 /// … … 262 262 /// can be found 263 263 /// 264 bool choose(const theplu:: gslapi::vector&);264 bool choose(const theplu::utility::vector&); 265 265 266 266 /// … … 273 273 inline int target(size_t i) const { return target_.binary(i) ? 1 : -1; } 274 274 275 gslapi::vector alpha_;275 utility::vector alpha_; 276 276 double bias_; 277 277 double C_inverse_; … … 279 279 double margin_; 280 280 unsigned long int max_epochs_; 281 gslapi::vector output_;281 utility::vector output_; 282 282 bool owner_; 283 283 Index sample_; -
trunk/c++_tools/classifier/SupervisedClassifier.h
r615 r616 1 // $Id$2 3 1 #ifndef _theplu_classifier_supervisedclassifier_ 4 2 #define _theplu_classifier_supervisedclassifier_ 3 4 // $Id$ 5 5 6 6 #include <stddef.h> … … 8 8 namespace theplu { 9 9 10 namespace gslapi { 11 class vector; 10 namespace utility { 12 11 class matrix; 13 12 } … … 71 70 /// Generate output values for a data set 72 71 /// 73 virtual void predict(const DataLookup2D&, gslapi::matrix&) const =0;72 virtual void predict(const DataLookup2D&, utility::matrix&) const =0; 74 73 75 74 -
trunk/c++_tools/classifier/utility.cc
r608 r616 5 5 6 6 #include <c++_tools/classifier/DataLookup1D.h> 7 #include <c++_tools/ gslapi/vector.h>7 #include <c++_tools/utility/vector.h> 8 8 9 9 … … 11 11 namespace classifier { 12 12 13 void convert(const DataLookup1D& lookup, gslapi::vector& vector)13 void convert(const DataLookup1D& lookup, utility::vector& vector) 14 14 { 15 vector= gslapi::vector(lookup.size());15 vector=utility::vector(lookup.size()); 16 16 for(u_int i=0; i<lookup.size(); i++) 17 17 vector(i)=lookup(i); -
trunk/c++_tools/classifier/utility.h
r608 r616 1 // $Id$2 3 1 #ifndef _theplu_classifier_utility_ 4 2 #define _theplu_classifier_utility_ 5 3 4 // $Id$ 5 6 6 namespace theplu { 7 7 8 namespace gslapi{8 namespace utility { 9 9 class vector; 10 10 } … … 15 15 16 16 /// 17 /// Converts a DataLookup1D to a gslapi::vector17 /// Converts a DataLookup1D to a utility::vector 18 18 /// 19 void convert(const DataLookup1D&, gslapi::vector&);19 void convert(const DataLookup1D&, utility::vector&); 20 20 21 21 -
trunk/c++_tools/statistics/Averager.cc
r420 r616 2 2 3 3 #include <c++_tools/statistics/Averager.h> 4 #include <c++_tools/gslapi/vector.h>5 6 #include <sys/types.h>7 #include <ostream>8 4 9 5 namespace theplu { -
trunk/c++_tools/statistics/Averager.h
r597 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_averager_ 4 2 #define _theplu_statistics_averager_ 5 3 6 #include <c++_tools/gslapi/vector.h> 4 // $Id$ 7 5 8 6 #include <cmath> 7 #include <sys/types.h> 9 8 10 9 namespace theplu{ -
trunk/c++_tools/statistics/AveragerPairWeighted.h
r582 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_averager_pair_weighted_ 4 2 #define _theplu_statistics_averager_pair_weighted_ 5 3 4 // $Id$ 5 6 6 #include <c++_tools/statistics/AveragerWeighted.h> 7 #include <c++_tools/gslapi/vector.h>8 7 9 8 #include <cmath> 10 //#include <utility>11 9 12 10 -
trunk/c++_tools/statistics/AveragerWeighted.cc
r582 r616 2 2 3 3 #include <c++_tools/statistics/AveragerWeighted.h> 4 #include <c++_tools/statistics/Averager.h>5 #include <c++_tools/gslapi/vector.h>6 7 #include <cassert>8 #include <ostream>9 #include <sys/types.h>10 4 11 5 namespace theplu { -
trunk/c++_tools/statistics/AveragerWeighted.h
r589 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_averager_weighted_ 4 2 #define _theplu_statistics_averager_weighted_ 5 3 4 // $Id$ 5 6 6 #include <c++_tools/statistics/Averager.h> 7 7 8 8 #include <cmath> 9 //#include <ostream>10 9 11 10 namespace theplu{ 12 class gslapi::vector;13 14 11 namespace statistics{ 15 12 -
trunk/c++_tools/statistics/Distance.cc
r582 r616 5 5 #include <c++_tools/classifier/DataLookup1D.h> 6 6 #include <c++_tools/classifier/utility.h> 7 #include <c++_tools/ gslapi/vector.h>7 #include <c++_tools/utility/vector.h> 8 8 9 9 namespace theplu{ … … 13 13 const classifier::DataLookup1D& y) const 14 14 { 15 gslapi::vector a;15 utility::vector a; 16 16 classifier::convert(x,a); 17 gslapi::vector b;17 utility::vector b; 18 18 classifier::convert(y,b); 19 19 return this->operator()(a,b); … … 26 26 const classifier::DataLookup1D& wy) const 27 27 { 28 gslapi::vector a;28 utility::vector a; 29 29 classifier::convert(x,a); 30 gslapi::vector b;30 utility::vector b; 31 31 classifier::convert(y,b); 32 gslapi::vector c;32 utility::vector c; 33 33 classifier::convert(wx,c); 34 gslapi::vector d;34 utility::vector d; 35 35 classifier::convert(wy,d); 36 36 return this->operator()(a,b,c,d); … … 38 38 39 39 40 41 42 40 }} // of namespace statistics and namespace theplu 43 41 -
trunk/c++_tools/statistics/Distance.h
r582 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_distance_ 4 2 #define _theplu_statistics_distance_ 5 3 4 // $Id$ 5 6 6 namespace theplu{ 7 7 8 namespace gslapi{8 namespace utility { 9 9 class vector; 10 10 } … … 30 30 } 31 31 32 virtual double operator()(const gslapi::vector& x,33 const gslapi::vector& y) const = 0;32 virtual double operator()(const utility::vector& x, 33 const utility::vector& y) const = 0; 34 34 35 35 … … 38 38 39 39 40 virtual double operator()(const gslapi::vector& x,41 const gslapi::vector& y,42 const gslapi::vector& wx,43 const gslapi::vector& wy) const = 0;40 virtual double operator()(const utility::vector& x, 41 const utility::vector& y, 42 const utility::vector& wx, 43 const utility::vector& wy) const = 0; 44 44 45 45 virtual double operator()(const classifier::DataLookup1D& x, -
trunk/c++_tools/statistics/Fisher.cc
r556 r616 111 111 112 112 double Fisher::score(const classifier::Target& target, 113 const gslapi::vector& value)113 const utility::vector& value) 114 114 { 115 115 weighted_=false; … … 137 137 138 138 double Fisher::score(const classifier::Target& target, 139 const gslapi::vector& value,140 const gslapi::vector& weight)139 const utility::vector& value, 140 const utility::vector& weight) 141 141 { 142 142 weighted_=true; -
trunk/c++_tools/statistics/Fisher.h
r556 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_fisher_ 4 2 #define _theplu_statistics_fisher_ 5 3 4 // $Id$ 5 6 6 #include <c++_tools/statistics/Score.h> 7 #include <c++_tools/ gslapi/vector.h>7 #include <c++_tools/utility/vector.h> 8 8 9 9 #include <cmath> … … 106 106 /// 107 107 double score(const classifier::Target& target, 108 const gslapi::vector& value);108 const utility::vector& value); 109 109 110 110 /// … … 118 118 /// 119 119 double score(const classifier::Target& target, 120 const gslapi::vector& value,121 const gslapi::vector& weight);120 const utility::vector& value, 121 const utility::vector& weight); 122 122 123 123 /// -
trunk/c++_tools/statistics/FoldChange.cc
r514 r616 32 32 33 33 double FoldChange::score(const classifier::Target& target, 34 const gslapi::vector& value)34 const utility::vector& value) 35 35 { 36 36 weighted_=false; … … 50 50 51 51 double FoldChange::score(const classifier::Target& target, 52 const gslapi::vector& value,53 const gslapi::vector& weight)52 const utility::vector& value, 53 const utility::vector& weight) 54 54 { 55 55 weighted_=true; -
trunk/c++_tools/statistics/FoldChange.h
r475 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_foldchange_ 4 2 #define _theplu_statistics_foldchange_ 3 4 // $Id$ 5 5 6 6 #include "Score.h" … … 8 8 namespace theplu { 9 9 10 class gslapi::vector;10 class utility::vector; 11 11 12 12 … … 34 34 /// 35 35 double score(const classifier::Target& target, 36 const gslapi::vector& value);36 const utility::vector& value); 37 37 38 38 /// … … 46 46 /// 47 47 double score(const classifier::Target& target, 48 const gslapi::vector& value,49 const gslapi::vector& weight);48 const utility::vector& value, 49 const utility::vector& weight); 50 50 51 51 private: -
trunk/c++_tools/statistics/Linear.cc
r586 r616 4 4 5 5 #include <c++_tools/statistics/AveragerPair.h> 6 #include <c++_tools/ gslapi/vector.h>6 #include <c++_tools/utility/vector.h> 7 7 8 8 #include <gsl/gsl_fit.h> … … 14 14 15 15 16 void Linear::fit(const gslapi::vector& x, const gslapi::vector& y)16 void Linear::fit(const utility::vector& x, const utility::vector& y) 17 17 { 18 18 ap_.reset(); -
trunk/c++_tools/statistics/Linear.h
r586 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_regression_linear_ 4 2 #define _theplu_statistics_regression_linear_ 5 3 4 // $Id$ 5 6 6 #include <c++_tools/statistics/OneDimensional.h> 7 #include <c++_tools/gslapi/vector.h>8 7 9 8 #include <cmath> 10 9 11 10 namespace theplu { 11 namespace utility { 12 class vector; 13 } 12 14 namespace statistics { 13 15 namespace regression { … … 61 63 /// construction \f$ \alpha \f$ and \f$ \beta \f$ are independent. 62 64 /// 63 void fit(const gslapi::vector& x, const gslapi::vector& y) ;65 void fit(const utility::vector& x, const utility::vector& y) ; 64 66 65 67 /// -
trunk/c++_tools/statistics/LinearWeighted.cc
r586 r616 4 4 5 5 #include <c++_tools/statistics/AveragerPairWeighted.h> 6 #include <c++_tools/ gslapi/vector.h>6 #include <c++_tools/utility/vector.h> 7 7 8 8 #include <gsl/gsl_fit.h> … … 14 14 15 15 16 void LinearWeighted::fit(const gslapi::vector& x,17 const gslapi::vector& y,18 const gslapi::vector& w)16 void LinearWeighted::fit(const utility::vector& x, 17 const utility::vector& y, 18 const utility::vector& w) 19 19 { 20 20 // AveragerPairWeighted requires 2 weights but works only on the 21 21 // product wx*wy, so we can send in w and a dummie to get what we 22 22 // want. 23 gslapi::vector dummie(w.size(),1);23 utility::vector dummie(w.size(),1); 24 24 AveragerPairWeighted ap; 25 25 ap.add_values(x,y,w,dummie); -
trunk/c++_tools/statistics/LinearWeighted.h
r586 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_regression_linear_weighted_ 4 2 #define _theplu_statistics_regression_linear_weighted_ 5 3 4 // $Id$ 5 6 6 #include <c++_tools/statistics/OneDimensionalWeighted.h> 7 #include <c++_tools/gslapi/vector.h>8 7 9 8 #include <cmath> 10 9 11 10 namespace theplu { 12 namespace statistics { 11 namespace utility { 12 class vector; 13 } 14 namespace statistics { 13 15 namespace regression { 14 16 … … 63 65 /// \alpha \f$ and \f$ \beta \f$ are independent. 64 66 /// 65 void fit(const gslapi::vector& x, const gslapi::vector& y,66 const gslapi::vector& w);67 void fit(const utility::vector& x, const utility::vector& y, 68 const utility::vector& w); 67 69 68 70 /// -
trunk/c++_tools/statistics/Local.cc
r586 r616 3 3 #include <c++_tools/statistics/Local.h> 4 4 5 #include <c++_tools/ gslapi/vector.h>5 #include <c++_tools/utility/vector.h> 6 6 #include <c++_tools/statistics/Kernel.h> 7 7 #include <c++_tools/statistics/OneDimensionalWeighted.h> … … 26 26 27 27 size_t nof_fits=data_.size()/step_size; 28 x_= gslapi::vector(nof_fits);29 y_predicted_ = gslapi::vector(x_.size());30 y_err_ = gslapi::vector(x_.size());28 x_= utility::vector(nof_fits); 29 y_predicted_ = utility::vector(x_.size()); 30 y_err_ = utility::vector(x_.size()); 31 31 sort(data_.begin(), data_.end()); 32 32 33 // coying data to 2 gslapivectors ONCE to use views from34 gslapi::vector x(data_.size());35 gslapi::vector y(data_.size());33 // coying data to 2 utility vectors ONCE to use views from 34 utility::vector x(data_.size()); 35 utility::vector y(data_.size()); 36 36 for (size_t j=0; j<x.size(); j++){ 37 37 x(j)=data_[j].first; … … 69 69 assert(max_index<data_.size()); 70 70 71 gslapi::vector x_local(x, min_index, max_index-min_index+1);72 gslapi::vector y_local(y, min_index, max_index-min_index+1);71 utility::vector x_local(x, min_index, max_index-min_index+1); 72 utility::vector y_local(y, min_index, max_index-min_index+1); 73 73 74 74 // calculating weights 75 gslapi::vector w(max_index-min_index+1);75 utility::vector w(max_index-min_index+1); 76 76 for (size_t j=0; j<w.size(); j++) 77 77 w(j) = kernel_->weight( (x_local(j)- x_mid)/width ); -
trunk/c++_tools/statistics/Local.h
r614 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_regression_local_ 4 2 #define _theplu_statistics_regression_local_ 5 3 4 // $Id$ 5 6 6 #include <c++_tools/statistics/Kernel.h> 7 7 #include <c++_tools/statistics/OneDimensionalWeighted.h> 8 #include <c++_tools/ gslapi/vector.h>8 #include <c++_tools/utility/vector.h> 9 9 10 10 #include <iostream> … … 51 51 /// Function returning predicted values 52 52 /// 53 inline const gslapi::vector& y_predicted(void) const53 inline const utility::vector& y_predicted(void) const 54 54 { return y_predicted_; } 55 55 … … 57 57 /// Function returning error of predictions 58 58 /// 59 inline const gslapi::vector& y_err(void) const { return y_err_; }59 inline const utility::vector& y_err(void) const { return y_err_; } 60 60 61 61 /// … … 68 68 /// @return x-values where fitting was performed. 69 69 /// 70 inline const gslapi::vector& x(void) const { return x_; }70 inline const utility::vector& x(void) const { return x_; } 71 71 72 72 private: … … 79 79 Kernel* kernel_; 80 80 OneDimensionalWeighted* regressor_; 81 gslapi::vector x_; 82 gslapi::vector y_predicted_; 83 gslapi::vector y_err_; 84 81 utility::vector x_; 82 utility::vector y_predicted_; 83 utility::vector y_err_; 85 84 }; 86 85 -
trunk/c++_tools/statistics/MultiDimensional.cc
r586 r616 2 2 3 3 #include <c++_tools/statistics/MultiDimensional.h> 4 #include <c++_tools/ gslapi/matrix.h>5 #include <c++_tools/ gslapi/vector.h>4 #include <c++_tools/utility/matrix.h> 5 #include <c++_tools/utility/vector.h> 6 6 7 7 namespace theplu { … … 10 10 11 11 12 void MultiDimensional::fit(const gslapi::matrix& x, const gslapi::vector& y)12 void MultiDimensional::fit(const utility::matrix& x, const utility::vector& y) 13 13 { 14 covariance_= gslapi::matrix(x.columns(),x.columns());15 fit_parameters_= gslapi::vector(x.columns());14 covariance_=utility::matrix(x.columns(),x.columns()); 15 fit_parameters_=utility::vector(x.columns()); 16 16 if (work_) 17 17 gsl_multifit_linear_free(work_); … … 23 23 24 24 25 double MultiDimensional::prediction_error(const gslapi::vector& x) const25 double MultiDimensional::prediction_error(const utility::vector& x) const 26 26 { 27 27 double s2 = 0; … … 35 35 36 36 37 double MultiDimensional::standard_error(const gslapi::vector& x) const37 double MultiDimensional::standard_error(const utility::vector& x) const 38 38 { 39 39 double s2 = 0; -
trunk/c++_tools/statistics/MultiDimensional.h
r586 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_regression_multidimensional_ 4 2 #define _theplu_statistics_regression_multidimensional_ 5 3 6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/gslapi/vector.h> 4 // $Id$ 5 6 #include <c++_tools/utility/matrix.h> 7 #include <c++_tools/utility/vector.h> 8 8 9 9 #include <gsl/gsl_multifit.h> … … 34 34 /// 35 35 /// 36 void fit(const gslapi::matrix& X, const gslapi::vector& y);36 void fit(const utility::matrix& X, const utility::vector& y); 37 37 38 38 /// 39 39 /// 40 40 /// 41 gslapi::vector fit_parameters(void) { return fit_parameters_; }41 utility::vector fit_parameters(void) { return fit_parameters_; } 42 42 43 43 /// 44 44 /// @return value in @a x according to fitted model 45 45 /// 46 inline double predict(const gslapi::vector& x) const46 inline double predict(const utility::vector& x) const 47 47 { return fit_parameters_ * x; } 48 48 … … 50 50 /// @return expected prediction error for a new data point in @a x 51 51 /// 52 double prediction_error(const gslapi::vector& x) const;52 double prediction_error(const utility::vector& x) const; 53 53 54 54 /// 55 55 /// @return error of model value in @a x 56 56 /// 57 double standard_error(const gslapi::vector& x) const;57 double standard_error(const utility::vector& x) const; 58 58 59 59 private: 60 60 double chisquare_; 61 gslapi::matrix covariance_;62 gslapi::vector fit_parameters_;61 utility::matrix covariance_; 62 utility::vector fit_parameters_; 63 63 gsl_multifit_linear_workspace* work_; 64 64 -
trunk/c++_tools/statistics/MultiDimensionalWeighted.cc
r586 r616 2 2 3 3 #include <c++_tools/statistics/MultiDimensionalWeighted.h> 4 #include <c++_tools/ gslapi/matrix.h>5 #include <c++_tools/ gslapi/vector.h>4 #include <c++_tools/utility/matrix.h> 5 #include <c++_tools/utility/vector.h> 6 6 7 7 #include <cassert> … … 12 12 13 13 14 void MultiDimensionalWeighted::fit(const gslapi::matrix& x,15 const gslapi::vector& y,16 const gslapi::vector& w)14 void MultiDimensionalWeighted::fit(const utility::matrix& x, 15 const utility::vector& y, 16 const utility::vector& w) 17 17 { 18 18 assert(y.size()==w.size()); 19 19 assert(x.rows()==y.size()); 20 20 21 covariance_= gslapi::matrix(x.columns(),x.columns());22 fit_parameters_= gslapi::vector(x.columns());21 covariance_=utility::matrix(x.columns(),x.columns()); 22 fit_parameters_=utility::vector(x.columns()); 23 23 if (work_) 24 24 gsl_multifit_linear_free(work_); … … 29 29 } 30 30 31 double MultiDimensionalWeighted::prediction_error(const gslapi::vector& x,31 double MultiDimensionalWeighted::prediction_error(const utility::vector& x, 32 32 const double w) const 33 33 { … … 42 42 43 43 44 double MultiDimensionalWeighted::standard_error(const gslapi::vector& x) const44 double MultiDimensionalWeighted::standard_error(const utility::vector& x) const 45 45 { 46 46 double s2 = 0; -
trunk/c++_tools/statistics/MultiDimensionalWeighted.h
r586 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_regression_multidimensional_weighted_ 4 2 #define _theplu_statistics_regression_multidimensional_weighted_ 5 3 6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/gslapi/vector.h> 4 // $Id$ 5 6 #include <c++_tools/utility/matrix.h> 7 #include <c++_tools/utility/vector.h> 8 8 9 9 #include <gsl/gsl_multifit.h> … … 35 35 /// @todo doc 36 36 /// 37 void fit(const gslapi::matrix& X, const gslapi::vector& y,38 const gslapi::vector& w);37 void fit(const utility::matrix& X, const utility::vector& y, 38 const utility::vector& w); 39 39 40 40 /// 41 41 /// @return value in @a x according to fitted model 42 42 /// 43 inline double predict(const gslapi::vector& x) const43 inline double predict(const utility::vector& x) const 44 44 { return fit_parameters_ * x; } 45 45 … … 47 47 /// @return expected prediction error for a new data point in @a x 48 48 /// 49 double prediction_error(const gslapi::vector& x, const double w) const;49 double prediction_error(const utility::vector& x, const double w) const; 50 50 51 51 /// 52 52 /// @return error of model value in @a x 53 53 /// 54 double standard_error(const gslapi::vector& x) const;54 double standard_error(const utility::vector& x) const; 55 55 56 56 /// 57 57 /// 58 58 /// 59 gslapi::vector fit_parameters(void) { return fit_parameters_; }59 utility::vector fit_parameters(void) { return fit_parameters_; } 60 60 61 61 private: 62 62 double chisquare_; 63 gslapi::matrix covariance_;64 gslapi::vector fit_parameters_;63 utility::matrix covariance_; 64 utility::vector fit_parameters_; 65 65 gsl_multifit_linear_workspace* work_; 66 66 -
trunk/c++_tools/statistics/Naive.cc
r586 r616 6 6 #include <c++_tools/statistics/AveragerWeighted.h> 7 7 #include <c++_tools/statistics/OneDimensional.h> 8 #include <c++_tools/ gslapi/vector.h>8 #include <c++_tools/utility/vector.h> 9 9 10 #include <cmath> 10 11 #include <iostream> 11 12 … … 16 17 17 18 18 void Naive::fit(const gslapi::vector& x, const gslapi::vector& y)19 void Naive::fit(const utility::vector& x, const utility::vector& y) 19 20 { 20 21 ap_.reset(); -
trunk/c++_tools/statistics/Naive.h
r586 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_regression_naive_ 4 2 #define _theplu_statistics_regression_naive_ 5 3 4 // $Id$ 5 6 6 #include <c++_tools/statistics/OneDimensional.h> 7 8 #include <c++_tools/gslapi/vector.h>9 7 10 8 #include <iostream> 11 9 #include <utility> 12 10 13 14 11 namespace theplu { 12 namespace utility { 13 class vector; 14 } 15 15 namespace statistics { 16 16 namespace regression { … … 46 46 /// weighted version with unity weights. 47 47 /// 48 void fit(const gslapi::vector& x, const gslapi::vector& y);48 void fit(const utility::vector& x, const utility::vector& y); 49 49 50 50 /// -
trunk/c++_tools/statistics/NaiveWeighted.cc
r586 r616 5 5 #include <c++_tools/statistics/AveragerWeighted.h> 6 6 #include <c++_tools/statistics/OneDimensional.h> 7 #include <c++_tools/gslapi/vector.h> 8 9 #include <iostream> 7 #include <c++_tools/utility/vector.h> 10 8 11 9 … … 15 13 16 14 17 void NaiveWeighted::fit(const gslapi::vector& x,18 const gslapi::vector& y,19 const gslapi::vector& w)15 void NaiveWeighted::fit(const utility::vector& x, 16 const utility::vector& y, 17 const utility::vector& w) 20 18 { 21 19 AveragerWeighted a; -
trunk/c++_tools/statistics/NaiveWeighted.h
r586 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_regression_naive_weighted_ 4 2 #define _theplu_statistics_regression_naive_weighted_ 5 3 4 // $Id$ 5 6 6 #include <c++_tools/statistics/OneDimensionalWeighted.h> 7 8 #include <c++_tools/gslapi/vector.h>9 //#include <c++_tools/statistics/AveragerPairWeighted.h>10 7 11 8 #include <cmath> … … 15 12 16 13 namespace theplu { 14 namespace utility { 15 class vector; 16 } 17 17 namespace statistics { 18 18 namespace regression { … … 44 44 /// the inverse of the variance for \f$ y_i \f$ 45 45 /// 46 void fit(const gslapi::vector& x,47 const gslapi::vector& y,48 const gslapi::vector& w);46 void fit(const utility::vector& x, 47 const utility::vector& y, 48 const utility::vector& w); 49 49 50 50 /// -
trunk/c++_tools/statistics/OneDimensional.h
r586 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_regression_onedimensioanl_ 4 2 #define _theplu_statistics_regression_onedimensioanl_ 3 4 // $Id$ 5 5 6 6 #include <c++_tools/statistics/AveragerPair.h> … … 9 9 10 10 namespace theplu { 11 namespace gslapi{11 namespace utility { 12 12 class vector; 13 13 } … … 40 40 /// \sum{(\hat{y_i}-y_i)^2} \f$, where \f$ \hat{y} \f$ is the fitted value. 41 41 /// 42 virtual void fit(const gslapi::vector& x, const gslapi::vector& y)=0;42 virtual void fit(const utility::vector& x, const utility::vector& y)=0; 43 43 44 44 /// -
trunk/c++_tools/statistics/OneDimensionalWeighted.h
r586 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_regression_onedimensioanlweighted_ 4 2 #define _theplu_statistics_regression_onedimensioanlweighted_ 3 4 // $Id$ 5 5 6 6 #include <ostream> 7 7 8 8 namespace theplu { 9 namespace gslapi{9 namespace utility { 10 10 class vector; 11 11 } … … 41 41 /// to the inverse of the variance for \f$ y_i \f$ 42 42 /// 43 virtual void fit(const gslapi::vector& x, const gslapi::vector& y,44 const gslapi::vector& w)=0;43 virtual void fit(const utility::vector& x, const utility::vector& y, 44 const utility::vector& w)=0; 45 45 46 46 /// -
trunk/c++_tools/statistics/Pearson.cc
r514 r616 1 1 // $Id$ 2 3 2 4 3 #include <c++_tools/statistics/Pearson.h> 5 4 #include <c++_tools/statistics/AveragerPair.h> 6 5 #include <c++_tools/statistics/AveragerPairWeighted.h> 7 #include <c++_tools/ gslapi/vector.h>6 #include <c++_tools/utility/vector.h> 8 7 #include <c++_tools/classifier/Target.h> 9 8 … … 41 40 42 41 double Pearson::score(const classifier::Target& target, 43 const gslapi::vector& value)42 const utility::vector& value) 44 43 { 45 44 weighted_=false; … … 60 59 61 60 double Pearson::score(const classifier::Target& target, 62 const gslapi::vector& value,63 const gslapi::vector& weight)61 const utility::vector& value, 62 const utility::vector& weight) 64 63 { 65 64 weighted_=true; -
trunk/c++_tools/statistics/Pearson.h
r597 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_pearson_ 4 2 #define _theplu_statistics_pearson_ 3 4 // $Id$ 5 5 6 6 #include <c++_tools/statistics/Score.h> 7 7 8 8 namespace theplu { 9 namespace utility { 10 class vector; 11 } 9 12 namespace classifier { 10 13 class VectorAbstract; 11 14 } 12 13 15 namespace statistics { 14 16 … … 39 41 /// 40 42 double score(const classifier::Target& target, 41 const gslapi::vector& value);43 const utility::vector& value); 42 44 43 45 /// … … 51 53 /// 52 54 double score(const classifier::Target& target, 53 const gslapi::vector& value,54 const gslapi::vector& weight);55 const utility::vector& value, 56 const utility::vector& weight); 55 57 56 58 /// … … 68 70 69 71 70 // void centralize( gslapi::vector&, const gslapi::vector&);72 // void centralize(utility::vector&, const utility::vector&); 71 73 }; 72 74 -
trunk/c++_tools/statistics/PearsonDistance.cc
r582 r616 5 5 #include <c++_tools/statistics/AveragerPair.h> 6 6 #include <c++_tools/statistics/AveragerPairWeighted.h> 7 #include <c++_tools/ gslapi/vector.h>7 #include <c++_tools/utility/vector.h> 8 8 9 9 namespace theplu{ 10 10 namespace statistics{ 11 11 12 double PearsonDistance::operator()(const gslapi::vector& x,13 const gslapi::vector& y) const12 double PearsonDistance::operator()(const utility::vector& x, 13 const utility::vector& y) const 14 14 { 15 15 AveragerPair ap; … … 19 19 20 20 21 double PearsonDistance::operator()(const gslapi::vector& x,22 const gslapi::vector& y,23 const gslapi::vector& wx,24 const gslapi::vector& wy) const21 double PearsonDistance::operator()(const utility::vector& x, 22 const utility::vector& y, 23 const utility::vector& wx, 24 const utility::vector& wy) const 25 25 { 26 26 AveragerPairWeighted ap; -
trunk/c++_tools/statistics/PearsonDistance.h
r582 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_pearson_distance_ 4 2 #define _theplu_statistics_pearson_distance_ 3 4 // $Id$ 5 5 6 6 #include <c++_tools/statistics/Distance.h> … … 8 8 namespace theplu{ 9 9 10 namespace gslapi{10 namespace utility { 11 11 class vector; 12 12 } … … 40 40 using Distance::operator(); 41 41 42 virtual double operator()(const gslapi::vector& x,43 const gslapi::vector& y) const;42 virtual double operator()(const utility::vector& x, 43 const utility::vector& y) const; 44 44 45 45 46 virtual double operator()(const gslapi::vector& x,47 const gslapi::vector& y,48 const gslapi::vector& wx,49 const gslapi::vector& wy) const;46 virtual double operator()(const utility::vector& x, 47 const utility::vector& y, 48 const utility::vector& wx, 49 const utility::vector& wy) const; 50 50 51 51 private: -
trunk/c++_tools/statistics/Polynomial.cc
r586 r616 2 2 3 3 #include <c++_tools/statistics/Polynomial.h> 4 #include <c++_tools/ gslapi/matrix.h>5 #include <c++_tools/ gslapi/vector.h>4 #include <c++_tools/utility/matrix.h> 5 #include <c++_tools/utility/vector.h> 6 6 7 7 namespace theplu { … … 10 10 11 11 12 void Polynomial::fit(const gslapi::vector& x, const gslapi::vector& y)12 void Polynomial::fit(const utility::vector& x, const utility::vector& y) 13 13 { 14 gslapi::matrix X=gslapi::matrix(x.size(),power_+1,1);14 utility::matrix X=utility::matrix(x.size(),power_+1,1); 15 15 for (size_t i=0; i<X.rows(); ++i) 16 16 for (u_int j=1; j<X.columns(); j++) … … 21 21 double Polynomial::predict(const double x) const 22 22 { 23 gslapi::vector vec(power_+1,1);23 utility::vector vec(power_+1,1); 24 24 for (size_t i=1; i<=power_; ++i) 25 25 vec(i) = vec(i-1)*x; … … 29 29 double Polynomial::prediction_error(const double x) const 30 30 { 31 gslapi::vector vec(power_+1,1);31 utility::vector vec(power_+1,1); 32 32 for (size_t i=1; i<=power_; ++i) 33 33 vec(i) = vec(i-1)*x; … … 37 37 double Polynomial::standard_error(const double x) const 38 38 { 39 gslapi::vector vec(power_+1,1);39 utility::vector vec(power_+1,1); 40 40 for (size_t i=1; i<=power_; ++i) 41 41 vec(i) = vec(i-1)*x; -
trunk/c++_tools/statistics/Polynomial.h
r586 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_regression_polynomial_ 4 2 #define _theplu_statistics_regression_polynomial_ 3 4 // $Id$ 5 5 6 6 #include <c++_tools/statistics/OneDimensional.h> 7 7 #include <c++_tools/statistics/MultiDimensional.h> 8 8 9 #include <c++_tools/ gslapi/vector.h>9 #include <c++_tools/utility/vector.h> 10 10 11 11 #include <gsl/gsl_multifit.h> … … 39 39 /// 40 40 /// 41 void fit(const gslapi::vector& x, const gslapi::vector& y);41 void fit(const utility::vector& x, const utility::vector& y); 42 42 43 43 /// 44 44 /// 45 45 /// 46 gslapi::vector fit_parameters(void) { return md_.fit_parameters(); }46 utility::vector fit_parameters(void) { return md_.fit_parameters(); } 47 47 48 48 /// -
trunk/c++_tools/statistics/PolynomialWeighted.cc
r586 r616 2 2 3 3 #include <c++_tools/statistics/PolynomialWeighted.h> 4 #include <c++_tools/ gslapi/matrix.h>5 #include <c++_tools/ gslapi/vector.h>4 #include <c++_tools/utility/matrix.h> 5 #include <c++_tools/utility/vector.h> 6 6 7 7 #include <cassert> … … 12 12 13 13 14 void PolynomialWeighted::fit(const gslapi::vector& x, const gslapi::vector& y, 15 const gslapi::vector& w) 14 void PolynomialWeighted::fit(const utility::vector& x, 15 const utility::vector& y, 16 const utility::vector& w) 16 17 { 17 18 assert(x.size()==y.size()); 18 19 assert(y.size()==w.size()); 19 gslapi::matrix X=gslapi::matrix(x.size(),power_+1,1);20 utility::matrix X=utility::matrix(x.size(),power_+1,1); 20 21 for (size_t i=0; i<X.rows(); ++i) 21 22 for (u_int j=1; j<X.columns(); j++) … … 26 27 double PolynomialWeighted::predict(const double x) const 27 28 { 28 gslapi::vector vec(power_+1,1);29 utility::vector vec(power_+1,1); 29 30 for (size_t i=1; i<=power_; ++i) 30 31 vec(i) = vec(i-1)*x; … … 35 36 const double w) const 36 37 { 37 gslapi::vector vec(power_+1,1);38 utility::vector vec(power_+1,1); 38 39 for (size_t i=1; i<=power_; ++i) 39 40 vec(i) = vec(i-1)*x; … … 43 44 double PolynomialWeighted::standard_error(const double x) const 44 45 { 45 gslapi::vector vec(power_+1,1);46 utility::vector vec(power_+1,1); 46 47 for (size_t i=1; i<=power_; ++i) 47 48 vec(i) = vec(i-1)*x; -
trunk/c++_tools/statistics/PolynomialWeighted.h
r586 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_regression_polynomial_weighted_ 4 2 #define _theplu_statistics_regression_polynomial_weighted_ 3 4 // $Id$ 5 5 6 6 #include <c++_tools/statistics/OneDimensionalWeighted.h> 7 7 #include <c++_tools/statistics/MultiDimensionalWeighted.h> 8 8 9 #include <c++_tools/ gslapi/vector.h>9 #include <c++_tools/utility/vector.h> 10 10 11 11 //#include <gsl/gsl_multifit.h> … … 43 43 /// y_i \f$ 44 44 /// 45 void fit(const gslapi::vector& x, const gslapi::vector& y,46 const gslapi::vector& w);45 void fit(const utility::vector& x, const utility::vector& y, 46 const utility::vector& w); 47 47 48 48 /// 49 49 /// @return parameters for polynomial model 50 50 /// 51 gslapi::vector fit_parameters(void) { return md_.fit_parameters(); }51 utility::vector fit_parameters(void) { return md_.fit_parameters(); } 52 52 53 53 /// -
trunk/c++_tools/statistics/ROC.cc
r514 r616 3 3 #include <c++_tools/statistics/ROC.h> 4 4 #include <c++_tools/utility/stl_utility.h> 5 #include <c++_tools/ gslapi/vector.h>5 #include <c++_tools/utility/vector.h> 6 6 7 7 #include <gsl/gsl_cdf.h> … … 13 13 14 14 namespace theplu { 15 class gslapi::vector;16 15 namespace statistics { 17 16 … … 67 66 68 67 double ROC::score(const classifier::Target& target, 69 const gslapi::vector& value)68 const utility::vector& value) 70 69 { 71 70 assert(target.size()==value.size()); … … 101 100 // Peter, should be possible to do this in NlogN 102 101 double ROC::score(const classifier::Target& target, 103 const gslapi::vector& value,104 const gslapi::vector& weight)102 const utility::vector& value, 103 const utility::vector& weight) 105 104 { 106 105 weighted_=true; -
trunk/c++_tools/statistics/ROC.h
r589 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_roc_ 4 2 #define _theplu_statistics_roc_ 3 4 // $Id$ 5 5 6 6 #include <c++_tools/classifier/Target.h> … … 11 11 12 12 namespace theplu { 13 namespace utility { 14 class vector; 15 } 13 16 namespace statistics { 14 17 … … 42 45 /// 43 46 double score(const classifier::Target& target, 44 const gslapi::vector& value);47 const utility::vector& value); 45 48 46 49 /// Function taking values, target, weight and a vector defining … … 56 59 /// 57 60 double score(const classifier::Target& target, 58 const gslapi::vector& value,59 const gslapi::vector& weight);61 const utility::vector& value, 62 const utility::vector& weight); 60 63 61 64 -
trunk/c++_tools/statistics/SNR.cc
r560 r616 12 12 13 13 SNR::SNR(bool b) 14 : Score(b), 14 : Score(b), score_(0) 15 15 { 16 16 } 17 17 18 18 double SNR::score(const classifier::Target& target, 19 const gslapi::vector& value)19 const utility::vector& value) 20 20 { 21 21 weighted_=false; … … 39 39 40 40 double SNR::score(const classifier::Target& target, 41 const gslapi::vector& value,42 const gslapi::vector& weight)41 const utility::vector& value, 42 const utility::vector& weight) 43 43 { 44 44 weighted_=true; -
trunk/c++_tools/statistics/SNR.h
r532 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_snr 4 2 #define _theplu_statistics_snr 5 3 6 // C++ tools include7 ///////////////////// 4 // $Id$ 5 8 6 #include <c++_tools/statistics/Score.h> 9 #include <c++_tools/gslapi/vector.h>10 7 11 8 #include <gsl/gsl_cdf.h> 12 9 13 14 10 namespace theplu { 11 namespace utility { 12 class vector; 13 } 15 14 namespace statistics { 16 15 … … 39 38 /// 40 39 double score(const classifier::Target& target, 41 const gslapi::vector& value);40 const utility::vector& value); 42 41 43 42 /// … … 46 45 /// 47 46 double score(const classifier::Target& target, 48 const gslapi::vector& value,49 const gslapi::vector& weight);47 const utility::vector& value, 48 const utility::vector& weight); 50 49 private: 51 50 double score_; -
trunk/c++_tools/statistics/Score.h
r581 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_score_ 4 2 #define _theplu_statistics_score_ 5 3 4 // $Id$ 5 6 6 #include <c++_tools/classifier/utility.h> 7 #include <c++_tools/ gslapi/vector.h>7 #include <c++_tools/utility/vector.h> 8 8 9 9 #include <cassert> … … 51 51 virtual double 52 52 score(const classifier::Target& target, 53 const gslapi::vector& value) = 0;53 const utility::vector& value) = 0; 54 54 55 55 /// … … 69 69 { 70 70 assert(target.size()==value.size()); 71 gslapi::vector a;71 utility::vector a; 72 72 classifier::convert(value,a); 73 73 return score(target,a); … … 83 83 virtual double 84 84 score(const classifier::Target& target, 85 const gslapi::vector& value,86 const gslapi::vector& weight) = 0;85 const utility::vector& value, 86 const utility::vector& weight) = 0; 87 87 88 88 /// … … 98 98 const classifier::DataLookup1D& weight) 99 99 { 100 gslapi::vector a;100 utility::vector a; 101 101 classifier::convert(value,a); 102 gslapi::vector b;102 utility::vector b; 103 103 classifier::convert(weight,a); 104 104 return score(target,a,b); -
trunk/c++_tools/statistics/WilcoxonFoldChange.cc
r502 r616 4 4 #include <c++_tools/statistics/utility.h> 5 5 #include <c++_tools/classifier/Target.h> 6 #include <c++_tools/gslapi/vector.h>7 6 8 7 #include <cmath> … … 22 21 23 22 double WilcoxonFoldChange::score(const classifier::Target& target, 24 const gslapi::vector& value)23 const utility::vector& value) 25 24 { 26 25 std::vector<double> distance; … … 40 39 41 40 double WilcoxonFoldChange::score(const classifier::Target& target, 42 const gslapi::vector& value,43 const gslapi::vector& weight)41 const utility::vector& value, 42 const utility::vector& weight) 44 43 { 45 44 std::cerr << " WilcoxonFoldChange::score not implemented" << std::endl; -
trunk/c++_tools/statistics/WilcoxonFoldChange.h
r475 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_wilcoxonfoldchange_ 4 2 #define _theplu_statistics_wilcoxonfoldchange_ 3 4 // $Id$ 5 5 6 6 #include <c++_tools/statistics/Score.h> 7 7 8 8 namespace theplu { 9 namespace utility { 10 class vector; 11 } 9 12 namespace statistics { 10 13 … … 30 33 /// 31 34 double score(const classifier::Target& target, 32 const gslapi::vector& value);35 const utility::vector& value); 33 36 34 37 /// … … 43 46 /// 44 47 double score(const classifier::Target& target, 45 const gslapi::vector& value,46 const gslapi::vector& weight);48 const utility::vector& value, 49 const utility::vector& weight); 47 50 48 51 private: -
trunk/c++_tools/statistics/tScore.cc
r589 r616 20 20 21 21 double tScore::score(const classifier::Target& target, 22 const gslapi::vector& value)22 const utility::vector& value) 23 23 { 24 24 weighted_=false; … … 43 43 44 44 double tScore::score(const classifier::Target& target, 45 const gslapi::vector& value,46 const gslapi::vector& weight)45 const utility::vector& value, 46 const utility::vector& weight) 47 47 { 48 48 weighted_=true; -
trunk/c++_tools/statistics/tScore.h
r597 r616 1 #ifndef _theplu_statistics_tscore_ 2 #define _theplu_statistics_tscore_ 3 1 4 // $Id$ 2 3 #ifndef _theplu_statistics_t_score_4 #define _theplu_statistics_t_score_5 5 6 6 // C++ tools include 7 7 ///////////////////// 8 8 #include <c++_tools/statistics/Score.h> 9 #include <c++_tools/gslapi/vector.h>10 9 11 10 #include <gsl/gsl_cdf.h> … … 13 12 14 13 namespace theplu { 14 namespace utility { 15 class vector; 16 } 15 17 namespace statistics { 16 18 … … 44 46 /// 45 47 double score(const classifier::Target& target, 46 const gslapi::vector& value);48 const utility::vector& value); 47 49 48 50 /// … … 60 62 /// 61 63 double score(const classifier::Target& target, 62 const gslapi::vector& value,63 const gslapi::vector& weight);64 const utility::vector& value, 65 const utility::vector& weight); 64 66 65 67 /// -
trunk/c++_tools/statistics/utility.cc
r511 r616 18 18 } 19 19 20 double median(const gslapi::vector& vec, const bool sorted)20 double median(const utility::vector& vec, const bool sorted) 21 21 { 22 22 if (!sorted){ 23 gslapi::vector vec_copy(vec);23 utility::vector vec_copy(vec); 24 24 vec_copy.sort(); 25 25 return gsl_stats_median_from_sorted_data (vec_copy.gsl_vector_p()->data, … … 32 32 } 33 33 34 double percentile(const gslapi::vector& vec, const double p,34 double percentile(const utility::vector& vec, const double p, 35 35 const bool sorted) 36 36 { 37 37 if (!sorted){ 38 gslapi::vector vec_c(vec);38 utility::vector vec_c(vec); 39 39 vec_c.sort(); 40 40 return gsl_stats_quantile_from_sorted_data(vec_c.gsl_vector_p()->data, -
trunk/c++_tools/statistics/utility.h
r588 r616 1 // $Id$2 3 1 #ifndef _theplu_statistics_utility_ 4 2 #define _theplu_statistics_utility_ 5 3 6 #include <c++_tools/gslapi/vector.h> 4 // $Id$ 5 6 #include <c++_tools/utility/vector.h> 7 7 8 8 #include <algorithm> … … 41 41 /// distribution. 42 42 /// 43 inline double kurtosis(const gslapi::vector& v)43 inline double kurtosis(const utility::vector& v) 44 44 { 45 45 const gsl_vector* gvp=v.gsl_vector_p(); … … 72 72 /// @return median 73 73 /// 74 double median(const gslapi::vector& vec, const bool sorted=false);74 double median(const utility::vector& vec, const bool sorted=false); 75 75 76 76 /// … … 122 122 /// @return \a p'th percentile 123 123 /// 124 double percentile(const gslapi::vector& vec, const double,124 double percentile(const utility::vector& vec, const double, 125 125 const bool sorted=false); 126 126 … … 129 129 /// measures the asymmetry of the tails of a distribution. 130 130 /// 131 inline double skewness(const gslapi::vector& v)131 inline double skewness(const utility::vector& v) 132 132 { 133 133 const gsl_vector* gvp=v.gsl_vector_p(); -
trunk/c++_tools/utility/Alignment.cc
r301 r616 2 2 3 3 #include <c++_tools/utility/Alignment.h> 4 #include <c++_tools/ gslapi/matrix.h>4 #include <c++_tools/utility/matrix.h> 5 5 6 6 #include <utility> … … 11 11 namespace alignment { 12 12 13 double NeedlemanWunsch(const gslapi::matrix& s,13 double NeedlemanWunsch(const utility::matrix& s, 14 14 std::vector<std::pair<size_t, size_t> >& path, 15 15 const double gap) 16 16 { 17 gslapi::matrix m(s.rows()+1,s.columns()+1);17 utility::matrix m(s.rows()+1,s.columns()+1); 18 18 // Init upper and left border of matrix 19 19 for (size_t i=1; i<m.rows(); i++) … … 23 23 // choice(i,j) tells us how we came to s(i,j). 1 is diagonal, 2 24 24 // vertical, and 3 horizontal, 25 gslapi::matrix choice(m.rows(),m.columns());25 utility::matrix choice(m.rows(),m.columns()); 26 26 27 27 // Calculating NeedlemanWunsch matrix -
trunk/c++_tools/utility/Alignment.h
r304 r616 1 // $Id$2 3 1 #ifndef _theplu_utility_alignment_ 4 2 #define _theplu_utility_alignment_ 3 4 // $Id$ 5 5 6 6 #include <utility> … … 9 9 namespace theplu { 10 10 11 namespace gslapi{11 namespace utility { 12 12 class matrix; 13 13 } … … 36 36 /// @return the global maximum alignment score. 37 37 /// 38 double NeedlemanWunsch(const gslapi::matrix& s,38 double NeedlemanWunsch(const utility::matrix& s, 39 39 std::vector<std::pair<size_t, size_t> >& path, 40 40 const double gap); -
trunk/c++_tools/utility/Makefile.am
r594 r616 26 26 noinst_LTLIBRARIES = libutility.la 27 27 libutility_la_SOURCES = \ 28 Alignment.cc CommandLine.cc FileIO.cc kNNI.cc NNI.cc Option.cc PCA.cc \ 29 stl_utility.cc SVD.cc utility.cc WeNNI.cc 28 Alignment.cc CommandLine.cc FileIO.cc kNNI.cc matrix.cc NNI.cc \ 29 Option.cc PCA.cc stl_utility.cc SVD.cc utility.cc vector.cc WeNNI.cc 30 30 31 31 32 include_utilitydir = $(includedir)/c++_tools/utility 32 33 33 34 include_utility_HEADERS = \ 34 Alignment.h CommandLine.h Exception.h FileIO.h kNNI.h NNI.h Option.h PCA.h\35 stl_utility.h SVD.h utility.h WeNNI.h35 Alignment.h CommandLine.h Exception.h FileIO.h kNNI.h matrix.h NNI.h \ 36 Option.h PCA.h stl_utility.h SVD.h utility.h vector.h WeNNI.h -
trunk/c++_tools/utility/NNI.cc
r570 r616 37 37 namespace utility { 38 38 39 using namespace std;40 41 39 // For a discussion and motivation for various algorithm 42 40 // implementations here see the paper cited in the class definition 43 41 // documentation. 44 NNI::NNI(const gslapi::matrix& matrix,const gslapi::matrix& weight,42 NNI::NNI(const utility::matrix& matrix,const utility::matrix& weight, 45 43 const u_int neighbours) 46 44 : data_(matrix), imputed_data_(matrix), neighbours_(neighbours), … … 53 51 // {\sum_{k=l,C} w_{ik} w_{jk} } 54 52 // where C is the number of columns 55 vector<pair<u_int,double> > NNI::calculate_distances(const u_int row) const 53 std::vector<std::pair<u_int,double> > 54 NNI::calculate_distances(const u_int row) const 56 55 { 57 vector<pair<u_int,double> > distance;56 std::vector<std::pair<u_int,double> > distance; 58 57 for (size_t i=0; i<data_.rows(); i++) 59 58 if (i!=row) { 60 59 double contribs=0; 61 pair<u_int,double> this_distance(i,0.0);60 std::pair<u_int,double> this_distance(i,0.0); 62 61 for (size_t j=0; j<data_.columns(); j++) 63 62 // 0 contribution for missing values … … 82 81 // number, and neighbours are disqualified if their element (column) 83 82 // weight is zero 84 vector<u_int>83 std::vector<u_int> 85 84 NNI::nearest_neighbours(const u_int column, 86 const vector<pair<u_int,double> >& d) const85 const std::vector<std::pair<u_int,double> >& d) const 87 86 { 88 vector<u_int> index;87 std::vector<u_int> index; 89 88 double contribs=0; 90 89 for (u_int i=0; ((i<d.size()) && -
trunk/c++_tools/utility/NNI.h
r570 r616 1 #ifndef _theplu_utility_nni_ 2 #define _theplu_utility_nni_ 3 1 4 // $Id$ 2 5 … … 25 28 */ 26 29 27 #ifndef _theplu_utility_nni_28 #define _theplu_utility_nni_29 30 30 #include <iostream> 31 31 #include <utility> 32 32 #include <vector> 33 33 34 #include <c++_tools/ gslapi/matrix.h>34 #include <c++_tools/utility/matrix.h> 35 35 36 36 namespace theplu { … … 88 88 /// algorithms. 89 89 /// 90 NNI(const gslapi::matrix& matrix,const gslapi::matrix& weight,90 NNI(const utility::matrix& matrix,const utility::matrix& weight, 91 91 const u_int neighbours); 92 92 … … 103 103 /// @return A const reference to the modified data. 104 104 /// 105 const gslapi::matrix& imputed_data(void) const { return imputed_data_; }105 const utility::matrix& imputed_data(void) const { return imputed_data_; } 106 106 107 107 /// … … 115 115 const std::vector<std::pair<u_int,double> >&) const; 116 116 117 const gslapi::matrix& data_;118 gslapi::matrix imputed_data_;117 const utility::matrix& data_; 118 utility::matrix imputed_data_; 119 119 u_int neighbours_; 120 120 std::vector<size_t> not_imputed_; 121 const gslapi::matrix& weight_;121 const utility::matrix& weight_; 122 122 }; 123 123 -
trunk/c++_tools/utility/PCA.cc
r420 r616 10 10 11 11 namespace theplu { 12 namespace utility { 12 namespace utility { 13 13 14 14 15 void PCA::process() 16 { 17 process_ = true; 18 // Row-center the data matrix 19 gslapi::matrix A_center( A_.rows(), A_.columns() ); 20 this->row_center( A_center ); 21 15 void PCA::process(void) 16 { 17 process_ = true; 18 // Row-center the data matrix 19 utility::matrix A_center( A_.rows(), A_.columns() ); 20 this->row_center( A_center ); 22 21 23 24 25 26 gslapi::matrix U = pSVD->U();27 gslapi::matrix V = pSVD->V();22 // Single value decompose the data matrix 23 std::auto_ptr<SVD> pSVD( new SVD( A_center ) ); 24 pSVD->decompose(); 25 utility::matrix U = pSVD->U(); 26 utility::matrix V = pSVD->V(); 28 27 29 30 eigenvectors_ = U;31 eigenvectors_ .transpose();32 eigenvalues_ = pSVD->s();28 // Read the eigenvectors and eigenvalues 29 eigenvectors_ = U; 30 eigenvectors_ .transpose(); 31 eigenvalues_ = pSVD->s(); 33 32 34 // T 35 for( size_t i = 0; i < eigenvalues_.size(); ++i ) 36 { 37 eigenvalues_[ i ] = eigenvalues_[ i ]*eigenvalues_[ i ]; 38 } 33 // T 34 for( size_t i = 0; i < eigenvalues_.size(); ++i ) 35 eigenvalues_[ i ] = eigenvalues_[ i ]*eigenvalues_[ i ]; 36 eigenvalues_ *= 1.0/A_center.rows(); 39 37 40 eigenvalues_ *= 1.0/A_center.rows(); 41 42 // Sort the eigenvectors in order of eigenvalues 43 // Simple (not efficient) algorithm that always 44 // make sure that the i:th element is in its correct 45 // position (N element --> Ordo( N*N )) 46 for ( size_t i = 0; i < eigenvalues_.size(); ++i ) 47 for ( size_t j = i + 1; j < eigenvalues_.size(); ++j ) 48 if ( eigenvalues_[ j ] > eigenvalues_[ i ] ) { 49 std::swap( eigenvalues_[ i ], eigenvalues_[ j ] ); 50 eigenvectors_.swap_rows(i,j); 51 } 52 } 38 // Sort the eigenvectors in order of eigenvalues 39 // Simple (not efficient) algorithm that always 40 // make sure that the i:th element is in its correct 41 // position (N element --> Ordo( N*N )) 42 for ( size_t i = 0; i < eigenvalues_.size(); ++i ) 43 for ( size_t j = i + 1; j < eigenvalues_.size(); ++j ) 44 if ( eigenvalues_[ j ] > eigenvalues_[ i ] ) { 45 std::swap( eigenvalues_[ i ], eigenvalues_[ j ] ); 46 eigenvectors_.swap_rows(i,j); 47 } 48 } 53 49 54 50 51 void PCA::process_transposed_problem(void) 52 { 53 process_ = true; 54 // Row-center the data matrix 55 utility::matrix A_center( A_.rows(), A_.columns() ); 56 this->row_center( A_center ); 55 57 56 void PCA::process_transposed_problem() 57 { 58 process_ = true; 59 // Row-center the data matrix 60 gslapi::matrix A_center( A_.rows(), A_.columns() ); 61 this->row_center( A_center ); 58 // Transform into SVD friendly dimension 59 A_.transpose(); 60 A_center.transpose(); 62 61 63 // Transform into SVD friendly dimension 64 //////////////////////////////////////// 65 A_.transpose(); 66 A_center.transpose(); 62 // Single value decompose the data matrix 63 std::auto_ptr<SVD> pSVD( new SVD( A_center ) ); 64 pSVD->decompose(); 65 utility::matrix U = pSVD->U(); 66 utility::matrix V = pSVD->V(); 67 67 68 // Single value decompose the data matrix 69 std::auto_ptr<SVD> pSVD( new SVD( A_center ) ); 70 pSVD->decompose(); 71 gslapi::matrix U = pSVD->U(); 72 gslapi::matrix V = pSVD->V(); 68 // Read the eigenvectors and eigenvalues 69 eigenvectors_=V; 70 eigenvectors_.transpose(); 71 eigenvalues_ = pSVD->s(); 73 72 74 // Read the eigenvectors and eigenvalues 75 eigenvectors_=V; 76 eigenvectors_.transpose();77 eigenvalues_ = pSVD->s();73 // Transform back when done with SVD! 74 // (used V insted of U now for eigenvectors) 75 A_.transpose(); 76 A_center.transpose(); 78 77 79 // Transform back when done with SVD! 80 // (used V insted of U now for eigenvectors) 81 //////////////////////////////////////////// 82 A_.transpose(); 83 A_center.transpose(); 78 // T 79 for( size_t i = 0; i < eigenvalues_.size(); ++i ) 80 eigenvalues_[ i ] = eigenvalues_[ i ]*eigenvalues_[ i ]; 81 eigenvalues_ *= 1.0/A_center.rows(); 84 82 85 // T 86 for( size_t i = 0; i < eigenvalues_.size(); ++i ) 87 { 88 eigenvalues_[ i ] = eigenvalues_[ i ]*eigenvalues_[ i ]; 89 } 90 91 eigenvalues_ *= 1.0/A_center.rows(); 92 93 // Sort the eigenvectors in order of eigenvalues 94 // Simple (not efficient) algorithm that always 95 // make sure that the i:th element is in its correct 96 // position (N element --> Ordo( N*N )) 97 for ( size_t i = 0; i < eigenvalues_.size(); ++i ) 98 for ( size_t j = i + 1; j < eigenvalues_.size(); ++j ) 99 if ( eigenvalues_[ j ] > eigenvalues_[ i ] ) { 100 std::swap( eigenvalues_[ i ], eigenvalues_[ j ] ); 101 eigenvectors_.swap_rows(i,j); 102 } 103 } 83 // Sort the eigenvectors in order of eigenvalues 84 // Simple (not efficient) algorithm that always 85 // make sure that the i:th element is in its correct 86 // position (N element --> Ordo( N*N )) 87 for ( size_t i = 0; i < eigenvalues_.size(); ++i ) 88 for ( size_t j = i + 1; j < eigenvalues_.size(); ++j ) 89 if ( eigenvalues_[ j ] > eigenvalues_[ i ] ) { 90 std::swap( eigenvalues_[ i ], eigenvalues_[ j ] ); 91 eigenvectors_.swap_rows(i,j); 92 } 93 } 104 94 105 95 106 107 // This function will row-center the matrix A_, 108 // that is, A_ = A_ - M, where M is a matrix 109 // with the meanvalues of each row 110 void PCA::row_center( gslapi::matrix& A_center ) 111 { 112 meanvalues_ = gslapi::vector( A_.rows() ); 113 gslapi::vector A_row_sum(A_.rows()); 114 for (size_t i=0; i<A_row_sum.size(); ++i) 115 A_row_sum(i)=gslapi::vector(A_,i).sum(); 116 for( size_t i = 0; i < A_center.rows(); ++i ) 117 { 118 meanvalues_[i] = A_row_sum(i) / static_cast<double>(A_.columns()); 119 for( size_t j = 0; j < A_center.columns(); ++j ) 120 A_center(i,j) = A_(i,j) - meanvalues_(i); 121 } 122 } 96 // This function will row-center the matrix A_, 97 // that is, A_ = A_ - M, where M is a matrix 98 // with the meanvalues of each row 99 void PCA::row_center(utility::matrix& A_center) 100 { 101 meanvalues_ = utility::vector( A_.rows() ); 102 utility::vector A_row_sum(A_.rows()); 103 for (size_t i=0; i<A_row_sum.size(); ++i) 104 A_row_sum(i)=utility::vector(A_,i).sum(); 105 for( size_t i = 0; i < A_center.rows(); ++i ) { 106 meanvalues_[i] = A_row_sum(i) / static_cast<double>(A_.columns()); 107 for( size_t j = 0; j < A_center.columns(); ++j ) 108 A_center(i,j) = A_(i,j) - meanvalues_(i); 109 } 110 } 123 111 124 112 113 utility::matrix PCA::projection(const utility::matrix& samples ) const 114 { 115 const size_t Ncol = samples.columns(); 116 const size_t Nrow = samples.rows(); 117 utility::matrix projs( Ncol, Ncol ); 125 118 126 gslapi::matrix PCA::projection( const gslapi::matrix& 127 samples ) const 128 { 129 const size_t Ncol = samples.columns(); 130 const size_t Nrow = samples.rows(); 131 gslapi::matrix projs( Ncol, Ncol ); 132 133 gslapi::vector temp(samples.rows()); 134 for( size_t j = 0; j < Ncol; ++j ) 135 { 119 utility::vector temp(samples.rows()); 120 for( size_t j = 0; j < Ncol; ++j ) { 136 121 for (size_t i=0; i<Ncol; ++i ) 137 temp(i) = samples(i,j); 138 gslapi::vector centered( Nrow ); 139 140 for( size_t i = 0; i < Nrow; ++i ) 141 centered(i) = temp(i) - meanvalues_(i); 142 143 gslapi::vector proj( eigenvectors_ * centered ); 144 for( size_t i = 0; i < Ncol; ++i ) 122 temp(i) = samples(i,j); 123 utility::vector centered( Nrow ); 124 for( size_t i = 0; i < Nrow; ++i ) 125 centered(i) = temp(i) - meanvalues_(i); 126 utility::vector proj( eigenvectors_ * centered ); 127 for( size_t i = 0; i < Ncol; ++i ) 145 128 projs(i,j)=proj(i); 146 } 147 148 }129 } 130 return projs; 131 } 149 132 150 133 134 utility::matrix 135 PCA::projection_transposed(const utility::matrix& samples) const 136 { 137 const size_t Ncol = samples.columns(); 138 const size_t Nrow = samples.rows(); 139 utility::matrix projs( Nrow, Ncol ); 151 140 152 gslapi::matrix PCA::projection_transposed( const gslapi::matrix& 153 samples ) const 154 { 155 const size_t Ncol = samples.columns(); 156 const size_t Nrow = samples.rows(); 157 gslapi::matrix projs( Nrow, Ncol ); 158 159 gslapi::vector temp(samples.rows()); 160 for( size_t j = 0; j < Ncol; ++j ) 161 { 141 utility::vector temp(samples.rows()); 142 for( size_t j = 0; j < Ncol; ++j ) { 162 143 for (size_t i=0; i<Ncol; ++i ) 163 temp(i) = samples(i,j); 164 gslapi::vector centered( Nrow ); 165 166 for( size_t i = 0; i < Nrow; ++i ) 167 centered(i)=temp(i)-meanvalues_(i); 168 169 gslapi::vector proj( eigenvectors_ * centered ); 170 for( size_t i = 0; i < Nrow; ++i ) 171 projs(i,j)=proj(i); 172 } 173 return projs; 174 } 144 temp(i) = samples(i,j); 145 utility::vector centered( Nrow ); 146 for( size_t i = 0; i < Nrow; ++i ) 147 centered(i)=temp(i)-meanvalues_(i); 148 utility::vector proj( eigenvectors_ * centered ); 149 for( size_t i = 0; i < Nrow; ++i ) 150 projs(i,j)=proj(i); 151 } 152 return projs; 153 } 175 154 176 155 177 178 void PCA::calculate_explained_intensity() 179 { 180 size_t DIM = eigenvalues_.size(); 181 explained_intensity_ = gslapi::vector( DIM ); 182 double sum = 0; 183 for( size_t i = 0; i < DIM; ++i ) 184 { 185 sum += eigenvalues_[ i ]; 186 } 187 double exp_sum = 0; 188 for( size_t i = 0; i < DIM; ++i ) 189 { 190 exp_sum += eigenvalues_[ i ]; 191 explained_intensity_[ i ] = exp_sum / sum ; 192 } 193 } 156 void PCA::calculate_explained_intensity(void) 157 { 158 size_t DIM = eigenvalues_.size(); 159 explained_intensity_ = utility::vector( DIM ); 160 double sum = 0; 161 for( size_t i = 0; i < DIM; ++i ) 162 sum += eigenvalues_[ i ]; 163 double exp_sum = 0; 164 for( size_t i = 0; i < DIM; ++i ) { 165 exp_sum += eigenvalues_[ i ]; 166 explained_intensity_[ i ] = exp_sum / sum ; 167 } 168 } 194 169 195 170 196 197 double PCA::get_explained_intensity( const size_t& k ) 198 { 199 if( !explained_calc_ ) 200 { 201 this->calculate_explained_intensity(); 202 explained_calc_ = true; 203 } 204 return explained_intensity_[ k ]; 205 } 171 double PCA::get_explained_intensity( const size_t& k ) 172 { 173 if( !explained_calc_ ) { 174 this->calculate_explained_intensity(); 175 explained_calc_ = true; 176 } 177 return explained_intensity_[ k ]; 178 } 206 179 207 180 -
trunk/c++_tools/utility/PCA.h
r420 r616 1 // $Id$2 3 1 #ifndef _theplu_utility_pca_ 4 2 #define _theplu_utility_pca_ 5 3 6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/gslapi/vector.h> 4 // $Id$ 5 6 #include <c++_tools/utility/matrix.h> 7 #include <c++_tools/utility/vector.h> 8 8 9 9 … … 34 34 should have been performed and no products. 35 35 */ 36 inline explicit PCA(const gslapi::matrix& A)36 inline explicit PCA(const utility::matrix& A) 37 37 : A_(A), process_(false), explained_calc_(false) {} 38 38 … … 59 59 @return Eigenvector \a i. 60 60 */ 61 inline gslapi::vector get_eigenvector(const size_t& i) const62 { return gslapi::vector(eigenvectors_,i); }61 inline utility::vector get_eigenvector(const size_t& i) const 62 { return utility::vector(eigenvectors_,i); } 63 63 64 64 /** … … 83 83 spanned by the eigenvectors. 84 84 */ 85 gslapi::matrix projection( const gslapi::matrix& ) const;85 utility::matrix projection( const utility::matrix& ) const; 86 86 87 87 /** … … 89 89 process_transposed_problem(). 90 90 */ 91 gslapi::matrix projection_transposed( const gslapi::matrix& ) const;91 utility::matrix projection_transposed( const utility::matrix& ) const; 92 92 93 93 94 94 private: 95 gslapi::matrix A_;96 gslapi::matrix eigenvectors_;97 gslapi::vector eigenvalues_;98 gslapi::vector explained_intensity_;99 gslapi::vector meanvalues_;95 utility::matrix A_; 96 utility::matrix eigenvectors_; 97 utility::vector eigenvalues_; 98 utility::vector explained_intensity_; 99 utility::vector meanvalues_; 100 100 bool process_, explained_calc_; 101 101 … … 105 105 with the meanvalues of each row 106 106 */ 107 void row_center( gslapi::matrix& A_center );107 void row_center( utility::matrix& A_center ); 108 108 109 109 /** -
trunk/c++_tools/utility/SVD.cc
r420 r616 17 17 case Jacobi: 18 18 return jacobi(); 19 19 } 20 20 // the program should never end up here, return values should be 21 21 // something different from normal GSL return values, or maybe … … 28 28 int SVD::golub_reinsch(void) 29 29 { 30 gslapi::vector w(U_.columns());30 utility::vector w(U_.columns()); 31 31 return gsl_linalg_SV_decomp(U_.gsl_matrix_p(), V_.gsl_matrix_p(), 32 32 s_.gsl_vector_p(), w.gsl_vector_p()); … … 37 37 int SVD::modified_golub_reinsch(void) 38 38 { 39 gslapi::vector w(U_.columns());40 gslapi::matrix X(U_.columns(),U_.columns());39 utility::vector w(U_.columns()); 40 utility::matrix X(U_.columns(),U_.columns()); 41 41 return gsl_linalg_SV_decomp_mod(U_.gsl_matrix_p(), X.gsl_matrix_p(), 42 42 V_.gsl_matrix_p(), s_.gsl_vector_p(), -
trunk/c++_tools/utility/SVD.h
r597 r616 1 // $Id$2 3 1 #ifndef _theplu_utility_svd_ 4 2 #define _theplu_utility_svd_ 5 3 6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/gslapi/vector.h> 4 // $Id$ 5 6 #include <c++_tools/utility/matrix.h> 7 #include <c++_tools/utility/vector.h> 8 8 9 9 #include <gsl/gsl_linalg.h> … … 52 52 /// input matrix is copied for further use in the object. 53 53 /// 54 inline SVD(const gslapi::matrix& Ain)54 inline SVD(const utility::matrix& Ain) 55 55 : U_(Ain), V_(Ain.columns(),Ain.columns()), s_(Ain.columns()) {} 56 56 … … 73 73 /// is undefined. 74 74 /// 75 inline const gslapi::vector& s(void) const { return s_; }75 inline const utility::vector& s(void) const { return s_; } 76 76 77 77 /// … … 83 83 /// @return Whatever GSL returns. 84 84 /// 85 inline int solve( gslapi::vector b, gslapi::vector x)85 inline int solve(utility::vector b, utility::vector x) 86 86 { return gsl_linalg_SV_solve(U_.gsl_matrix_p(), V_.gsl_matrix_p(), 87 87 s_.gsl_vector_p(), b.gsl_vector_p(), … … 96 96 /// is undefined. 97 97 /// 98 inline const gslapi::matrix& U(void) const { return U_; }98 inline const utility::matrix& U(void) const { return U_; } 99 99 100 100 /// … … 106 106 /// is undefined. 107 107 /// 108 inline const gslapi::matrix& V(void) const { return V_; }108 inline const utility::matrix& V(void) const { return V_; } 109 109 110 110 private: … … 115 115 int modified_golub_reinsch(void); 116 116 117 gslapi::matrix U_, V_;118 gslapi::vector s_;117 utility::matrix U_, V_; 118 utility::vector s_; 119 119 }; 120 120 -
trunk/c++_tools/utility/WeNNI.cc
r570 r616 27 27 #include <c++_tools/utility/WeNNI.h> 28 28 29 #include <c++_tools/utility/matrix.h> 29 30 #include <c++_tools/utility/stl_utility.h> 30 31 … … 37 38 38 39 39 WeNNI::WeNNI(const gslapi::matrix& matrix,const gslapi::matrix& flag,40 WeNNI::WeNNI(const utility::matrix& matrix,const utility::matrix& flag, 40 41 const u_int neighbours) 41 42 : NNI(matrix,flag,neighbours), imputed_data_raw_(matrix) … … 52 53 u_int WeNNI::estimate(void) 53 54 { 54 using namespace std;55 55 for (unsigned int i=0; i<data_.rows(); i++) { 56 56 // Jari, avoid copying in next line 57 vector<pair<u_int,double> > distance=calculate_distances(i);58 57 std::vector<std::pair<u_int,double> > distance=calculate_distances(i); 58 std::sort(distance.begin(),distance.end(), 59 59 pair_value_compare<u_int,double>()); 60 60 bool row_imputed=true; 61 61 for (unsigned int j=0; j<data_.columns(); j++) { 62 vector<u_int> knn=nearest_neighbours(j,distance);62 std::vector<u_int> knn=nearest_neighbours(j,distance); 63 63 double new_value=0.0; 64 64 double norm=0.0; 65 for (vector<u_int>::const_iterator k=knn.begin(); k!=knn.end(); k++) { 65 for (std::vector<u_int>::const_iterator k=knn.begin(); k!=knn.end(); 66 ++k) { 66 67 // Jari, a small number needed here, use something standardized. 67 68 // Avoid division with zero (perfect match vectors) -
trunk/c++_tools/utility/WeNNI.h
r570 r616 1 #ifndef _theplu_utility_wenni_ 2 #define _theplu_utility_wenni_ 3 1 4 // $Id$ 2 5 … … 25 28 */ 26 29 27 #ifndef _theplu_utility_wenni_28 #define _theplu_utility_wenni_29 30 30 #include <c++_tools/utility/NNI.h> 31 31 32 #include <c++_tools/ gslapi/matrix.h>32 #include <c++_tools/utility/matrix.h> 33 33 34 34 #include <iostream> … … 54 54 /// Constructor 55 55 /// 56 WeNNI(const gslapi::matrix& matrix,const gslapi::matrix& weight,56 WeNNI(const utility::matrix& matrix,const utility::matrix& weight, 57 57 const u_int neighbours); 58 58 … … 67 67 /// @return A const reference to imputed_data_raw. 68 68 /// 69 const gslapi::matrix& imputed_data_raw(void) const69 const utility::matrix& imputed_data_raw(void) const 70 70 { return imputed_data_raw_; } 71 71 … … 74 74 private: 75 75 76 gslapi::matrix imputed_data_raw_;76 utility::matrix imputed_data_raw_; 77 77 }; 78 78 -
trunk/c++_tools/utility/kNNI.cc
r570 r616 37 37 namespace utility { 38 38 39 kNNI::kNNI(const gslapi::matrix& matrix,const gslapi::matrix& flag,39 kNNI::kNNI(const utility::matrix& matrix,const utility::matrix& flag, 40 40 const u_int neighbours) 41 41 : NNI(matrix,flag,neighbours) … … 58 58 u_int kNNI::estimate(void) 59 59 { 60 using namespace std;61 60 for (unsigned int i=0; i<mv_rows_.size(); i++) { 62 61 // Jari, avoid copying in next line 63 vector<pair<u_int,double> > distance=calculate_distances(mv_rows_[i]); 64 sort(distance.begin(),distance.end(), 62 std::vector<std::pair<u_int,double> > distance= 63 calculate_distances(mv_rows_[i]); 64 std::sort(distance.begin(),distance.end(), 65 65 pair_value_compare<u_int,double>()); 66 66 for (unsigned int j=0; j<data_.columns(); j++) 67 67 if (!weight_(mv_rows_[i],j)) { 68 vector<u_int> knn=nearest_neighbours(j,distance);68 std::vector<u_int> knn=nearest_neighbours(j,distance); 69 69 double new_value=0.0; 70 70 double norm=0.0; 71 for (vector<u_int>::const_iterator k=knn.begin(); k!=knn.end(); k++){ 71 for (std::vector<u_int>::const_iterator k=knn.begin(); k!=knn.end(); 72 ++k) { 72 73 // Jari, a small number needed here, use something standardized. 73 74 // Avoid division with zero (perfect match vectors) -
trunk/c++_tools/utility/kNNI.h
r570 r616 1 #ifndef _theplu_utility_knni_ 2 #define _theplu_utility_knni_ 3 1 4 // $Id$ 2 5 … … 25 28 */ 26 29 27 #ifndef _theplu_utility_knni_28 #define _theplu_utility_knni_29 30 30 #include <c++_tools/utility/NNI.h> 31 31 … … 52 52 /// Constructor 53 53 /// 54 kNNI(const gslapi::matrix& matrix,const gslapi::matrix& weight,54 kNNI(const utility::matrix& matrix,const utility::matrix& weight, 55 55 const u_int neighbours); 56 56 -
trunk/c++_tools/utility/matrix.cc
r613 r616 25 25 */ 26 26 27 #include <c++_tools/ gslapi/matrix.h>28 29 #include <c++_tools/ gslapi/vector.h>27 #include <c++_tools/utility/matrix.h> 28 29 #include <c++_tools/utility/vector.h> 30 30 #include <c++_tools/utility/stl_utility.h> 31 31 #include <c++_tools/utility/utility.h> … … 39 39 40 40 namespace theplu { 41 namespace gslapi{41 namespace utility { 42 42 43 43 … … 242 242 243 243 244 }} // of namespace gslapiand namespace thep244 }} // of namespace utility and namespace thep -
trunk/c++_tools/utility/matrix.h
r614 r616 1 #ifndef _theplu_utility_matrix_ 2 #define _theplu_utility_matrix_ 3 1 4 // $Id$ 2 5 … … 26 29 */ 27 30 28 #ifndef _theplu_gslapi_matrix_ 29 #define _theplu_gslapi_matrix_ 30 31 #include <c++_tools/gslapi/vector.h> 31 #include <c++_tools/utility/vector.h> 32 32 #include <c++_tools/utility/Exception.h> 33 33 … … 36 36 37 37 namespace theplu { 38 namespace gslapi{38 namespace utility { 39 39 40 40 class vector; … … 51 51 /// 52 52 /// \par[Matrix views] GSL matrix views are supported and these are 53 /// disguised as ordinary gslapi::matrix'es. A support function is54 /// added, gslapi::matrix::isview(), that can be used to check if a53 /// disguised as ordinary utility::matrix'es. A support function is 54 /// added, utility::matrix::isview(), that can be used to check if a 55 55 /// matrix object is a view. Note that view matricess do not own the 56 56 /// undelying data, and a view is not valid if the matrix owning the … … 61 61 /// this interface class. Most notable GSL functionality not 62 62 /// supported are no binary file support and views on arrays, 63 /// gslapi::vectors, gsl_vectors, diagonals, subdiagonals, and63 /// utility::vectors, gsl_vectors, diagonals, subdiagonals, and 64 64 /// superdiagonals. If there is an interest from the user community, 65 65 /// the omitted functionality could be included. … … 464 464 465 465 466 }} // of namespace gslapiand namespace theplu466 }} // of namespace utility and namespace theplu 467 467 468 468 #endif -
trunk/c++_tools/utility/utility.cc
r609 r616 26 26 #include <c++_tools/utility/utility.h> 27 27 28 #include <c++_tools/random/random.h> 28 29 #include <c++_tools/utility/stl_utility.h> 30 #include <c++_tools/utility/vector.h> 29 31 30 32 #include <sstream> … … 88 90 } 89 91 92 93 std::pair<size_t, size_t> minmax_index(const vector& vec, 94 const std::vector<size_t>& subset) 95 { 96 size_t min_index = subset[0]; 97 size_t max_index = subset[0]; 98 for (unsigned int i=1; i<subset.size(); i++) 99 if (vec[subset[i]] < vec[min_index]) 100 min_index = subset[i]; 101 else if (vec[subset[i]] > vec[max_index]) 102 max_index = subset[i]; 103 return std::pair<size_t,size_t>(min_index, max_index); 104 } 105 106 107 void shuffle(vector& invec) 108 { 109 vector vec(invec); 110 random::DiscreteUniform rnd; 111 for (size_t i=0; i<vec.size(); i++){ 112 size_t index = rnd(vec.size()-i); 113 invec[i]=vec(index); 114 vec(index)=vec(vec.size()-i-1); 115 } 116 } 117 118 90 119 }} // end of namespace utility and namespace thep -
trunk/c++_tools/utility/utility.h
r570 r616 1 #ifndef _theplu_utility_utility_ 2 #define _theplu_utility_utility_ 3 1 4 // $Id$ 2 5 … … 24 27 */ 25 28 26 #ifndef _theplu_utility_utility_27 #define _theplu_utility_utility_28 29 29 /// 30 30 /// @file utility/utility.h … … 34 34 35 35 #include <string> 36 #include <utility> 37 #include <vector> 36 38 37 39 namespace theplu { 38 40 namespace utility { 39 41 42 class vector; 40 43 41 44 /// … … 60 63 bool is_nan(const std::string& s); 61 64 65 /** 66 This function returns the indices of the minimum and maximum 67 values in the sub-vector (defined by \a subset), storing them in 68 imin and imax. When there are several equal minimum or maximum 69 elements then the lowest indices are returned. The returned index 70 is the index from the complete vector (not the sub-vector) 71 72 @return Index corresponding to the smallest and largest value. 73 74 @note If \a subset is emtpy, the result is undefined. 75 */ 76 std::pair<size_t,size_t> minmax_index(const vector& vec, 77 const std::vector<size_t>& subset); 78 79 /** 80 Randomly shuffles the elements in vector \a invec 81 */ 82 void shuffle(vector& invec); 83 84 62 85 }} // of namespace utility and namespace theplu 63 86 -
trunk/c++_tools/utility/vector.cc
r613 r616 26 26 */ 27 27 28 #include <c++_tools/ gslapi/vector.h>29 #include <c++_tools/ gslapi/matrix.h>28 #include <c++_tools/utility/vector.h> 29 #include <c++_tools/utility/matrix.h> 30 30 #include <c++_tools/utility/stl_utility.h> 31 31 #include <c++_tools/utility/utility.h> … … 39 39 40 40 namespace theplu { 41 namespace gslapi{41 namespace utility { 42 42 43 43 … … 265 265 266 266 267 }} // of namespace gslapiand namespace thep267 }} // of namespace utility and namespace thep -
trunk/c++_tools/utility/vector.h
r613 r616 1 #ifndef _theplu_utility_vector_ 2 #define _theplu_utility_vector_ 3 1 4 // $Id$ 2 5 … … 26 29 */ 27 30 28 #ifndef _theplu_gslapi_vector_29 #define _theplu_gslapi_vector_30 31 31 #include <c++_tools/utility/Exception.h> 32 32 … … 39 39 40 40 namespace theplu { 41 namespace gslapi{41 namespace utility { 42 42 43 43 class matrix; … … 54 54 /// 55 55 /// \par[Vector views] GSL vector views are supported and these are 56 /// disguised as ordinary gslapi::vectors. A support function is57 /// added, gslapi::vector::isview(), that can be used to check if a56 /// disguised as ordinary utility::vectors. A support function is 57 /// added, utility::vector::isview(), that can be used to check if a 58 58 /// vector object is a view. Note that view vectors do not own the 59 59 /// undelying data, and a view is not valid if the vector owning the … … 491 491 492 492 493 }} // of namespace gslapiand namespace theplu493 }} // of namespace utility and namespace theplu 494 494 495 495 #endif -
trunk/test/alignment_test.cc
r442 r616 3 3 #include <c++_tools/utility/Alignment.h> 4 4 5 #include <c++_tools/ gslapi/matrix.h>5 #include <c++_tools/utility/matrix.h> 6 6 7 7 #include <gsl/gsl_cdf.h> … … 54 54 const std::vector<double>& l2, 55 55 const double sigma, 56 theplu:: gslapi::matrix& dot_matrix,56 theplu::utility::matrix& dot_matrix, 57 57 std::vector<std::pair<size_t,size_t> >& path) 58 58 { 59 dot_matrix = theplu:: gslapi::matrix(l1.size(),l2.size());59 dot_matrix = theplu::utility::matrix(l1.size(),l2.size()); 60 60 for (size_t i=0; i<l1.size(); i++) 61 61 for (size_t j=0; j<l2.size(); j++) { … … 78 78 for (size_t i=0; i<peaksets.size()-1; i++) 79 79 for (size_t j=i+1; j<peaksets.size(); j++) { 80 gslapi::matrix dot_m;80 utility::matrix dot_m; 81 81 std::vector<std::pair<size_t,size_t> > path; 82 82 score(peaksets[i], peaksets[j], 1.0, dot_m, path); -
trunk/test/averager_test.cc
r583 r616 5 5 #include <c++_tools/statistics/AveragerPairWeighted.h> 6 6 #include <c++_tools/statistics/AveragerWeighted.h> 7 #include <c++_tools/ gslapi/vector.h>7 #include <c++_tools/utility/vector.h> 8 8 9 9 #include <fstream> … … 91 91 // Testing AveragerWeighted 92 92 *error << "testing AveragerWeighted" << std::endl; 93 theplu:: gslapi::vector x(3,0);93 theplu::utility::vector x(3,0); 94 94 x(0)=0; 95 95 x(1)=1; 96 96 x(2)=2; 97 theplu:: gslapi::vector w(3,1);97 theplu::utility::vector w(3,1); 98 98 theplu::statistics::AveragerWeighted aw; 99 99 aw.add_values(x,w); … … 152 152 AveragerPairWeighted apw; 153 153 x(0)=0; x(1)=1; x(2)=2; 154 theplu:: gslapi::vector y(3,0);154 theplu::utility::vector y(3,0); 155 155 x(0)=0; x(1)=0; x(2)=2; 156 156 apw.add_values(x,y,w,w); -
trunk/test/consensus_inputranker_test.cc
r615 r616 5 5 #include <c++_tools/classifier/ConsensusInputRanker.h> 6 6 #include <c++_tools/statistics/ROC.h> 7 #include <c++_tools/ gslapi/matrix.h>7 #include <c++_tools/utility/matrix.h> 8 8 #include <c++_tools/classifier/MatrixLookup.h> 9 9 #include <c++_tools/classifier/CrossValidationSampler.h> … … 31 31 32 32 ifstream is("data/rank_data.txt"); 33 theplu:: gslapi::matrix data_tmp(is);33 theplu::utility::matrix data_tmp(is); 34 34 theplu::classifier::MatrixLookup data(data_tmp); 35 35 is.close(); … … 56 56 } 57 57 58 theplu:: gslapi::matrix flag(data.rows(),data.columns(),1);58 theplu::utility::matrix flag(data.rows(),data.columns(),1); 59 59 // Peter, fix weighted version instead 60 60 theplu::classifier::ConsensusInputRanker cir2(sampler,data,roc); -
trunk/test/crossvalidation_test.cc
r615 r616 5 5 #include <c++_tools/classifier/MatrixLookup.h> 6 6 #include <c++_tools/classifier/Target.h> 7 #include <c++_tools/ gslapi/matrix.h>7 #include <c++_tools/utility/matrix.h> 8 8 9 9 #include <cstdlib> … … 40 40 41 41 classifier::Target target(label); 42 gslapi::matrix raw_data(10,10);42 utility::matrix raw_data(10,10); 43 43 classifier::MatrixLookup data(raw_data); 44 44 classifier::CrossValidationSampler cv(target,3,3); … … 81 81 82 82 target=classifier::Target(label); 83 gslapi::matrix raw_data2(2,9);83 utility::matrix raw_data2(2,9); 84 84 for(size_t i=0;i<raw_data2.rows();i++) 85 85 for(size_t j=0;j<raw_data2.columns();j++) -
trunk/test/data_lookup_1d_test.cc
r593 r616 1 1 // $Id$ 2 2 3 #include <c++_tools/ gslapi/matrix.h>3 #include <c++_tools/utility/matrix.h> 4 4 #include <c++_tools/classifier/DataLookup1D.h> 5 5 #include <c++_tools/classifier/MatrixLookup.h> … … 12 12 using namespace theplu; 13 13 14 gslapi::matrix matrix(size_t n);14 utility::matrix matrix(size_t n); 15 15 16 16 int main(const int argc,const char* argv[]) … … 31 31 32 32 *error << "Testing DataLookup1D" << std::endl; 33 gslapi::matrix gsl_m1(matrix(5));33 utility::matrix gsl_m1(matrix(5)); 34 34 std::vector<size_t> index_odd; 35 35 index_odd.push_back(1); … … 97 97 98 98 *error << "Testing that output from ostream operator for DataLookup1D" 99 << " can be used by the gslapi::vector istream constructor...";99 << " can be used by the utility::vector istream constructor..."; 100 100 101 101 // First with a vector with no missing values separated by ' '. … … 104 104 my_out.close(); 105 105 std::ifstream is("data/tmp_test_datalookup1D.txt"); 106 gslapi::vector v5(is);106 utility::vector v5(is); 107 107 is.close(); 108 108 if (v5.size()!=v1.size() || v5(0)!=v1(0) || v5(1)!=v1(1) || … … 122 122 my_out.close(); 123 123 is.open("data/tmp_test_datalookup1D.txt"); 124 gslapi::vector v7(is,'\t');124 utility::vector v7(is,'\t'); 125 125 is.close(); 126 126 if (v7.size()!=v6.size() || !std::isnan(v7(1))) { … … 141 141 } 142 142 143 gslapi::matrix matrix(size_t n)143 utility::matrix matrix(size_t n) 144 144 { 145 gslapi::matrix res(n,n);145 utility::matrix res(n,n); 146 146 for (size_t i=0;i<n;i++) 147 147 for (size_t j=0;j<n;j++) -
trunk/test/ensemble_test.cc
r615 r616 1 1 // $Id$ 2 2 3 #include <c++_tools/gslapi/matrix.h> 4 #include <c++_tools/gslapi/vector.h> 3 #include <c++_tools/utility/matrix.h> 5 4 #include <c++_tools/classifier/SubsetGenerator.h> 6 5 #include <c++_tools/classifier/CrossValidationSampler.h> … … 39 38 *error << "loading data" << std::endl; 40 39 std::ifstream is("data/nm_data_centralized.txt"); 41 gslapi::matrix data_core(is);40 utility::matrix data_core(is); 42 41 is.close(); 43 42 -
trunk/test/inputranker_test.cc
r604 r616 3 3 #include <c++_tools/classifier/InputRanker.h> 4 4 #include <c++_tools/statistics/ROC.h> 5 #include <c++_tools/gslapi/matrix.h> 6 #include <c++_tools/gslapi/matrix.h> 5 #include <c++_tools/utility/matrix.h> 7 6 #include <c++_tools/classifier/MatrixLookup.h> 8 7 #include <c++_tools/classifier/Target.h> … … 29 28 30 29 std::ifstream is("data/rank_data.txt"); 31 theplu:: gslapi::matrix data_tmp(is);30 theplu::utility::matrix data_tmp(is); 32 31 theplu::classifier::MatrixLookup data(data_tmp); 33 32 is.close(); -
trunk/test/kernel_lookup_test.cc
r559 r616 1 1 // $Id$ 2 2 3 #include <c++_tools/ gslapi/matrix.h>3 #include <c++_tools/utility/matrix.h> 4 4 #include <c++_tools/classifier/DataLookup1D.h> 5 5 #include <c++_tools/classifier/KernelLookup.h> … … 30 30 bool ok =true; 31 31 *error << "\nTesting KernelLookup" << std::endl; 32 gslapi::matrix data_core(1,5);32 utility::matrix data_core(1,5); 33 33 for (size_t i=0; i<data_core.columns(); i++) 34 34 data_core(0,i)=i; -
trunk/test/kernel_test.cc
r536 r616 1 1 // $Id$ 2 3 2 4 3 // C++ tools include 5 4 //////////////////// 6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/gslapi/vector.h> 5 #include <c++_tools/utility/matrix.h> 8 6 #include <c++_tools/classifier/KernelFunction.h> 9 7 #include <c++_tools/classifier/PolynomialKernelFunction.h> … … 25 23 bool test_MEV(const classifier::MatrixLookup& data, 26 24 const classifier::KernelFunction* kf, 27 const gslapi::matrix& control, const double error_bound,25 const utility::matrix& control, const double error_bound, 28 26 std::ostream* error); 29 27 30 28 bool test_SEV(const classifier::MatrixLookup& data, 31 29 const classifier::KernelFunction* kf, 32 const gslapi::matrix& control, const double error_bound,30 const utility::matrix& control, const double error_bound, 33 31 std::ostream* error); 34 32 … … 48 46 bool ok = true; 49 47 50 gslapi::matrix data2_core(2,3);48 utility::matrix data2_core(2,3); 51 49 data2_core(0,0)=0; 52 50 data2_core(1,0)=0; … … 77 75 double error_bound = 1e-8; 78 76 std::ifstream is("data/nm_data_centralized.txt"); 79 gslapi::matrix data_core(is);77 utility::matrix data_core(is); 80 78 is.close(); 81 79 … … 83 81 84 82 is.open("data/nm_kernel.txt"); 85 gslapi::matrix kernel_matlab(is);83 utility::matrix kernel_matlab(is); 86 84 is.close(); 87 85 classifier::KernelFunction* kf = new classifier::PolynomialKernelFunction(); … … 91 89 92 90 is.open("data/nm_kernel2.txt"); 93 gslapi::matrix kernel_matlab2(is);91 utility::matrix kernel_matlab2(is); 94 92 is.close(); 95 93 kf = new classifier::PolynomialKernelFunction(2); … … 102 100 delete kf; 103 101 104 data_core = gslapi::matrix(1,5);102 data_core = utility::matrix(1,5); 105 103 for (size_t i=0; i<data_core.columns(); i++) 106 104 data_core(0,i)=i; … … 120 118 bool test_MEV(const classifier::MatrixLookup& data, 121 119 const classifier::KernelFunction* kf, 122 const gslapi::matrix& control, const double error_bound,120 const utility::matrix& control, const double error_bound, 123 121 std::ostream* error) 124 122 { … … 162 160 bool test_SEV(const classifier::MatrixLookup& data, 163 161 const classifier::KernelFunction* kf, 164 const gslapi::matrix& control, const double error_bound,162 const utility::matrix& control, const double error_bound, 165 163 std::ostream* error) 166 164 { -
trunk/test/matrix_lookup_test.cc
r537 r616 1 1 // $Id$ 2 2 3 #include <c++_tools/ gslapi/matrix.h>3 #include <c++_tools/utility/matrix.h> 4 4 #include <c++_tools/classifier/MatrixLookup.h> 5 5 … … 10 10 using namespace theplu; 11 11 12 gslapi::matrix matrix(size_t n);12 utility::matrix matrix(size_t n); 13 13 14 14 int main(const int argc,const char* argv[]) … … 27 27 28 28 *error << "\nTesting MatrixLookup" << std::endl; 29 *error << "MatrixLookup::MatrixLookup(const gslapi::matrix& data)...";30 gslapi::matrix gsl_m1(matrix(2));29 *error << "MatrixLookup::MatrixLookup(const utility::matrix& data)..."; 30 utility::matrix gsl_m1(matrix(2)); 31 31 classifier::MatrixLookup m1(gsl_m1); 32 32 if (m1.rows()!=gsl_m1.rows() || m1.columns()!=gsl_m1.columns() || … … 40 40 41 41 42 *error << "MatrixLookup::MatrixLookup(const gslapi::matrix&,\n"42 *error << "MatrixLookup::MatrixLookup(const utility::matrix&,\n" 43 43 << " const std::vector<size_t>&,\n" 44 44 << " const std::vector<size_t>&)..."; 45 gslapi::matrix gsl_m2(matrix(4));45 utility::matrix gsl_m2(matrix(4)); 46 46 std::vector<size_t> index_odd; 47 47 index_odd.push_back(1); … … 61 61 *error << "Ok" << std::endl; 62 62 63 *error << "MatrixLookup::MatrixLookup(const gslapi::matrix&,\n"63 *error << "MatrixLookup::MatrixLookup(const utility::matrix&,\n" 64 64 << " const std::vector<size_t>&,\n" 65 65 << " const bool)..."; … … 152 152 } 153 153 154 gslapi::matrix matrix(size_t n)154 utility::matrix matrix(size_t n) 155 155 { 156 gslapi::matrix res(n,n);156 utility::matrix res(n,n); 157 157 for (size_t i=0;i<n;i++) 158 158 for (size_t j=0;j<n;j++) -
trunk/test/matrix_test.cc
r611 r616 1 1 // $Id$ 2 2 3 #include <c++_tools/ gslapi/matrix.h>3 #include <c++_tools/utility/matrix.h> 4 4 5 5 #include <unistd.h> … … 13 13 : m_(i,j,value) {} 14 14 15 inline theplu:: gslapi::vector16 row(const size_t& i) { return theplu:: gslapi::vector(m_,i); }17 18 inline const theplu:: gslapi::matrix& matrix(void) const { return m_; }15 inline theplu::utility::vector 16 row(const size_t& i) { return theplu::utility::vector(m_,i); } 17 18 inline const theplu::utility::matrix& matrix(void) const { return m_; } 19 19 20 20 private: 21 theplu:: gslapi::matrix m_;21 theplu::utility::matrix m_; 22 22 }; 23 23 … … 39 39 40 40 *error << "\tcopy constructor and operator!=" << std::endl; 41 gslapi::matrix m(3,3,9);42 gslapi::matrix m2(m);41 utility::matrix m(3,3,9); 42 utility::matrix m2(m); 43 43 if (m2!=m) 44 44 ok=false; … … 51 51 my_out.close(); 52 52 std::ifstream is("data/tmp_test_matrix.txt"); 53 gslapi::matrix m3(is);53 utility::matrix m3(is); 54 54 is.close(); 55 55 if (m3!=m2) … … 58 58 59 59 *error << "\toperator*(double)" << std::endl; 60 gslapi::matrix m4(3,3,1);60 utility::matrix m4(3,3,1); 61 61 m4 *= 9; 62 62 if (m4!=m) { … … 72 72 // lines and other whitespaces. The file is not expected to break 73 73 // things. 74 gslapi::matrix m5(is);74 utility::matrix m5(is); 75 75 is.close(); 76 76 double m5_sum=0; … … 78 78 for (size_t j=0; j<m5.columns(); ++j) 79 79 m5_sum+=m5(i,j); 80 gslapi::matrix* m5sub=new gslapi::matrix(m5,3,3,3,3);80 utility::matrix* m5sub=new utility::matrix(m5,3,3,3,3); 81 81 double m5sub_sum=0; 82 82 for (size_t i=0; i<m5sub->rows(); ++i) … … 98 98 // Checking that the row view works, i.e. mutation to the view are 99 99 // reflected in the viewed object. 100 gslapi::vector v5subrow(m5,3);100 utility::vector v5subrow(m5,3); 101 101 double v5subrow_sum=0; 102 102 for (size_t i=0; i<v5subrow.size(); ++i) { … … 116 116 // Checking that the column view works, i.e. mutation to the view 117 117 // are reflected in the viewed object. 118 gslapi::vector v5subcolumn(m5,0,false);118 utility::vector v5subcolumn(m5,0,false); 119 119 double v5subcolumn_sum=0; 120 120 for (size_t i=0; i<v5subcolumn.size(); ++i) { … … 143 143 // Checking that a view is not inherited through the copy 144 144 // contructor. 145 gslapi::vector v6(v5subrow);145 utility::vector v6(v5subrow); 146 146 v6.set_all(2); 147 147 double v5subrow_sum3=0; … … 164 164 // Checking that vector::operator= indeed makes a view to become a 165 165 // "normal" vector. 166 v5subrow= gslapi::vector(23,22);166 v5subrow=utility::vector(23,22); 167 167 double m5_sum6=0; 168 168 for (size_t i=0; i<m5.rows(); ++i) … … 178 178 *error << "\tthat class member returns a view" << std::endl; 179 179 matrixwrapper mw(5,2); 180 gslapi::vector mwrow=mw.row(2);180 utility::vector mwrow=mw.row(2); 181 181 if (mwrow.gsl_vector_p()->data != &(mw.matrix()(2,0))) { 182 182 ok=false; … … 186 186 *error << "\tsub-matrix of a sub-matrix" << std::endl; 187 187 // Checking that a sub-matrix of a sub-matrix can be created. 188 gslapi::matrix sub(m5,3,3,3,3);189 gslapi::matrix subsub(sub,2,1,1,2);188 utility::matrix sub(m5,3,3,3,3); 189 utility::matrix subsub(sub,2,1,1,2); 190 190 subsub(0,0)=23221121; 191 191 if (&sub(2,1)!=&subsub(0,0) || subsub(0,0)!=m5(5,4) || &subsub(0,0)!=&m5(5,4)){ … … 196 196 *error << "\tmatrix::nan()" << std::endl; 197 197 is.open("data/sorlie_centroids.txt"); 198 gslapi::matrix* m_nan = new gslapi::matrix(is,'\t');199 gslapi::matrix m_weight;198 utility::matrix* m_nan = new utility::matrix(is,'\t'); 199 utility::matrix m_weight; 200 200 m_nan->nan(m_weight); 201 201 is.close(); -
trunk/test/ncc_test.cc
r593 r616 5 5 #include <c++_tools/classifier/NCC.h> 6 6 #include <c++_tools/classifier/Target.h> 7 #include <c++_tools/gslapi/matrix.h> 8 #include <c++_tools/gslapi/vector.h> 7 #include <c++_tools/utility/matrix.h> 9 8 #include <c++_tools/statistics/PearsonDistance.h> 10 9 #include <c++_tools/utility/utility.h> … … 35 34 36 35 std::ifstream is("data/sorlie_centroids.txt"); 37 gslapi::matrix data(is,'\t');36 utility::matrix data(is,'\t'); 38 37 is.close(); 39 38 … … 43 42 44 43 // Generate weight matrix with 0 for missing values and 1 for others. 45 gslapi::matrix weights(data.rows(),data.columns(),0.0);44 utility::matrix weights(data.rows(),data.columns(),0.0); 46 45 for(size_t i=0;i<data.rows();++i) 47 46 for(size_t j=0;j<data.columns();++j) … … 55 54 ncc.train(); 56 55 57 gslapi::matrix prediction;56 utility::matrix prediction; 58 57 ncc.predict(dataview,prediction); 59 58 60 59 is.open("data/sorlie_centroid_predictions.txt"); 61 gslapi::matrix result(is,'\t');60 utility::matrix result(is,'\t'); 62 61 is.close(); 63 62 -
trunk/test/nni_test.cc
r335 r616 2 2 3 3 #include <c++_tools/utility/FileIO.h> 4 #include <c++_tools/ gslapi/matrix.h>4 #include <c++_tools/utility/matrix.h> 5 5 #include <c++_tools/utility/kNNI.h> 6 6 #include <c++_tools/utility/WeNNI.h> … … 42 42 std::ifstream data_stream(knni_data.c_str()); 43 43 std::ifstream weight_stream(knni_weight.c_str()); 44 gslapi::matrix data(data_stream);45 gslapi::matrix weight(weight_stream);44 utility::matrix data(data_stream); 45 utility::matrix weight(weight_stream); 46 46 utility::kNNI knni(data,weight,neighbours); 47 47 knni.estimate(); 48 48 std::ifstream control_stream(knni_result.c_str()); 49 gslapi::matrix control(control_stream);49 utility::matrix control(control_stream); 50 50 control-=knni.imputed_data(); 51 51 // Jari, should we use GSL defined round off errors? Anyway, the … … 75 75 // test WeNNI 76 76 data_stream.open(wenni_data.c_str()); 77 data= gslapi::matrix(data_stream);77 data=utility::matrix(data_stream); 78 78 weight_stream.open(wenni_weight.c_str()); 79 weight= gslapi::matrix(weight_stream);79 weight=utility::matrix(weight_stream); 80 80 utility::WeNNI wenni(data,weight,neighbours); 81 81 wenni.estimate(); 82 82 control_stream.open(wenni_result.c_str()); 83 control= gslapi::matrix(control_stream);83 control=utility::matrix(control_stream); 84 84 control-=wenni.imputed_data(); 85 85 for (unsigned int i=0; i<control.rows(); i++) … … 108 108 // test WeNNI with binary weights 109 109 data_stream.open(knni_data.c_str()); 110 data= gslapi::matrix(data_stream);110 data=utility::matrix(data_stream); 111 111 weight_stream.open(knni_weight.c_str()); 112 weight= gslapi::matrix(weight_stream);112 weight=utility::matrix(weight_stream); 113 113 utility::WeNNI wenni2(data,weight,neighbours); 114 114 wenni2.estimate(); 115 115 control_stream.open(knni_result.c_str()); 116 control= gslapi::matrix(control_stream);116 control=utility::matrix(control_stream); 117 117 control-=wenni2.imputed_data(); 118 118 for (unsigned int i=0; i<control.rows(); i++) -
trunk/test/pca_test.cc
r301 r616 1 1 // $Id$ 2 2 3 #include <c++_tools/utility/matrix.h> 3 4 #include <c++_tools/utility/PCA.h> 4 5 … … 9 10 10 11 11 12 12 using namespace theplu; 13 13 int main() 14 14 { 15 gslapi::matrix A( 3, 4 );15 utility::matrix A( 3, 4 ); 16 16 for( size_t i = 0; i < 3; ++i ) 17 17 for( size_t j = 0; j < 4; ++j ) -
trunk/test/regression_test.cc
r586 r616 1 1 // $Id$ 2 2 3 4 #include <c++_tools/gslapi/matrix.h>5 3 #include <c++_tools/statistics/KernelBox.h> 6 4 #include <c++_tools/statistics/Linear.h> … … 11 9 #include <c++_tools/statistics/Polynomial.h> 12 10 #include <c++_tools/statistics/PolynomialWeighted.h> 11 #include <c++_tools/utility/matrix.h> 12 #include <c++_tools/utility/vector.h> 13 13 14 14 #include <cmath> … … 39 39 40 40 // test data for Linear and Naive (Weighted and non-weighted) 41 gslapi::vector x(4); x(0)=1970; x(1)=1980; x(2)=1990; x(3)=2000;42 gslapi::vector y(4); y(0)=12; y(1)=11; y(2)=14; y(3)=13;43 gslapi::vector w(4); w(0)=0.1; w(1)=0.2; w(2)=0.3; w(3)=0.4;41 utility::vector x(4); x(0)=1970; x(1)=1980; x(2)=1990; x(3)=2000; 42 utility::vector y(4); y(0)=12; y(1)=11; y(2)=14; y(3)=13; 43 utility::vector w(4); w(0)=0.1; w(1)=0.2; w(2)=0.3; w(3)=0.4; 44 44 45 45 *error << "testing regression::LinearWeighted" << std::endl; … … 84 84 { 85 85 std::ifstream s("data/regression_gauss.data"); 86 gslapi::matrix data(s);87 gslapi::vector x(data.rows());88 gslapi::vector ln_y(data.rows());86 utility::matrix data(s); 87 utility::vector x(data.rows()); 88 utility::vector ln_y(data.rows()); 89 89 for (size_t i=0; i<data.rows(); ++i) { 90 90 x(i)=data(i,0); … … 94 94 statistics::regression::Polynomial polynomialfit(2); 95 95 polynomialfit.fit(x,ln_y); 96 gslapi::vector fit=polynomialfit.fit_parameters();96 utility::vector fit=polynomialfit.fit_parameters(); 97 97 if (fabs(fit[0]-1.012229646706 + fit[1]-0.012561322528 + 98 98 fit[2]+1.159674470130)>1e-11) { // Jari, fix number! … … 132 132 rl.fit(10, 100); 133 133 134 gslapi::vector y = rl.y_predicted();134 utility::vector y = rl.y_predicted(); 135 135 for (size_t i=0; i<y.size(); i++) 136 136 if (y(i)!=10.0){ -
trunk/test/score_test.cc
r514 r616 1 1 // $Id$ 2 2 3 #include <c++_tools/gslapi/matrix.h>4 3 #include <c++_tools/statistics/ROC.h> 5 4 #include <c++_tools/statistics/tScore.h> 6 5 #include <c++_tools/statistics/Pearson.h> 7 6 #include <c++_tools/statistics/FoldChange.h> 8 #include <c++_tools/gslapi/vector.h>9 7 #include <c++_tools/statistics/WilcoxonFoldChange.h> 8 #include <c++_tools/utility/matrix.h> 9 #include <c++_tools/utility/vector.h> 10 10 11 11 #include <gsl/gsl_cdf.h> … … 31 31 32 32 *error << "testing ROC" << std::endl; 33 gslapi::vector value(31);33 utility::vector value(31); 34 34 std::vector<std::string> label(31,"negative"); 35 35 for (size_t i=0; i<16; i++) … … 68 68 69 69 std::ifstream is("data/rank_data.txt"); 70 gslapi::matrix data(is);70 utility::matrix data(is); 71 71 is.close(); 72 72 … … 75 75 is.close(); 76 76 77 gslapi::vector correct_area(3);77 utility::vector correct_area(3); 78 78 correct_area(0)=8.0/9.0; 79 79 correct_area(1)=6.0/9.0; … … 82 82 const double tol = 0.001; 83 83 for (size_t i=0; i<data.rows(); i++){ 84 gslapi::vector vec(data,i);84 utility::vector vec(data,i); 85 85 if (vec.size()!=target2.size()){ 86 86 *error << "vec.size() is " << vec.size() << " and target2.size() is " … … 96 96 } 97 97 98 gslapi::vector weight(target2.size(),1);98 utility::vector weight(target2.size(),1); 99 99 for (size_t i=0; i<data.rows(); i++){ 100 gslapi::vector vec(data,i);100 utility::vector vec(data,i); 101 101 area = roc.score(target2, vec, weight); 102 102 if (area<correct_area(i)-tol || area>correct_area(i)+tol){ -
trunk/test/statistics_test.cc
r588 r616 2 2 3 3 #include <c++_tools/statistics/utility.h> 4 #include <c++_tools/ gslapi/vector.h>4 #include <c++_tools/utility/vector.h> 5 5 6 6 #include <vector> … … 12 12 { 13 13 using namespace theplu; 14 gslapi::vector gsl_vec(10);14 utility::vector gsl_vec(10); 15 15 std::vector<double> data; 16 16 for (unsigned int i=0; i<10; i++){ -
trunk/test/svd_test.cc
r420 r616 1 1 // $Id$ 2 2 3 #include <c++_tools/random/random.h> 4 #include <c++_tools/utility/matrix.h> 3 5 #include <c++_tools/utility/SVD.h> 4 #include <c++_tools/gslapi/matrix.h> 5 #include <c++_tools/random/random.h> 6 #include <c++_tools/gslapi/vector.h> 6 #include <c++_tools/utility/vector.h> 7 7 8 8 using namespace theplu; 9 9 10 double this_norm(const gslapi::matrix& A)10 double this_norm(const utility::matrix& A) 11 11 { 12 12 double sum=0.0; … … 26 26 // initialise a random test-matrix 27 27 theplu::random::ContinuousUniform rnd; 28 gslapi::matrix A(m,n);28 utility::matrix A(m,n); 29 29 for (size_t i=0; i<m; ++i) 30 30 for(size_t j=0; j<n; ++j) … … 33 33 utility::SVD svd(A); 34 34 svd.decompose(algo); 35 theplu:: gslapi::vector s(svd.s());36 gslapi::matrix S(s.size(),s.size());35 theplu::utility::vector s(svd.s()); 36 utility::matrix S(s.size(),s.size()); 37 37 for (size_t i=0; i<s.size(); ++i) 38 38 S(i,i)=s[i]; 39 gslapi::matrix Vtranspose=svd.V();39 utility::matrix Vtranspose=svd.V(); 40 40 Vtranspose.transpose(); 41 41 // Reconstructing A = U*S*Vtranspose 42 gslapi::matrix Areconstruct=svd.U();42 utility::matrix Areconstruct=svd.U(); 43 43 Areconstruct*=S; 44 44 Areconstruct*=Vtranspose; … … 63 63 } 64 64 65 gslapi::matrix Utranspose=svd.U();65 utility::matrix Utranspose=svd.U(); 66 66 Utranspose.transpose(); 67 67 Utranspose*=svd.U(); // Expect unity matrix -
trunk/test/svm_test.cc
r527 r616 1 1 // $Id$ 2 2 3 #include <c++_tools/gslapi/matrix.h>4 #include <c++_tools/gslapi/vector.h>5 3 #include <c++_tools/classifier/SVM.h> 6 4 #include <c++_tools/classifier/Kernel.h> … … 9 7 #include <c++_tools/classifier/Kernel_MEV.h> 10 8 #include <c++_tools/classifier/PolynomialKernelFunction.h> 9 #include <c++_tools/utility/matrix.h> 10 #include <c++_tools/utility/vector.h> 11 11 12 12 #include <cassert> … … 32 32 bool ok = true; 33 33 34 gslapi::matrix data2_core(2,3);34 utility::matrix data2_core(2,3); 35 35 data2_core(0,0)=0; 36 36 data2_core(1,0)=0; … … 88 88 89 89 std::ifstream is("data/nm_data_centralized.txt"); 90 gslapi::matrix data_core(is);90 utility::matrix data_core(is); 91 91 is.close(); 92 92 … … 102 102 103 103 is.open("data/nm_alpha_linear_matlab.txt"); 104 theplu:: gslapi::vector alpha_matlab(is);104 theplu::utility::vector alpha_matlab(is); 105 105 is.close(); 106 106 … … 112 112 } 113 113 114 theplu:: gslapi::vector alpha = svm.alpha();114 theplu::utility::vector alpha = svm.alpha(); 115 115 116 116 // Comparing alpha to alpha_matlab 117 theplu:: gslapi::vector diff_alpha(alpha);117 theplu::utility::vector diff_alpha(alpha); 118 118 diff_alpha-=alpha_matlab; 119 119 if (diff_alpha*diff_alpha> 1e-10 ){ … … 123 123 124 124 // Comparing output to target 125 theplu:: gslapi::vector output(svm.output());125 theplu::utility::vector output(svm.output()); 126 126 double slack = 0; 127 127 for (unsigned int i=0; i<target.size(); i++){ -
trunk/test/vector_test.cc
r438 r616 3 3 #include <c++_tools/utility/Exception.h> 4 4 #include <c++_tools/utility/FileIO.h> 5 #include <c++_tools/ gslapi/vector.h>6 #include <c++_tools/ gslapi/utility.h>5 #include <c++_tools/utility/utility.h> 6 #include <c++_tools/utility/vector.h> 7 7 8 8 #include <fstream> … … 24 24 bool ok = true; 25 25 26 gslapi::vector vec(12);26 utility::vector vec(12); 27 27 for (unsigned int i=0; i<vec.size(); i++) 28 28 vec(i)=i; … … 39 39 for (unsigned int i=0; i<vec.size(); i+=2) 40 40 sum_before+=vec[i]; 41 gslapi::vector vec_view(vec,0,6,2);41 utility::vector vec_view(vec,0,6,2); 42 42 sum_after=vec_view.sum(); 43 43 if (sum_after != sum_before) … … 49 49 50 50 // checking that copy constructor creates an independent object 51 gslapi::vector vec2(vec);51 utility::vector vec2(vec); 52 52 if (vec.size()!=vec2.size()) 53 53 ok=false; … … 85 85 std::ifstream data_stream3(data3.c_str()); 86 86 std::ifstream data_stream4(data4.c_str()); 87 vec= gslapi::vector(data_stream1);87 vec=utility::vector(data_stream1); 88 88 if (vec.size()!=9) 89 89 ok=false; 90 vec= gslapi::vector(data_stream2);90 vec=utility::vector(data_stream2); 91 91 if (vec.size()!=9) 92 92 ok=false; 93 vec= gslapi::vector(data_stream3);93 vec=utility::vector(data_stream3); 94 94 if (vec.size()!=12) 95 95 ok=false; 96 vec= gslapi::vector(data_stream4);96 vec=utility::vector(data_stream4); 97 97 if (vec.size()!=12) 98 98 ok=false; … … 107 107 std::stringstream s; 108 108 s << vec; 109 vec2= gslapi::vector(s);109 vec2=utility::vector(s); 110 110 if (!(vec==vec2)) 111 111 ok=false; … … 120 120 check_file_access(data5); 121 121 std::ifstream data_stream5(data5.c_str()); 122 vec= gslapi::vector(data_stream5); // this will give an exception122 vec=utility::vector(data_stream5); // this will give an exception 123 123 } catch (utility::IO_error& err) { 124 124 if (print) … … 130 130 check_file_access(data); 131 131 std::ifstream data_stream(data.c_str()); 132 vec= gslapi::vector(data_stream); // this will give an exception132 vec=utility::vector(data_stream); // this will give an exception 133 133 } catch (utility::IO_error& err) { 134 134 if (print) … … 143 143 check_file_access(data); 144 144 std::ifstream data_stream(data.c_str()); 145 vec= gslapi::vector(data_stream); // this will give an exception145 vec=utility::vector(data_stream); // this will give an exception 146 146 } catch (utility::IO_error& err) { 147 147 if (print)
Note: See TracChangeset
for help on using the changeset viewer.