Changeset 295
- Timestamp:
- Apr 29, 2005, 11:15:58 AM (18 years ago)
- Location:
- trunk/lib
- Files:
-
- 9 added
- 76 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/gslapi/matrix.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "matrix.h"4 5 #include "stl_utility.h"6 #include "vector.h"3 #include <c++_tools/gslapi/matrix.h> 4 5 #include <c++_tools/gslapi/vector.h> 6 #include <c++_tools/utility/stl_utility.h> 7 7 8 8 #include <cmath> -
trunk/lib/gslapi/matrix.h
r294 r295 4 4 #define _theplu_gslapi_matrix_ 5 5 6 #include <c++_tools/gslapi/vector.h> 7 8 #include <gsl/gsl_matrix.h> 6 9 #include <iostream> 7 10 8 #include <gsl/gsl_matrix.h>9 #include "vector.h"10 11 11 12 namespace theplu { … … 62 63 63 64 /// 64 /// Swap column \a i with \ j.65 /// Swap column \a i with \a j. 65 66 /// 66 67 inline void column_swap(const size_t& i,const size_t& j) -
trunk/lib/gslapi/utility.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "gslapi_utility.h" 3 #include <c++_tools/gslapi/gslapi_utility.h> 4 5 #include <c++_tools/gslapi/vector.h> 6 #include <c++_tools/utility/random_singleton.h> 7 4 8 #include <utility> 5 6 #include "random_singleton.h"7 #include "vector.h"8 9 9 10 -
trunk/lib/gslapi/utility.h
r294 r295 6 6 #include <utility> 7 7 8 #include "vector.h" 8 #include <c++_tools/gslapi/vector.h> 9 9 10 10 11 namespace theplu { -
trunk/lib/gslapi/vector.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "vector.h"4 #include "matrix.h"3 #include <c++_tools/gslapi/vector.h> 4 #include <c++_tools/gslapi/matrix.h> 5 5 6 6 #include <iostream> -
trunk/lib/gslapi/vector.h
r294 r295 392 392 /// The output operator for the vector class. 393 393 /// 394 std::ostream& operator<< (std::ostream&, const vector& );394 std::ostream& operator<<(std::ostream&, const vector& ); 395 395 396 396 -
trunk/lib/statistics/Averager.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "Averager.h" 3 #include <c++_tools/statistics/Averager.h> 4 #include <c++_tools/gslapi/vector.h> 4 5 5 6 #include <sys/types.h> 6 7 #include <ostream> 7 #include "vector.h"8 9 8 10 9 namespace theplu { -
trunk/lib/statistics/Averager.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_averager_4 #define _theplu_ cpptools_averager_3 #ifndef _theplu_statistics_averager_ 4 #define _theplu_statistics_averager_ 5 5 6 6 #include <cmath> 7 #include "vector.h"8 7 9 8 namespace theplu{ 9 namespace gslapi{ 10 class vector; 11 } 12 10 13 namespace statistics{ 11 14 class ostream; -
trunk/lib/statistics/AveragerPair.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "AveragerPair.h" 3 #include <c++_tools/statistics/AveragerPair.h> 4 #include <c++_tools/statistics/Averager.h> 4 5 5 #include "Averager.h"6 //#include <sys/types.h>7 //#include <ostream>8 //#include "vector.h"9 6 #include <utility> 10 7 -
trunk/lib/statistics/AveragerPair.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_cpptools_averagerpair_ 4 #define _theplu_cpptools_averagerpair_ 3 #ifndef _theplu_statistics_averagerpair_ 4 #define _theplu_statistics__averagerpair_ 5 6 #include <c++_tools/statistics/Averager.h> 5 7 6 8 #include <cmath> 7 9 #include <utility> 8 10 9 #include "Averager.h"10 11 11 12 namespace theplu{ -
trunk/lib/statistics/AveragerWeighted.cc
r294 r295 1 1 // $Id$ 2 2 3 #include <sys/types.h> 3 #include <c++_tools/statistics/AveragerWeighted.h> 4 #include <c++_tools/statistics/Averager.h> 4 5 5 6 #include <ostream> 6 7 #include "Averager.h" 8 #include "WeightedAverager.h" 7 #include <sys/types.h> 9 8 10 9 namespace theplu { … … 12 11 13 12 14 WeightedAverager::WeightedAverager(void)13 AveragerWeighted::AveragerWeighted(void) 15 14 : w_(Averager()), wx_(Averager()), wwx_(0) 16 15 { 17 16 } 18 17 19 WeightedAverager::WeightedAverager(const double d, const double w)18 AveragerWeighted::AveragerWeighted(const double d, const double w) 20 19 : w_(Averager(w,w*w,1)), wx_(Averager(w*d,w*w*d*d,1)), wwx_(w*w*d) 21 20 { 22 21 } 23 22 24 WeightedAverager::WeightedAverager(const WeightedAverager& a)23 AveragerWeighted::AveragerWeighted(const AveragerWeighted& a) 25 24 : w_(Averager(a.sum_w(), a.sum_ww(),1)), 26 25 wx_(Averager(a.sum_wx(),a.sum_wwxx(),1)), wwx_(a.sum_wwx()) -
trunk/lib/statistics/AveragerWeighted.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_weighted_averager_4 #define _theplu_ cpptools_weighted_averager_3 #ifndef _theplu_statistics_averager_weighted_ 4 #define _theplu_statistics_averager_weighted_ 5 5 6 //#include <cmath> 7 #include "Averager.h" 6 #include <c++_tools/statistics/Averager.h> 7 8 #include <ostream> 8 9 9 10 namespace theplu{ 10 11 namespace statistics{ 12 11 13 /// 12 14 /// Class to calulate simple (first and second moments) averages … … 15 17 /// @see Averager 16 18 /// 17 class WeightedAverager19 class AveragerWeighted 18 20 { 19 21 public: … … 22 24 /// Default constructor 23 25 /// 24 WeightedAverager(void);26 AveragerWeighted(void); 25 27 26 28 /// … … 28 30 /// weight (default = 1) 29 31 /// 30 WeightedAverager(const double, const double=1);32 AveragerWeighted(const double, const double=1); 31 33 32 34 /// 33 35 /// Copy constructor 34 36 /// 35 WeightedAverager(const WeightedAverager&);37 AveragerWeighted(const AveragerWeighted&); 36 38 37 39 /// … … 117 119 118 120 /// 119 /// operator to add a WeightedAverager121 /// operator to add a AveragerWeighted 120 122 /// 121 inline WeightedAverager operator+=(WeightedAverager& a)123 inline AveragerWeighted operator+=(AveragerWeighted& a) 122 124 { wx_+=a.wx(); w_+=a.w(); wwx_+=a.sum_wwx(); return *this; } 123 125 … … 133 135 134 136 /// 135 /// The WeightedAverageroutput operator137 /// The AveragerWeighted output operator 136 138 /// 137 std::ostream& operator<<(std::ostream& s,const WeightedAverager&);139 std::ostream& operator<<(std::ostream& s,const AveragerWeighted&); 138 140 139 141 }} // of namespace statistics and namespace theplu -
trunk/lib/statistics/Fisher.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "Fisher.h" 4 5 #include "Score.h" 6 #include "Statistics.h" 3 #include <c++_tools/statistics/Fisher.h> 4 #include <c++_tools/statistics/Score.h> 5 #include <c++_tools/statistics/Statistics.h> 7 6 8 7 namespace theplu { 9 namespace cpptools {8 namespace statistics { 10 9 11 10 … … 22 21 { 23 22 // If a column sum or a row sum is zero, the table is nonsense 24 if ( a*d==0 && c*b==0){25 std::c out << "Fisher: Table is not valid\n";26 exit (-1);23 if ((a==0 || d==0) && (c==0 || b==0)){ 24 std::cerr << "Warning: Fisher: Table is not valid\n"; 25 return 1.0; 27 26 } 28 27 29 if (a*b*c*d){ 30 double ratio=a/b*d/c; 31 if (absolute_ && ratio<1) 32 return 1/ratio; 33 else 34 return ratio; 35 } 36 else 37 return 0.0; 28 double ratio=(a*d)/(b*d); 29 if (absolute_ && ratio<1) 30 return 1/ratio; 31 else 32 return ratio; 38 33 } 39 34 … … 66 61 else 67 62 train_set_ = train_set; 68 a_=0;69 63 a_=b_=c_=d_=0; 70 64 for (size_t i=0; i<train_set_.size(); i++) … … 81 75 82 76 // If a column sum or a row sum is zero, the table is nonsense 83 if ( a_*d_==0 && c_*b_==0){84 std::c out << "Fisher: Table is not valid\n";85 exit (-1);77 if ((a_==0 || d_==0) && (c_==0 || b_==0)){ 78 std::cerr << "Warning: Fisher: Table is not valid\n"; 79 return 0; 86 80 } 87 81 … … 136 130 } 137 131 138 }} // of namespace cpptools and namespace theplu132 }} // of namespace statistics and namespace theplu -
trunk/lib/statistics/Fisher.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_fisher_4 #define _theplu_ cpptools_fisher_3 #ifndef _theplu_statistics_fisher_ 4 #define _theplu_statistics_fisher_ 5 5 6 // C++ tools include 7 ///////////////////// 8 #include "Score.h" 9 #include "vector.h" 10 //#include <gsl/gsl_cdf.h> 6 #include <c++_tools/statistics/Score.h> 7 #include <c++_tools/gslapi/vector.h> 11 8 12 // Standard C++ includes13 ////////////////////////14 //#include <utility>15 //#include <vector>16 9 17 10 namespace theplu { 18 namespace cpptools {11 namespace statistics { 19 12 /// 20 13 /// Class for Fisher's exact test. … … 65 58 66 59 /// 60 /// Function calculating score from 2x2 table for which the 61 /// elements are calculated as follows \n 62 /// a: #data \f$ x=1 \f$ AND \f$ y=1 \f$ \n 63 /// b: #data \f$ x=-1 \f$ AND \f$ y=1 \f$ \n 64 /// c: #data \f$ x=1 \f$ AND \f$ y=-1 \f$ \n 65 /// d: #data \f$ x=-1 \f$ AND \f$ y=1 \f$ \n 66 /// 67 67 /// @return odds ratio. If absolute_ is true and odds ratio is 68 68 /// less than unity 1 divided by odds ratio is returned 69 69 /// 70 double score(const gslapi::vector& , const gslapi::vector&,70 double score(const gslapi::vector& x, const gslapi::vector& y, 71 71 const std::vector<size_t>& = std::vector<size_t>()); 72 72 73 73 /// 74 /// Weighted version of odds ratio. Each element in 2x2 table is75 /// calculated as \f$ \sum w eight_i \f$, so when each weight is74 /// Weighted version of score. Each element in 2x2 table is 75 /// calculated as \f$ \sum w_i \f$, so when each weight is 76 76 /// unitary the same table is created as in the unweighted version 77 77 /// @return odds ratio 78 78 /// 79 double score(const gslapi::vector& , const gslapi::vector&,80 const gslapi::vector& ,79 double score(const gslapi::vector& x, const gslapi::vector& y, 80 const gslapi::vector& w, 81 81 const std::vector<size_t>& = std::vector<size_t>()); 82 82 83 83 /// 84 /// @return odds ratio \f$ ad/bc\f$84 /// \f$ \frac{ad}{bc} \f$ 85 85 /// 86 double score(const u_int, const u_int, const u_int, const u_int); 86 /// @return odds ratio. If absolute_ is true and odds ratio is 87 /// less than unity, 1 divided by odds ratio is returned 88 /// 89 double score(const u_int a, const u_int b, 90 const u_int c, const u_int d); 87 91 88 double oddsratio(const double, const double,89 const double, const double) const;90 92 91 93 … … 98 100 u_int d_; 99 101 102 double oddsratio(const double a, const double b, 103 const double c, const double d) const; 100 104 101 105 }; 102 106 103 }} // of namespace cpptools and namespace theplu107 }} // of namespace statistics and namespace theplu 104 108 105 109 #endif -
trunk/lib/statistics/Histogram.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_cpptools_histogram_ 4 #define _theplu_cpptools_histogram_ 3 #ifndef _theplu_statistics_histogram_ 4 #define _theplu_statistics_histogram_ 5 6 #include <c++_tools/statistics/AveragerWeighted.h> 5 7 6 8 #include <string> 7 9 #include <vector> 8 10 9 #include "WeightedAverager.h"10 11 11 12 12 namespace theplu { 13 namespace cpptools {13 namespace statistics { 14 14 15 15 /// … … 58 58 59 59 /// 60 /// Gives access to the WeightedAveragerobject that keeps track of60 /// Gives access to the AveragerWeighted object that keeps track of 61 61 /// average of all events presented to the histogram. 62 62 /// 63 63 /// @short Average of all events presented to the histogram. 64 64 /// 65 /// @return A const reference to an WeightedAveragerobject.65 /// @return A const reference to an AveragerWeighted object. 66 66 /// 67 inline const statistics:: WeightedAverager& averager_all(void) const67 inline const statistics::AveragerWeighted& averager_all(void) const 68 68 { return sum_all_; } 69 69 70 70 /// 71 /// Gives access to the WeightedAveragerobject that keeps track of71 /// Gives access to the AveragerWeighted object that keeps track of 72 72 /// average of events that fits within the histogram lower and 73 73 /// upper limits. This function is equivalent to averager(). … … 75 75 /// @short Average of events fitting within histogram. 76 76 /// 77 /// @return A const reference to an WeightedAveragerobject.77 /// @return A const reference to an AveragerWeighted object. 78 78 /// 79 inline const statistics:: WeightedAverager& averager_histogram(void) const79 inline const statistics::AveragerWeighted& averager_histogram(void) const 80 80 { return sum_histogram_; } 81 81 … … 144 144 double xmax_; 145 145 double xmin_; 146 statistics:: WeightedAveragersum_all_; // average of all data147 statistics:: WeightedAveragersum_histogram_;// average of data in histogram146 statistics::AveragerWeighted sum_all_; // average of all data 147 statistics::AveragerWeighted sum_histogram_;// average of data in histogram 148 148 }; 149 149 … … 153 153 std::ostream& operator<<(std::ostream& s,const Histogram&); 154 154 155 }} // of namespace cpptools and namespace theplu155 }} // of namespace statistics and namespace theplu 156 156 157 157 #endif -
trunk/lib/statistics/Kernel.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "RegressionKernel.h"3 #include <c++_tools/statistics/Kernel.h> 4 4 5 5 namespace theplu{ 6 6 namespace statistics{ 7 7 8 RegressionKernel::RegressionKernel(void)8 Kernel::Kernel(void) 9 9 { 10 10 } -
trunk/lib/statistics/Kernel.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_statistics_ regression_kernel_4 #define _theplu_statistics_ regression_kernel_3 #ifndef _theplu_statistics_kernel_ 4 #define _theplu_statistics_kernel_ 5 5 6 6 namespace theplu { … … 11 11 /// 12 12 13 class RegressionKernel13 class Kernel 14 14 { 15 15 … … 18 18 /// Constructor 19 19 /// 20 RegressionKernel();20 Kernel(); 21 21 22 22 /// -
trunk/lib/statistics/KernelBox.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "RegressionKernelBox.h" 4 5 #include "RegressionKernel.h" 3 #include <c++_tools/statistics/KernelBox.h> 4 #include <c++_tools/statistics/Kernel.h> 6 5 7 6 namespace theplu { 8 7 namespace statistics { 9 8 10 RegressionKernelBox::RegressionKernelBox(void)11 : RegressionKernel()9 KernelBox::KernelBox(void) 10 : Kernel() 12 11 { 13 12 } 14 13 15 double RegressionKernelBox::weight(const double u) const14 double KernelBox::weight(const double u) const 16 15 { 17 16 if (u>1 || u<-1) -
trunk/lib/statistics/KernelTriCube.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "RegressionKernelTriCube.h"4 #include "RegressionKernel.h"3 #include <c++_tools/statistics/KernelTriCube.h> 4 #include <c++_tools/statistics/Kernel.h> 5 5 6 6 #include <cmath> … … 9 9 namespace statistics { 10 10 11 RegressionKernelTriCube::RegressionKernelTriCube(void)12 : RegressionKernel()11 KernelTriCube::KernelTriCube(void) 12 : Kernel() 13 13 { 14 14 } 15 15 16 double RegressionKernelTriCube::weight(const double x) const16 double KernelTriCube::weight(const double x) const 17 17 { 18 18 if (x>1 || x<-1) -
trunk/lib/statistics/KernelTriCube.h
r294 r295 2 2 3 3 4 #ifndef _theplu_statistics_ regression_kernel_tricube_5 #define _theplu_statistics_ regression_kernel_tricube_4 #ifndef _theplu_statistics_kernel_tricube_ 5 #define _theplu_statistics_kernel_tricube_ 6 6 7 #include "RegressionKernel.h" 7 #include <c++_tools/statistics/Kernel.h> 8 8 9 9 10 namespace theplu { … … 14 15 /// 15 16 16 class RegressionKernelTriCube : public RegressionKernel17 class KernelTriCube : public Kernel 17 18 { 18 19 … … 21 22 /// Constructor 22 23 /// 23 RegressionKernelTriCube() ;24 KernelTriCube() ; 24 25 25 26 /// -
trunk/lib/statistics/Pearson.cc
r294 r295 2 2 3 3 4 #include "Pearson.h"4 #include <c++_tools/statistics/Pearson.h> 5 5 6 // System includes 6 #include <c++_tools/statistics/AveragerPair.h> 7 #include <c++_tools/gslapi/vector.h> 8 7 9 #include <cmath> 8 10 #include <gsl/gsl_cdf.h> 9 11 10 // Thep C++ Tools11 #include "AveragerPair.h"12 #include "vector.h"13 14 12 15 13 namespace theplu { 16 namespace cpptools {14 namespace statistics { 17 15 18 16 Pearson::Pearson(bool b) 19 : Score(b), r_(0), nof_samples_(0) , weighted_(true)17 : Score(b), r_(0), nof_samples_(0) 20 18 { 21 19 } 22 20 23 void centralize (vector& x, constvector& w)21 void Pearson::centralize(gslapi::vector& x, const gslapi::vector& w) 24 22 { 25 23 double m = (x*w)/w.sum(); … … 28 26 } 29 27 30 double Pearson::p_value() const ;28 double Pearson::p_value() const 31 29 { 32 30 if(weighted_) 33 31 return 1; 34 32 else if(nof_samples_<3){ 35 std::cerr << "Warning: Only " << nof_samples_ << "samples. " <<33 std::cerr << "Warning: Only " << nof_samples_ << "samples. " 36 34 << "Need at lest 3.\n"; 37 35 return 1; 38 36 } 39 37 else{ 40 t = sqrt(nof_samples_ - 2)*abs(r_) /sqrt(1-r_*r_); 41 p = 2*gsl_cdf_tdist_Q (t, nof_samples_ -2 ); 42 return p; 38 double t = sqrt(nof_samples_ - 2)*fabs(r_) /sqrt(1-r_*r_); 39 return 2*gsl_cdf_tdist_Q (t, nof_samples_ -2 ); 43 40 } 44 41 } 45 42 46 43 double Pearson::score(const gslapi::vector& vec1, const gslapi::vector& vec2, 47 const std::vector<size_t>& = std::vector<size_t>());44 const std::vector<size_t>& train_set) 48 45 { 49 46 weighted_=false; 47 AveragerPair ap; 50 48 if (!train_set.size()){ 51 AveragerPair x(vec1,vec2); 49 ap = AveragerPair(vec1.sum(),vec1*vec1,vec2.sum(),vec2*vec2, 50 vec1*vec2,vec1.size()); 52 51 nof_samples_ = vec1.size(); 53 52 } 54 53 else{ 55 Averager a();56 54 for (size_t i=0; i<train_set.size(); i++){ 57 a .add(vec1(train_set[i]), vec2(train_set[i]));55 ap.add(vec1(train_set[i]), vec2(train_set[i])); 58 56 } 59 57 nof_samples_ = train_set.size(); 60 58 } 61 r_ = a.correlation(); 62 weighted_=false; 63 if (r<0 && absolute_) 59 r_ = ap.correlation(); 60 if (r_<0 && absolute_) 64 61 r_=-r_; 65 62 … … 68 65 69 66 double Pearson::score(const gslapi::vector& vec1, const gslapi::vector& vec2, 70 const gslapi::vector& w eight,67 const gslapi::vector& w1, const gslapi::vector& w2, 71 68 const std::vector<size_t>& train_set = 72 std::vector<size_t>()) ;69 std::vector<size_t>()) 73 70 { 74 71 weighted_=true; 72 gslapi::vector x; 73 gslapi::vector y; 74 gslapi::vector wx; 75 gslapi::vector wy; 75 76 if (!train_set.size()){ 76 gslapi::vector x = vec1; 77 gslapi::vector y = vec2; 78 gslapi::vector w = weights; 77 x = vec1; 78 y = vec2; 79 wx = w1; 80 wy = w2; 79 81 nof_samples_ = vec1.size(); 80 82 } 81 83 else{ 82 84 nof_samples_ = train_set.size(); 83 gslapi::vector x(nof_samples_); 84 gslapi::vector y(nof_samples_); 85 gslapi::vector w(nof_samples_); 85 x = gslapi::vector(nof_samples_); 86 y = gslapi::vector(nof_samples_); 87 wx = gslapi::vector(nof_samples_); 88 wy = gslapi::vector(nof_samples_); 86 89 for (size_t i=0; i<train_set.size(); i++){ 87 90 x(i)=vec1(train_set[i]); 88 91 y(i)=vec2(train_set[i]); 89 w(i)=weight(train_set[i]); 92 wx(i)=w1(train_set[i]); 93 wy(i)=w2(train_set[i]); 90 94 } 91 95 } 92 96 93 centralize(x,w );94 centralize(y,w );97 centralize(x,wx); 98 centralize(y,wy); 95 99 96 r_ = ( (x.mul_elements(w)*y) / 97 sqrt( (x.mul_elements(w)*x)*(y.mul_elements(w)*y)) ); 100 x.mul(wx); 101 y.mul(wy); 102 103 r_ = ( (x*y) / sqrt( (x*x)*(y*y)) ); 98 104 weighted_=true; 99 105 100 if (r <0 && absolute_)106 if (r_<0 && absolute_) 101 107 r_=-r_; 102 108 103 109 return r_; 104 }105 106 double Pearson::score(const gslapi::vector& vec1, const gslapi::vector& vec2,107 const gslapi::vector& w1, const gslapi::vector& w2,108 const std::vector<size_t>& train_set =109 std::vector<size_t>());110 {111 weighted_=true;112 return = score(vec1, vec2, w1.mul_elements(w2),train_set);113 110 } 114 111 115 }} // of namespace cpptools and namespace theplu112 }} // of namespace statistics and namespace theplu -
trunk/lib/statistics/Pearson.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_pearson_4 #define _theplu_ cpptools_pearson_3 #ifndef _theplu_statistics_pearson_ 4 #define _theplu_statistics_pearson_ 5 5 6 // C++ tools include 7 ///////////////////// 8 #include "Score.h" 9 #include "vector.h" 10 //#include <gsl/gsl_cdf.h> 11 12 // Standard C++ includes 13 //////////////////////// 14 //#include <utility> 15 //#include <vector> 16 6 #include <c++_tools/statistics/Score.h> 17 7 18 8 //Peter, should add a function to get the sign of the correlation 19 9 namespace theplu { 20 namespace cpptools { 10 class gslapi::vector; 11 12 namespace statistics { 13 21 14 /// 22 15 /// Class for calculating Pearson correlation. … … 48 41 49 42 /// 50 /// \f$ \frac{\vert \sum_iw _i(x_i-\bar{x})(y_i-\bar{y})\vert }51 /// {\sqrt{\sum_iw _i(x_i-\bar{x})^2\sum_iw_i(x_i-\bar{x})^2}}\f$,43 /// \f$ \frac{\vert \sum_iw^2_i(x_i-\bar{x})(y_i-\bar{y})\vert } 44 /// {\sqrt{\sum_iw^2_i(x_i-\bar{x})^2\sum_iw^2_i(y_i-\bar{y})^2}}\f$, 52 45 /// where \f$m_x = \frac{\sum w_ix_i}{\sum w_i}\f$ and \f$m_x = 53 46 /// \frac{\sum w_ix_i}{\sum w_i}\f$. This expression is chosen to … … 56 49 /// correlation. 57 50 /// 58 double score(const gslapi::vector& x, const gslapi::vector& y, 59 const gslapi::vector& w, 60 const std::vector<size_t>& = std::vector<size_t>()); 51 inline double score(const gslapi::vector& x, const gslapi::vector& y, 52 const gslapi::vector& w, 53 const std::vector<size_t>& train_set = 54 std::vector<size_t>()) 55 { return score(x,y,w,w,train_set); } 61 56 62 57 /// … … 72 67 double score(const gslapi::vector& x, const gslapi::vector& y, 73 68 const gslapi::vector& wx, const gslapi::vector& wy, 74 const std::vector<size_t>& = std::vector<size_t>());69 const std::vector<size_t>&); 75 70 76 71 /// … … 88 83 89 84 90 void centralize( vector, const vector);85 void centralize(gslapi::vector&, const gslapi::vector&); 91 86 }; 92 87 93 }} // of namespace cpptools and namespace theplu88 }} // of namespace statistics and namespace theplu 94 89 95 90 #endif -
trunk/lib/statistics/ROC.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "ROC.h"3 #include <c++_tools/statistics/ROC.h> 4 4 5 // System includes 5 #include <c++_tools/utility/stl_utility.h> 6 #include <c++_tools/gslapi/vector.h> 7 8 #include <gsl/gsl_cdf.h> 9 6 10 #include <cmath> 7 #include <gsl/gsl_cdf.h>8 11 #include <iostream> 9 12 #include <utility> 10 13 #include <vector> 11 14 12 // Thep C++ Tools13 #include "stl_utility.h"14 #include "vector.h"15 15 16 16 namespace theplu { 17 namespace cpptools {17 namespace statistics { 18 18 19 19 ROC::ROC(bool b) … … 151 151 } 152 152 std::sort(value_.begin(),value_.end(), 153 pair_value_compare<double, double>());153 cpptools::pair_value_compare<double, double>()); 154 154 } 155 155 -
trunk/lib/statistics/ROC.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_roc_4 #define _theplu_ cpptools_roc_3 #ifndef _theplu_statistics_roc_ 4 #define _theplu_statistics_roc_ 5 5 6 // C++ tools include 7 ///////////////////// 8 #include "Score.h" 9 #include "vector.h" 6 #include <c++_tools/gslapi/vector.h> 7 #include <c++_tools/statistics/Score.h> 10 8 11 // Standard C++ includes12 ////////////////////////13 9 #include <utility> 14 10 #include <vector> 15 11 16 12 namespace theplu { 17 namespace cpptools {13 namespace statistics { 18 14 /// 19 15 /// Class for ROC (Reciever Operating Characteristic). … … 94 90 /// data. 95 91 std::vector<std::pair<double, double> > value_; 92 93 /// Implemented as in MatLab 13.1 94 double ROC::get_p_approx(const double) const; 96 95 97 98 ///99 ///100 96 /// Implemented as in MatLab 13.1 101 /// @return the p-value102 ///103 double ROC::get_p_approx(const double) const;104 105 ///106 /// @return the p-value107 ///108 97 double ROC::get_p_exact(const double, const double, 109 98 const double) const; 110 111 /// 99 112 100 /// sorting value_, should always be done when changing train_set_ 113 ///114 101 void ROC::sort(); 115 102 … … 124 111 125 112 126 }} // of namespace cpptools and namespace theplu113 }} // of namespace statistics and namespace theplu 127 114 128 115 #endif -
trunk/lib/statistics/Regression.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "Regression.h"3 #include <c++_tools/statistics/Regression.h> 4 4 5 5 namespace theplu { -
trunk/lib/statistics/Regression.h
r294 r295 4 4 #define _theplu_statistics_regression_ 5 5 6 #include "vector.h" 7 6 #include <ostream> 8 7 9 8 namespace theplu { 9 namespace gslapi { 10 class vector; 11 } 12 10 13 namespace statistics { 11 14 … … 46 49 const gslapi::vector& w)=0; 47 50 /// 48 /// 51 /// function predicting in one point 49 52 /// 50 53 virtual void predict(const double x, double& y, double& y_err, … … 61 64 62 65 protected: 66 /// 67 /// x for predicted point 68 /// 63 69 double x_; 70 /// 71 /// y for predicted point 72 /// 64 73 double y_; 74 /// 75 /// estimated error of predicted point (in y). 76 /// 65 77 double y_err_; 66 78 }; -
trunk/lib/statistics/RegressionLinear.cc
r294 r295 1 1 // $Id$ 2 2 3 // Header 4 #include "RegressionLinear.h" 3 #include <c++_tools/statistics/RegressionLinear.h> 5 4 6 // C++_tools 7 #include "AveragerPair.h" 8 #include "Regression.h" 9 #include "vector.h" 5 #include <c++_tools/statistics/AveragerPair.h> 6 #include <c++_tools/statistics/Regression.h> 7 #include <c++_tools/gslapi/vector.h> 10 8 11 9 #include <gsl/gsl_fit.h> -
trunk/lib/statistics/RegressionLinear.h
r294 r295 4 4 #define _theplu_statistics_regression_linear_ 5 5 6 // C++ tools include 7 ///////////////////// 8 #include "Regression.h" 9 #include "vector.h" 6 #include <c++_tools/statistics/Regression.h> 7 #include <c++_tools/gslapi/vector.h> 10 8 11 // Standard C++ includes12 ////////////////////////13 9 #include <cmath> 14 10 -
trunk/lib/statistics/RegressionLocal.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "RegressionLocal.h"3 #include <c++_tools/statistics/RegressionLocal.h> 4 4 5 #include "Regression.h" 6 #include "RegressionKernel.h" 7 #include "RegressionLinear.h" 8 #include "vector.h" 5 #include <c++_tools/gslapi/vector.h> 6 #include <c++_tools/statistics/Kernel.h> 7 #include <c++_tools/statistics/Regression.h> 9 8 10 #include "algorithm" 9 //#include <algorithm> 11 10 12 11 namespace theplu { 13 12 namespace statistics { 14 13 15 RegressionLocal::RegressionLocal(Regression& r, 16 RegressionKernel& k) 14 RegressionLocal::RegressionLocal(Regression& r, Kernel& k) 17 15 : kernel_(&k), regressor_(&r) 18 16 { -
trunk/lib/statistics/RegressionLocal.h
r294 r295 4 4 #define _theplu_statistics_regression_local_ 5 5 6 // C++ tools include 7 ///////////////////// 8 #include "Regression.h" 9 #include "RegressionKernel.h" 10 #include "vector.h" 6 #include <c++_tools/statistics/RegressionLocal.h> 11 7 12 // Standard C++ includes 13 //////////////////////// 8 #include <c++_tools/statistics/Kernel.h> 9 #include <c++_tools/statistics/Regression.h> 10 #include <c++_tools/gslapi/vector.h> 14 11 15 12 … … 46 43 /// type of \a kernel. 47 44 /// 48 RegressionLocal(Regression& regressor, RegressionKernel& kernel);45 RegressionLocal(Regression& regressor, Kernel& kernel); 49 46 50 47 /// … … 97 94 private: 98 95 std::vector<std::pair<double, double> > data_; 99 RegressionKernel* kernel_;96 Kernel* kernel_; 100 97 Regression* regressor_; 101 98 std::vector<double> x_; -
trunk/lib/statistics/RegressionNaive.cc
r294 r295 2 2 3 3 4 #include "RegressionNaive.h"4 #include <c++_tools/statistics/RegressionNaive.h> 5 5 6 #include "Averager.h"7 #include "Regression.h"8 #include "vector.h"9 #include "WeightedAverager.h"6 #include <c++_tools/statistics/Averager.h> 7 #include <c++_tools/statistics/AveragerWeighted.h> 8 #include <c++_tools/statistics/Regression.h> 9 #include <c++_tools/gslapi/vector.h> 10 10 11 11 #include <iostream> … … 35 35 const gslapi::vector& w) 36 36 { 37 WeightedAveragera;37 AveragerWeighted a; 38 38 for (size_t i=0; i<y.size(); i++) 39 39 a.add(y(i), w(i)); -
trunk/lib/statistics/RegressionNaive.h
r294 r295 4 4 #define _theplu_statistics_regression_naive_ 5 5 6 // C++ tools include 7 ///////////////////// 8 #include "Averager.h" 9 #include "Regression.h" 10 #include "vector.h" 11 #include "WeightedAverager.h" 12 // Standard C++ includes 13 //////////////////////// 14 //#include <gsl/gsl_fit.h> 6 #include <c++_tools/statistics/Regression.h> 7 8 #include <c++_tools/gslapi/vector.h> 9 #include <c++_tools/statistics/Averager.h> 10 #include <c++_tools/statistics/AveragerWeighted.h> 11 #include <c++_tools/statistics/RegressionNaive.h> 12 15 13 #include <iostream> 16 14 #include <utility> -
trunk/lib/statistics/Score.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "Score.h"3 #include <c++_tools/statistics/Score.h> 4 4 5 5 namespace theplu { 6 namespace cpptools {6 namespace statistics { 7 7 8 8 Score::Score(bool absolute) -
trunk/lib/statistics/Score.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_score_4 #define _theplu_ cpptools_score_3 #ifndef _theplu_statistics_score_ 4 #define _theplu_statistics_score_ 5 5 6 #include "vector.h"6 #include <c++_tools/gslapi/vector.h> 7 7 8 8 namespace theplu { 9 namespace cpptools {9 namespace statistics { 10 10 11 11 /// … … 31 31 inline void absolute(bool absolute) {absolute_=absolute;} 32 32 33 /// 34 /// @return statistica. 35 /// 33 36 virtual double 34 37 score(const gslapi::vector&, … … 36 39 const std::vector<size_t>& = std::vector<size_t>()) = 0; 37 40 41 /// 42 /// @return statistica (weighted version) 43 /// 38 44 virtual double 39 45 score(const gslapi::vector&, … … 42 48 const std::vector<size_t>& = std::vector<size_t>()) = 0; 43 49 50 /// 51 /// @return the ///one-sided p-value( if absolute true is used 52 /// this is equivalent to the two-sided p-value.) 53 /// 44 54 virtual double p_value(void) const = 0; 45 55 … … 56 66 }; // class Score 57 67 58 }} // of namespace cpptools and namespace theplu68 }} // of namespace statistics and namespace theplu 59 69 60 70 #endif -
trunk/lib/statistics/tScore.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_t_score_4 #define _theplu_ cpptools_t_score_3 #ifndef _theplu_statistics_t_score_ 4 #define _theplu_statistics_t_score_ 5 5 6 6 // C++ tools include 7 7 ///////////////////// 8 #include "Score.h" 9 #include "vector.h" 8 #include <c++_tools/statistics/Score.h> 9 #include <c++_tools/gslapi/vector.h> 10 10 11 #include <gsl/gsl_cdf.h> 11 12 12 // Standard C++ includes13 ////////////////////////14 //#include <utility>15 //#include <vector>16 13 17 14 namespace theplu { 18 namespace cpptools {15 namespace statistics { 19 16 /// 20 17 /// Class for Fisher's t-test. … … 75 72 }; 76 73 77 }} // of namespace cpptools and namespace theplu74 }} // of namespace statistics and namespace theplu 78 75 79 76 #endif -
trunk/lib/svm/ConsensusInputRanker.cc
r294 r295 2 2 3 3 4 #include "ConsensusInputRanker.h" 5 // Thep C++ Tools 6 #include "CrossValidation.h" 7 #include "InputRanker.h" 8 #include "Statistics.h" 9 #include "stl_utility.h" 4 #include <c++_tools/svm/ConsensusInputRanker.h> 10 5 11 // System includes 6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/statistics/Statistics.h> 8 #include <c++_tools/svm/CrossValidation.h> 9 #include <c++_tools/svm/InputRanker.h> 10 #include <c++_tools/utility/stl_utility.h> 11 12 #include <utility> 12 13 #include <vector> 13 14 14 15 namespace theplu { 15 namespace cpptools{16 namespace svm { 16 17 17 18 ConsensusInputRanker::ConsensusInputRanker(const gslapi::matrix& data, 18 19 const gslapi::vector& target, 19 Score& score_object,20 statistics::Score& score_object, 20 21 const size_t rounds, 21 22 const size_t k) … … 43 44 //sort medians and assign id_ and rank_ 44 45 sort(median.begin(), median.end(), 45 pair_value_compare<size_t, double>());46 cpptools::pair_value_compare<size_t, double>()); 46 47 id_.resize(data.rows()); 47 48 rank_.resize(data.rows()); … … 56 57 const gslapi::vector& target, 57 58 const gslapi::matrix& weight, 58 Score& score_object,59 statistics::Score& score_object, 59 60 const size_t rounds, 60 61 const size_t k) … … 80 81 //sort medians and assign id_ and rank_ 81 82 sort(median.begin(), median.end(), 82 pair_value_compare<size_t, double>());83 cpptools::pair_value_compare<size_t, double>()); 83 84 id_.resize(data.rows()); 84 85 rank_.resize(data.rows()); … … 91 92 92 93 93 }} // of namespace cpptoolsand namespace theplu94 }} // of namespace svm and namespace theplu -
trunk/lib/svm/ConsensusInputRanker.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_consensusinputranker_4 #define _theplu_ cpptools_consensusinputranker_3 #ifndef _theplu_svm_consensusinputranker_ 4 #define _theplu_svm_consensusinputranker_ 5 5 6 // C++ tools include 7 ///////////////////// 8 #include "InputRanker.h" 9 #include "matrix.h" 10 #include "Score.h" 11 #include "vector.h" 12 13 // Standard C++ includes 14 //////////////////////// 15 6 #include <c++_tools/svm/InputRanker.h> 16 7 17 8 namespace theplu { 18 namespace cpptools { 9 class gslapi::matrix; 10 class gslapi::vector; 11 class statistics::Score; 12 namespace svm { 19 13 20 14 /// … … 34 28 ConsensusInputRanker(const gslapi::matrix& data, 35 29 const gslapi::vector& target, 36 Score&,30 statistics::Score&, 37 31 const size_t n = 1 , 38 32 const size_t k = 3 ); … … 46 40 const gslapi::vector& target, 47 41 const gslapi::matrix& weight, 48 Score&,42 statistics::Score&, 49 43 const size_t n = 1 , 50 44 const size_t k = 3 ); … … 71 65 }; 72 66 73 }} // of namespace cpptoolsand namespace theplu67 }} // of namespace svm and namespace theplu 74 68 75 69 #endif -
trunk/lib/svm/CrossValidation.cc
r294 r295 1 1 // $Id$ 2 2 3 // System includes 3 4 #include <c++_tools/gslapi/vector.h> 5 #include <c++_tools/svm/CrossValidation.h> 6 #include <c++_tools/utility/random_singleton.h> 7 4 8 #include <vector> 5 9 6 // Thep C++ Tools7 #include "random_singleton.h"8 #include "CrossValidation.h"9 10 10 namespace theplu { 11 namespace cpptools{11 namespace svm { 12 12 13 13 CrossValidation::CrossValidation(const theplu::gslapi::vector& target, … … 24 24 } 25 25 26 my_uniform_rng a;26 cpptools::my_uniform_rng a; 27 27 random_shuffle(index_negative_.begin(), index_negative_.end(), a); 28 28 random_shuffle(index_positive_.begin(), index_positive_.end(), a); … … 33 33 if (count_==k_){ 34 34 count_=0; 35 my_uniform_rng a;35 cpptools::my_uniform_rng a; 36 36 random_shuffle(index_negative_.begin(), index_negative_.end(), a); 37 37 random_shuffle(index_positive_.begin(), index_positive_.end(), a); -
trunk/lib/svm/CrossValidation.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_crossvalidation_4 #define _theplu_ cpptools_crossvalidation_3 #ifndef _theplu_svm_crossvalidation_ 4 #define _theplu_svm_crossvalidation_ 5 5 6 // C++ tools include7 /////////////////////8 #include "vector.h"9 10 // Standard C++ includes11 ////////////////////////12 6 #include <vector> 13 7 14 8 namespace theplu { 15 namespace cpptools { 9 namespace gslapi { 10 class vector; 11 } 12 namespace svm { 16 13 17 14 /// … … 24 21 public: 25 22 /// 26 /// Constructor taking \a target and \ k for k-fold cross validation23 /// Constructor taking \a target and \a k for k-fold cross validation 27 24 /// 28 25 CrossValidation(const theplu::gslapi::vector& target, const size_t k = 3); … … 46 43 }; 47 44 48 }} // of namespace cpptoolsand namespace theplu45 }} // of namespace svm and namespace theplu 49 46 50 47 #endif -
trunk/lib/svm/GaussianKernelFunction.cc
r294 r295 1 1 // $Id$ 2 2 3 // System 3 #include <c++_tools/svm/GaussianKernelFunction.h> 4 5 #include <c++_tools/svm/KernelFunction.h> 6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/gslapi/vector.h> 8 4 9 #include <math.h> 5 10 6 7 // Thep C++ Tools8 #include "GaussianKernelFunction.h"9 #include "matrix.h"10 #include "vector.h"11 12 11 namespace theplu { 13 namespace cpptools{12 namespace svm { 14 13 15 14 GaussianKernelFunction::GaussianKernelFunction(double sigma) … … 53 52 } 54 53 55 }} // of namespace cpptoolsand namespace theplu54 }} // of namespace svn and namespace theplu -
trunk/lib/svm/GaussianKernelFunction.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_gaussian_kernel_function_4 #define _theplu_ cpptools_gaussian_kernel_function_3 #ifndef _theplu_svm_gaussian_kernel_function_ 4 #define _theplu_svm_gaussian_kernel_function_ 5 5 6 #include "KernelFunction.h" 7 #include "vector.h" 6 #include <c++_tools/gslapi/vector.h> 7 #include <c++_tools/svm/KernelFunction.h> 8 9 #include <cmath> 8 10 9 11 namespace theplu { 12 class gslapi::vector; 10 13 11 namespace gslapi { 12 class vector; 13 } 14 15 namespace cpptools { 14 namespace svm { 16 15 17 16 /// 18 17 /// Class for Gaussian kernel calculations. 19 18 /// 20 21 19 22 20 class GaussianKernelFunction : public KernelFunction … … 41 39 inline double operator()(const gslapi::vector& a1, 42 40 const gslapi::vector& a2) 43 {return exp(-(a1-a2)*(a1-a2)/ pow(sigma_,2));}41 {return exp(-(a1-a2)*(a1-a2)/(sigma_*sigma_));} 44 42 43 /// 45 44 ///returning the scalar product of two vectors in feature space using the 46 45 ///Gaussian kernel with weights. … … 52 51 53 52 /// 54 /// @ kernel matrix53 /// @return kernel matrix 55 54 /// 56 55 const gslapi::matrix& operator()(theplu::gslapi::matrix& kernel, … … 62 61 }; // class GaussianKernelFunction 63 62 64 }} // of namespace cpptoolsand namespace theplu63 }} // of namespace svm and namespace theplu 65 64 66 65 #endif -
trunk/lib/svm/InputRanker.cc
r294 r295 1 1 // $Id$ 2 2 3 // Thep C++ Tools 4 #include "InputRanker.h" 5 #include "ROC.h"6 #include "matrix.h"7 #include "vector.h"8 #include "stl_utility.h"3 #include <c++_tools/svm/InputRanker.h> 4 5 #include <c++_tools/gslapi/matrix.h> 6 #include <c++_tools/gslapi/vector.h> 7 #include <c++_tools/statistics/ROC.h> 8 #include <c++_tools/utility/stl_utility.h> 9 9 10 10 #include <vector> … … 12 12 13 13 namespace theplu { 14 namespace cpptools{14 namespace svm { 15 15 16 16 InputRanker::InputRanker() … … 24 24 InputRanker::InputRanker(const gslapi::matrix& data, 25 25 const gslapi::vector& target, 26 Score& score_object,26 statistics::Score& score_object, 27 27 const std::vector<size_t>& train_set) 28 28 :train_set_(train_set), … … 49 49 //sort the scores and assign id_ and rank_ 50 50 sort(score.begin(), score.end(), 51 pair_value_compare<size_t, double>());51 cpptools::pair_value_compare<size_t, double>()); 52 52 53 53 for (size_t i=0; i<nof_genes; i++){ … … 60 60 const gslapi::vector& target, 61 61 const gslapi::matrix& weight, 62 Score& score_object,62 statistics::Score& score_object, 63 63 const std::vector<size_t>& train_set) 64 64 :train_set_(train_set), … … 84 84 //sort the scores and assign id_ and rank_ 85 85 sort(score.begin(), score.end(), 86 pair_value_compare<size_t, double>());86 cpptools::pair_value_compare<size_t, double>()); 87 87 88 88 for (size_t i=0; i<nof_genes; i++){ … … 92 92 } 93 93 94 }} // of namespace cpptoolsand namespace theplu94 }} // of namespace svm and namespace theplu -
trunk/lib/svm/InputRanker.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_inputranker_4 #define _theplu_ cpptools_inputranker_3 #ifndef _theplu_svm_inputranker_ 4 #define _theplu_svm_inputranker_ 5 5 6 // C++ tools include 7 ///////////////////// 8 #include "vector.h" 9 #include "matrix.h" 10 #include "Score.h" 11 12 // Standard C++ includes 13 //////////////////////// 14 6 #include <vector> 15 7 16 8 namespace theplu { 17 namespace cpptools { 9 namespace gslapi { 10 class matrix; 11 class vector; 12 } 13 namespace statistics { 14 class Score; 15 } 16 namespace svm { 18 17 /// 19 18 /// Class for ranking rows in a matrix, using a Score and a … … 36 35 InputRanker(const gslapi::matrix&, 37 36 const gslapi::vector&, 38 Score&,37 statistics::Score&, 39 38 const std::vector<size_t>& = std::vector<size_t>()); 40 39 … … 47 46 const gslapi::vector&, 48 47 const gslapi::matrix&, 49 Score&,48 statistics::Score&, 50 49 const std::vector<size_t>& = std::vector<size_t>()); 51 50 … … 71 70 }; 72 71 73 }} // of namespace cpptoolsand namespace theplu72 }} // of namespace svm and namespace theplu 74 73 75 74 #endif -
trunk/lib/svm/Kernel.cc
r294 r295 1 1 // $Id$ 2 2 3 // Thep C++ Tools 4 #include "Kernel.h" 5 #include "KernelFunction.h"6 #include "matrix.h"7 #include "vector.h"3 #include <c++_tools/svm/Kernel.h> 4 5 #include <c++_tools/svm/KernelFunction.h> 6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/gslapi/vector.h> 8 8 9 9 namespace theplu { 10 namespace cpptools{10 namespace svm { 11 11 12 12 Kernel::Kernel(const gslapi::matrix& data, const KernelFunction& kf) … … 32 32 } 33 33 34 }} // of namespace cpptoolsand namespace theplu34 }} // of namespace svm and namespace theplu -
trunk/lib/svm/Kernel.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_kernel_4 #define _theplu_ cpptools_kernel_3 #ifndef _theplu_svm_kernel_ 4 #define _theplu_svm_kernel_ 5 5 6 #include "matrix.h"6 #include <c++_tools/gslapi/matrix.h> 7 7 8 8 namespace theplu { 9 namespace cpptools{9 namespace svm { 10 10 11 11 class KernelFunction; … … 42 42 private: 43 43 gslapi::matrix k_; 44 const theplu::cpptools::KernelFunction* kf_;44 const KernelFunction* kf_; 45 45 bool weighted_; 46 46 47 47 }; // class Kernel 48 48 49 }} // of namespace cpptoolsand namespace theplu49 }} // of namespace svm and namespace theplu 50 50 51 51 #endif -
trunk/lib/svm/KernelFunction.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_kernel_function_4 #define _theplu_ cpptools_kernel_function_3 #ifndef _theplu_svm_kernel_function_ 4 #define _theplu_svm_kernel_function_ 5 5 6 6 namespace theplu { … … 11 11 } 12 12 13 namespace cpptools{13 namespace svm { 14 14 15 15 /// … … 30 30 virtual ~KernelFunction(void) {}; 31 31 32 /// 33 /// @return scalar product of two vector in feature space. 34 /// 32 35 virtual double operator()(const gslapi::vector&, 33 36 const gslapi::vector&) const = 0; 34 37 38 /// 39 /// @return scalar product of two vector in feature space. 40 /// 35 41 virtual double operator()(const gslapi::vector&, 36 42 const gslapi::vector&, … … 38 44 const gslapi::vector&) const = 0; 39 45 46 /// 47 /// @return kernel matrix 48 /// 40 49 virtual const theplu::gslapi::matrix& operator() 41 50 (theplu::gslapi::matrix& k, const gslapi::matrix& data) const = 0; … … 43 52 }; // class KernelFunction 44 53 45 }} // of namespace cpptoolsand namespace theplu54 }} // of namespace svm and namespace theplu 46 55 47 56 #endif -
trunk/lib/svm/PolynomialKernelFunction.cc
r294 r295 1 1 // $Id$ 2 2 3 // System 3 4 #include <c++_tools/svm/PolynomialKernelFunction.h> 5 6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/gslapi/vector.h> 8 4 9 #include <math.h> 5 6 // Thep C++ Tools7 #include "PolynomialKernelFunction.h"8 #include "matrix.h"9 #include "vector.h"10 10 11 11 12 12 namespace theplu { 13 namespace cpptools{13 namespace svm { 14 14 15 15 PolynomialKernelFunction::PolynomialKernelFunction(int order) … … 48 48 const theplu::gslapi::matrix& data) const 49 49 { 50 theplu::gslapi::matrix data_transposed(data.transpose());50 gslapi::matrix data_transposed(data.transpose()); 51 51 kernel = data_transposed*data; 52 52 if (order_>1) -
trunk/lib/svm/PolynomialKernelFunction.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_polynomial_kernel_function_4 #define _theplu_ cpptools_polynomial_kernel_function_3 #ifndef _theplu_svm_polynomial_kernel_function_ 4 #define _theplu_svm_polynomial_kernel_function_ 5 5 6 #include "KernelFunction.h"6 #include <c++_tools/svm/KernelFunction.h> 7 7 8 8 namespace theplu { … … 12 12 } 13 13 14 namespace cpptools{14 namespace svm { 15 15 16 16 /// … … 49 49 50 50 /// 51 /// @ kernel matrix51 /// @return kernel matrix 52 52 /// 53 53 const gslapi::matrix& operator()(theplu::gslapi::matrix& kernel, … … 59 59 }; // class PolynomialKernelFunction 60 60 61 }} // of namespace cpptoolsand namespace theplu61 }} // of namespace svm and namespace theplu 62 62 63 63 #endif -
trunk/lib/svm/SVM.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "SVM.h" 4 5 // System includes 3 4 #include <c++_tools/svm/SVM.h> 5 6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/gslapi/vector.h> 8 #include <c++_tools/statistics/Averager.h> 9 #include <c++_tools/utility/random_singleton.h> 10 6 11 #include <cmath> 7 12 #include <limits.h> … … 9 14 #include <vector> 10 15 11 // Thep C++ Tools12 #include "Averager.h"13 #include "matrix.h"14 #include "random_singleton.h"15 #include "vector.h"16 17 18 16 19 17 namespace theplu { 20 namespace cpptools{18 namespace svm { 21 19 22 20 SVM::SVM(const Kernel& kernel, … … 76 74 for (size_t i=0; i<E.size(); i++) 77 75 tmp[i]=i; 78 my_uniform_rng a;76 cpptools::my_uniform_rng a; 79 77 random_shuffle(tmp.begin(), tmp.end(), a); 80 78 for (size_t i=0; i<tmp.size(); i++){ -
trunk/lib/svm/SVM.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_ cpptools_svm_4 #define _theplu_ cpptools_svm_3 #ifndef _theplu_svm_svm_ 4 #define _theplu_svm_svm_ 5 5 6 // C++ tools include 7 ///////////////////// 8 #include "Kernel.h" 9 #include "matrix.h" 10 #include "vector.h" 6 #include <c++_tools/svm/Kernel.h> 7 #include <c++_tools/gslapi/vector.h> 11 8 12 13 // Standard C++ includes14 ////////////////////////15 9 #include <utility> 16 10 #include <vector> … … 18 12 19 13 namespace theplu { 20 namespace cpptools{14 namespace svm { 21 15 /// 22 16 /// Class for SVM using Keerthi's second modification of Platt's SMO. Also … … 35 29 /// Constructor taking the kernel matrix and the target vector as input 36 30 /// 37 SVM(const Kernel&, const gslapi::vector&, 31 SVM(const Kernel&, 32 const gslapi::vector&, 38 33 const std::vector<size_t>& = std::vector<size_t>()); 39 34 … … 90 85 double bias_; 91 86 double c_; 92 Kernel kernel_; 87 Kernel kernel_; // Peter, const ref? 93 88 unsigned long int max_epochs_; 94 gslapi::vector target_; 89 gslapi::vector target_; // Peter, const ref? 95 90 bool trained_; 96 91 std::vector<size_t> train_set_; … … 116 111 117 112 118 }} // of namespace cpptoolsand namespace theplu113 }} // of namespace svm and namespace theplu 119 114 120 115 #endif -
trunk/lib/utility/Alignment.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "Alignment.h"4 #include "matrix.h"3 #include <c++_tools/utility/Alignment.h> 4 #include <c++_tools/gslapi/matrix.h> 5 5 6 6 #include <utility> -
trunk/lib/utility/FileIO.cc
r294 r295 1 1 // $Id$ 2 3 #include <c++_tools/utility/FileIO.h> 2 4 3 5 #include <iostream> 4 6 #include <unistd.h> 5 7 6 #include "FileIO.h"7 8 8 9 namespace theplu { -
trunk/lib/utility/Merge.cc
r294 r295 1 1 // $Id$ 2 3 4 #include <c++_tools/utility/Merge.h> 5 6 #include <c++_tools/statistics/Averager.h> 7 #include <c++_tools/statistics/AveragerWeighted.h> 8 #include <c++_tools/utility/stl_utility.h> 2 9 3 10 #include <algorithm> … … 5 12 #include <fstream> 6 13 #include <map> 7 8 #include "stl_utility.h"9 #include "Merge.h"10 #include "Averager.h"11 #include "WeightedAverager.h"12 14 13 15 namespace theplu { … … 88 90 89 91 void Merge::merging(vector<u_int> index, gslapi::matrix& weights){ 90 statistics:: WeightedAveragerw_av;92 statistics::AveragerWeighted w_av; 91 93 statistics::Averager av; 92 94 // merge genes for each assay -
trunk/lib/utility/Merge.h
r294 r295 1 1 // $Id$ 2 2 3 #ifndef _theplu_cpptools_merge_ //vad är detta?3 #ifndef _theplu_cpptools_merge_ 4 4 #define _theplu_cpptools_merge_ 5 6 #include <c++_tools/gslapi/matrix.h> 7 //#include <c++_tools/gslapi/vector.h> 5 8 6 9 #include <iostream> … … 9 12 #include <vector> 10 13 11 #include "vector.h"12 #include "matrix.h"13 14 14 15 namespace theplu { … … 17 18 using namespace std; 18 19 19 /** 20 A merger of datapoints on annotations. 21 Calculates weighted average (m) of all (i) data points with same annotation: 22 m=sum(w_i*x_i)sum(w_i) 23 and uncertainty U of new data point: 24 U=1/(sum(1/u_i))+sum(w_i^2*(x_i-m)^2)/(sum(w_i))^2 25 w_i is calculated from errors u_i 26 27 Missing values have error < 0 28 */ 20 /// 21 /// A merger of datapoints on annotations. Calculates weighted 22 /// average (m) of all (i) data points with same annotation: 23 /// m=sum(w_i*x_i)sum(w_i) and uncertainty U of new data point: 24 /// U=1/(sum(1/u_i))+sum(w_i^2*(x_i-m)^2)/(sum(w_i))^2 w_i is 25 /// calculated from errors u_i Missing values have error < 0 26 /// 27 29 28 class Merge 30 29 { … … 55 54 56 55 /// 57 /// Return matrix58 ///59 56 /// @return Const reference to the data matrix. 60 57 /// 61 58 inline const gslapi::matrix& data_matrix(void) const { return data_; } 59 60 /// 61 /// @return Const reference to the error matrix. 62 /// 62 63 inline const gslapi::matrix& error_matrix(void) const { return error_; } 63 64 -
trunk/lib/utility/NNI.cc
r294 r295 1 1 // $Id$ 2 3 #include <c++_tools/utility/NNI.h> 4 5 #include <c++_tools/utility/stl_utility.h> 2 6 3 7 #include <algorithm> … … 5 9 #include <fstream> 6 10 7 #include "stl_utility.h"8 #include "NNI.h"9 11 10 12 namespace theplu { -
trunk/lib/utility/NNI.h
r294 r295 8 8 #include <vector> 9 9 10 #include "matrix.h"10 #include <c++_tools/gslapi/matrix.h> 11 11 12 12 namespace theplu { -
trunk/lib/utility/PCA.cc
r294 r295 5 5 #include <memory> 6 6 7 #include "PCA.h" 8 #include "SVD.h" 9 10 11 // using namespace std; 12 // using namespace thep_cpp_tools; 7 #include <c++_tools/utility/PCA.h> 8 #include <c++_tools/utility/SVD.h> 9 13 10 14 11 namespace theplu { -
trunk/lib/utility/PCA.h
r294 r295 4 4 #define _theplu_cpptools_pca_ 5 5 6 #include "vector.h"7 #include "matrix.h"6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/gslapi/vector.h> 8 8 9 9 // Standard C++ includes -
trunk/lib/utility/SVD.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "SVD.h"3 #include <c++_tools/utility/SVD.h> 4 4 5 5 -
trunk/lib/utility/SVD.h
r294 r295 4 4 #define _theplu_cpptools_svd_ 5 5 6 #include "matrix.h"7 #include "vector.h"6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/gslapi/vector.h> 8 8 9 9 #include <gsl/gsl_linalg.h> -
trunk/lib/utility/WeNNI.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "WeNNI.h" 3 #include <c++_tools/utility/WeNNI.h> 4 5 #include <c++_tools/utility/stl_utility.h> 4 6 5 7 #include <algorithm> 6 8 #include <cmath> 7 9 #include <fstream> 8 9 #include "stl_utility.h"10 10 11 11 namespace theplu { -
trunk/lib/utility/WeNNI.h
r294 r295 4 4 #define _theplu_cpptools_wenni_ 5 5 6 #include "NNI.h" 6 #include <c++_tools/utility/NNI.h> 7 8 #include <c++_tools/gslapi/matrix.h> 7 9 8 10 #include <iostream> 9 11 10 #include "matrix.h" 12 11 13 12 14 namespace theplu { -
trunk/lib/utility/kNNI.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "kNNI.h"3 #include <c++_tools/utility/kNNI.h> 4 4 5 5 #include <algorithm> … … 8 8 #include <vector> 9 9 10 #include "stl_utility.h"10 #include <c++_tools/utility/stl_utility.h> 11 11 12 12 namespace theplu { -
trunk/lib/utility/kNNI.h
r294 r295 4 4 #define _theplu_cpptools_knni_ 5 5 6 #include "NNI.h"6 #include <c++_tools/utility/NNI.h> 7 7 8 8 #include <iostream> -
trunk/lib/utility/random_singleton.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "random_singleton.h"3 #include <c++_tools/utility/random_singleton.h> 4 4 5 5 namespace theplu { -
trunk/lib/utility/stl_utility.cc
r294 r295 1 1 // $Id$ 2 2 3 #include "stl_utility.h"3 #include <c++_tools/utility/stl_utility.h> 4 4 5 5 #include <iostream> -
trunk/lib/utility/stl_utility.h
r294 r295 27 27 struct pair_value_compare 28 28 { 29 /// 30 /// @return true if x.second<y.second or (x.second==y.second and 31 /// x.first<y.first) 32 /// 29 33 inline bool operator()(const std::pair<T1,T2>& x, 30 34 const std::pair<T1,T2>& y) {
Note: See TracChangeset
for help on using the changeset viewer.