Changeset 295


Ignore:
Timestamp:
Apr 29, 2005, 11:15:58 AM (16 years ago)
Author:
Peter
Message:

file structure modifications. NOTE, this revision is not working, please wait for the next...

Location:
trunk/lib
Files:
9 added
76 moved

Legend:

Unmodified
Added
Removed
  • trunk/lib/gslapi/matrix.cc

    r294 r295  
    11// $Id$
    22
    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>
    77
    88#include <cmath>
  • trunk/lib/gslapi/matrix.h

    r294 r295  
    44#define _theplu_gslapi_matrix_
    55
     6#include <c++_tools/gslapi/vector.h>
     7
     8#include <gsl/gsl_matrix.h>
    69#include <iostream>
    710
    8 #include <gsl/gsl_matrix.h>
    9 #include "vector.h"
    1011
    1112namespace theplu {
     
    6263
    6364    ///
    64     /// Swap column \a i with \j.
     65    /// Swap column \a i with \a j.
    6566    ///
    6667    inline void column_swap(const size_t& i,const size_t& j)
  • trunk/lib/gslapi/utility.cc

    r294 r295  
    11// $Id$
    22
    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
    48#include <utility>
    5 
    6 #include "random_singleton.h"
    7 #include "vector.h"
    89
    910
  • trunk/lib/gslapi/utility.h

    r294 r295  
    66#include <utility>
    77
    8 #include "vector.h"
     8#include <c++_tools/gslapi/vector.h>
     9
    910
    1011namespace theplu {
  • trunk/lib/gslapi/vector.cc

    r294 r295  
    11// $Id$
    22
    3 #include "vector.h"
    4 #include "matrix.h"
     3#include <c++_tools/gslapi/vector.h>
     4#include <c++_tools/gslapi/matrix.h>
    55
    66#include <iostream>
  • trunk/lib/gslapi/vector.h

    r294 r295  
    392392  /// The output operator for the vector class.
    393393  ///
    394   std::ostream& operator<< ( std::ostream&, const vector& );
     394  std::ostream& operator<<(std::ostream&, const vector& );
    395395
    396396
  • trunk/lib/statistics/Averager.cc

    r294 r295  
    11// $Id$
    22
    3 #include "Averager.h"
     3#include <c++_tools/statistics/Averager.h>
     4#include <c++_tools/gslapi/vector.h>
    45
    56#include <sys/types.h>
    67#include <ostream>
    7 #include "vector.h"
    8 
    98
    109namespace theplu {
  • trunk/lib/statistics/Averager.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_averager_
    4 #define _theplu_cpptools_averager_
     3#ifndef _theplu_statistics_averager_
     4#define _theplu_statistics_averager_
    55
    66#include <cmath>
    7 #include "vector.h"
    87
    98namespace theplu{
     9namespace gslapi{
     10  class vector;
     11}
     12
    1013namespace statistics{
    1114  class ostream;
  • trunk/lib/statistics/AveragerPair.cc

    r294 r295  
    11// $Id$
    22
    3 #include "AveragerPair.h"
     3#include <c++_tools/statistics/AveragerPair.h>
     4#include <c++_tools/statistics/Averager.h>
    45
    5 #include "Averager.h"
    6 //#include <sys/types.h>
    7 //#include <ostream>
    8 //#include "vector.h"
    96#include <utility>
    107
  • trunk/lib/statistics/AveragerPair.h

    r294 r295  
    11// $Id$
    22
    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>
    57
    68#include <cmath>
    79#include <utility>
    810
    9 #include "Averager.h"
    1011
    1112namespace theplu{
  • trunk/lib/statistics/AveragerWeighted.cc

    r294 r295  
    11// $Id$
    22
    3 #include <sys/types.h>
     3#include <c++_tools/statistics/AveragerWeighted.h>
     4#include <c++_tools/statistics/Averager.h>
    45
    56#include <ostream>
    6 
    7 #include "Averager.h"
    8 #include "WeightedAverager.h"
     7#include <sys/types.h>
    98
    109namespace theplu {
     
    1211 
    1312
    14   WeightedAverager::WeightedAverager(void)
     13  AveragerWeighted::AveragerWeighted(void)
    1514    : w_(Averager()), wx_(Averager()), wwx_(0)
    1615  {
    1716  }
    1817
    19   WeightedAverager::WeightedAverager(const double d, const double w)
     18  AveragerWeighted::AveragerWeighted(const double d, const double w)
    2019    : w_(Averager(w,w*w,1)), wx_(Averager(w*d,w*w*d*d,1)), wwx_(w*w*d)
    2120  {
    2221  }
    2322
    24   WeightedAverager::WeightedAverager(const WeightedAverager& a)
     23  AveragerWeighted::AveragerWeighted(const AveragerWeighted& a)
    2524    : w_(Averager(a.sum_w(), a.sum_ww(),1)),
    2625      wx_(Averager(a.sum_wx(),a.sum_wwxx(),1)), wwx_(a.sum_wwx())
  • trunk/lib/statistics/AveragerWeighted.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_weighted_averager_
    4 #define _theplu_cpptools_weighted_averager_
     3#ifndef _theplu_statistics_averager_weighted_
     4#define _theplu_statistics_averager_weighted_
    55
    6 //#include <cmath>
    7 #include "Averager.h"
     6#include <c++_tools/statistics/Averager.h>
     7
     8#include <ostream>
    89
    910namespace theplu{
    1011namespace statistics{
     12
    1113  ///
    1214  /// Class to calulate simple (first and second moments) averages
     
    1517  /// @see Averager
    1618  ///
    17   class WeightedAverager
     19  class AveragerWeighted
    1820  {
    1921  public:
     
    2224    /// Default constructor
    2325    ///
    24     WeightedAverager(void);
     26    AveragerWeighted(void);
    2527
    2628    ///
     
    2830    /// weight (default = 1)
    2931    ///
    30     WeightedAverager(const double, const double=1);
     32    AveragerWeighted(const double, const double=1);
    3133
    3234    ///
    3335    /// Copy constructor
    3436    ///
    35     WeightedAverager(const WeightedAverager&);
     37    AveragerWeighted(const AveragerWeighted&);
    3638
    3739    ///
     
    117119
    118120    ///
    119     /// operator to add a WeightedAverager
     121    /// operator to add a AveragerWeighted
    120122    ///
    121     inline WeightedAverager operator+=(WeightedAverager& a)
     123    inline AveragerWeighted operator+=(AveragerWeighted& a)
    122124    { wx_+=a.wx(); w_+=a.w(); wwx_+=a.sum_wwx(); return *this; }
    123125   
     
    133135
    134136///
    135 /// The WeightedAverager output operator
     137/// The AveragerWeighted output operator
    136138///
    137 std::ostream& operator<<(std::ostream& s,const WeightedAverager&);
     139std::ostream& operator<<(std::ostream& s,const AveragerWeighted&);
    138140
    139141}} // of namespace statistics and namespace theplu
  • trunk/lib/statistics/Fisher.cc

    r294 r295  
    11// $Id$
    22
    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>
    76
    87namespace theplu {
    9 namespace cpptools {
     8namespace statistics {
    109
    1110 
     
    2221  {
    2322    // If a column sum or a row sum is zero, the table is nonsense
    24     if (a*d==0 && c*b==0){
    25       std::cout << "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;
    2726    }
    2827
    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;
    3833  }
    3934
     
    6661    else
    6762      train_set_ = train_set;
    68     a_=0;
    6963    a_=b_=c_=d_=0;
    7064    for (size_t i=0; i<train_set_.size(); i++)
     
    8175       
    8276    // If a column sum or a row sum is zero, the table is nonsense
    83     if (a_*d_==0 && c_*b_==0){
    84       std::cout << "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;
    8680    }
    8781
     
    136130  }
    137131
    138 }} // of namespace cpptools and namespace theplu
     132}} // of namespace statistics and namespace theplu
  • trunk/lib/statistics/Fisher.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_fisher_
    4 #define _theplu_cpptools_fisher_
     3#ifndef _theplu_statistics_fisher_
     4#define _theplu_statistics_fisher_
    55
    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>
    118
    12 // Standard C++ includes
    13 ////////////////////////
    14 //#include <utility>
    15 //#include <vector>
    169
    1710namespace theplu {
    18 namespace cpptools { 
     11namespace statistics { 
    1912  ///
    2013  /// Class for Fisher's exact test.   
     
    6558   
    6659    ///
     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    ///
    6767    /// @return odds ratio. If absolute_ is true and odds ratio is
    6868    /// less than unity 1 divided by odds ratio is returned
    6969    ///
    70     double score(const gslapi::vector&, const gslapi::vector&
     70    double score(const gslapi::vector& x, const gslapi::vector& y
    7171                 const std::vector<size_t>& = std::vector<size_t>());
    7272
    7373    ///
    74     /// Weighted version of odds ratio. Each element in 2x2 table is
    75     /// calculated as \f$ \sum weight_i \f$, so when each weight is
     74    /// Weighted version of score. Each element in 2x2 table is
     75    /// calculated as \f$ \sum w_i \f$, so when each weight is
    7676    /// unitary the same table is created as in the unweighted version
    7777    /// @return odds ratio
    7878    ///
    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,
    8181                 const std::vector<size_t>& = std::vector<size_t>());
    8282
    8383    ///
    84     /// @return odds ratio  \f$ ad/bc\f$ 
     84    /// \f$ \frac{ad}{bc} \f$
    8585    ///
    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);
    8791   
    88     double oddsratio(const double, const double,
    89                      const double, const double) const;
    9092
    9193         
     
    98100    u_int d_;
    99101
     102    double oddsratio(const double a, const double b,
     103                     const double c, const double d) const;
    100104
    101105  };
    102106
    103 }} // of namespace cpptools and namespace theplu
     107}} // of namespace statistics and namespace theplu
    104108
    105109#endif
  • trunk/lib/statistics/Histogram.h

    r294 r295  
    11// $Id$
    22
    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>
    57
    68#include <string>
    79#include <vector>
    810
    9 #include "WeightedAverager.h"
    10 
    1111
    1212namespace theplu {
    13 namespace cpptools {
     13namespace statistics {
    1414
    1515  ///
     
    5858
    5959    ///
    60     /// Gives access to the WeightedAverager object that keeps track of
     60    /// Gives access to the AveragerWeighted object that keeps track of
    6161    /// average of all events presented to the histogram.
    6262    ///
    6363    /// @short Average of all events presented to the histogram.
    6464    ///
    65     /// @return A const reference to an WeightedAverager object.
     65    /// @return A const reference to an AveragerWeighted object.
    6666    ///
    67     inline const statistics::WeightedAverager& averager_all(void) const
     67    inline const statistics::AveragerWeighted& averager_all(void) const
    6868      { return sum_all_; }
    6969
    7070    ///
    71     /// Gives access to the WeightedAverager object that keeps track of
     71    /// Gives access to the AveragerWeighted object that keeps track of
    7272    /// average of events that fits within the histogram lower and
    7373    /// upper limits. This function is equivalent to averager().
     
    7575    /// @short Average of events fitting within histogram.
    7676    ///
    77     /// @return A const reference to an WeightedAverager object.
     77    /// @return A const reference to an AveragerWeighted object.
    7878    ///
    79     inline const statistics::WeightedAverager& averager_histogram(void) const
     79    inline const statistics::AveragerWeighted& averager_histogram(void) const
    8080      { return sum_histogram_; }
    8181
     
    144144    double xmax_;
    145145    double xmin_;
    146     statistics::WeightedAverager sum_all_;      // average of all data
    147     statistics::WeightedAverager sum_histogram_;// average of data in histogram
     146    statistics::AveragerWeighted sum_all_;      // average of all data
     147    statistics::AveragerWeighted sum_histogram_;// average of data in histogram
    148148  };
    149149
     
    153153std::ostream& operator<<(std::ostream& s,const Histogram&);
    154154
    155 }} // of namespace cpptools and namespace theplu
     155}} // of namespace statistics and namespace theplu
    156156
    157157#endif
  • trunk/lib/statistics/Kernel.cc

    r294 r295  
    11// $Id$
    22
    3 #include "RegressionKernel.h"
     3#include <c++_tools/statistics/Kernel.h>
    44
    55namespace theplu{
    66namespace statistics{
    77
    8   RegressionKernel::RegressionKernel(void)
     8  Kernel::Kernel(void)
    99  {
    1010  }
  • trunk/lib/statistics/Kernel.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_statistics_regression_kernel_
    4 #define _theplu_statistics_regression_kernel_
     3#ifndef _theplu_statistics_kernel_
     4#define _theplu_statistics_kernel_
    55
    66namespace theplu {
     
    1111  ///
    1212
    13   class RegressionKernel
     13  class Kernel
    1414  {
    1515   
     
    1818    /// Constructor
    1919    ///
    20     RegressionKernel();
     20    Kernel();
    2121
    2222    ///
  • trunk/lib/statistics/KernelBox.cc

    r294 r295  
    11// $Id$
    22
    3 #include "RegressionKernelBox.h"
    4 
    5 #include "RegressionKernel.h"
     3#include <c++_tools/statistics/KernelBox.h>
     4#include <c++_tools/statistics/Kernel.h>
    65
    76namespace theplu {
    87namespace statistics {
    98
    10   RegressionKernelBox::RegressionKernelBox(void)
    11     : RegressionKernel()
     9  KernelBox::KernelBox(void)
     10    : Kernel()
    1211  {
    1312  }
    1413
    15   double RegressionKernelBox::weight(const double u) const
     14  double KernelBox::weight(const double u) const
    1615  {
    1716    if (u>1 || u<-1)
  • trunk/lib/statistics/KernelTriCube.cc

    r294 r295  
    11// $Id$
    22
    3 #include "RegressionKernelTriCube.h"
    4 #include "RegressionKernel.h"
     3#include <c++_tools/statistics/KernelTriCube.h>
     4#include <c++_tools/statistics/Kernel.h>
    55
    66#include <cmath>
     
    99namespace statistics {
    1010
    11   RegressionKernelTriCube::RegressionKernelTriCube(void)
    12     : RegressionKernel()
     11  KernelTriCube::KernelTriCube(void)
     12    : Kernel()
    1313  {
    1414  }
    1515
    16   double RegressionKernelTriCube::weight(const double x) const
     16  double KernelTriCube::weight(const double x) const
    1717  {
    1818    if (x>1 || x<-1)
  • trunk/lib/statistics/KernelTriCube.h

    r294 r295  
    22
    33
    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_
    66
    7 #include "RegressionKernel.h"
     7#include <c++_tools/statistics/Kernel.h>
     8
    89
    910namespace theplu {
     
    1415  ///
    1516
    16   class RegressionKernelTriCube : public RegressionKernel
     17  class KernelTriCube : public Kernel
    1718  {
    1819   
     
    2122    /// Constructor
    2223    ///
    23     RegressionKernelTriCube() ;
     24    KernelTriCube() ;
    2425
    2526    ///
  • trunk/lib/statistics/Pearson.cc

    r294 r295  
    22
    33
    4 #include "Pearson.h"
     4#include <c++_tools/statistics/Pearson.h>
    55
    6 // System includes
     6#include <c++_tools/statistics/AveragerPair.h>
     7#include <c++_tools/gslapi/vector.h>
     8
    79#include <cmath>
    810#include <gsl/gsl_cdf.h>
    911
    10 // Thep C++ Tools
    11 #include "AveragerPair.h"
    12 #include "vector.h"
    13 
    1412
    1513namespace theplu {
    16 namespace cpptools { 
     14namespace statistics { 
    1715
    1816  Pearson::Pearson(bool b)
    19     : Score(b), r_(0), nof_samples_(0), weighted_(true)
     17    : Score(b), r_(0), nof_samples_(0)
    2018  {
    2119  }
    2220
    23   void centralize (vector& x, const vector& w)
     21  void Pearson::centralize(gslapi::vector& x, const gslapi::vector& w)
    2422  {
    2523    double m = (x*w)/w.sum();
     
    2826  }
    2927
    30   double Pearson::p_value() const;
     28  double Pearson::p_value() const
    3129  {
    3230    if(weighted_)
    3331      return 1;
    3432    else if(nof_samples_<3){
    35       std::cerr << "Warning: Only " << nof_samples_ << "samples. " <<
     33      std::cerr << "Warning: Only " << nof_samples_ << "samples. "
    3634                << "Need at lest 3.\n";
    3735      return 1;
    3836    }
    3937    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 );
    4340    }
    4441  }
    4542
    4643  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)
    4845  {
    4946    weighted_=false;
     47    AveragerPair ap;
    5048    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());
    5251      nof_samples_ = vec1.size();
    5352    }
    5453    else{
    55       Averager a();
    5654      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]));
    5856      }
    5957      nof_samples_ = train_set.size();
    6058    }
    61     r_ = a.correlation();
    62     weighted_=false;
    63     if (r<0 && absolute_)
     59    r_ = ap.correlation();
     60    if (r_<0 && absolute_)
    6461      r_=-r_;
    6562     
     
    6865   
    6966  double Pearson::score(const gslapi::vector& vec1, const gslapi::vector& vec2,
    70                         const gslapi::vector& weight,
     67                        const gslapi::vector& w1, const gslapi::vector& w2,
    7168                        const std::vector<size_t>& train_set =
    72                         std::vector<size_t>());
     69                        std::vector<size_t>())
    7370  {
    7471    weighted_=true;
     72    gslapi::vector x;
     73    gslapi::vector y;
     74    gslapi::vector wx;
     75    gslapi::vector wy;
    7576    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;
    7981      nof_samples_ = vec1.size();
    8082    }
    8183    else{
    8284      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_);
    8689      for (size_t i=0; i<train_set.size(); i++){
    8790        x(i)=vec1(train_set[i]);
    8891        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]);
    9094      }
    9195    }
    9296
    93     centralize(x,w);
    94     centralize(y,w);
     97    centralize(x,wx);
     98    centralize(y,wy);
    9599
    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)) );
    98104    weighted_=true;
    99105
    100     if (r<0 && absolute_)
     106    if (r_<0 && absolute_)
    101107      r_=-r_;
    102108     
    103109    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);
    113110  }
    114111
    115 }} // of namespace cpptools and namespace theplu
     112}} // of namespace statistics and namespace theplu
  • trunk/lib/statistics/Pearson.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_pearson_
    4 #define _theplu_cpptools_pearson_
     3#ifndef _theplu_statistics_pearson_
     4#define _theplu_statistics_pearson_
    55
    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>
    177
    188//Peter, should add a function to get the sign of the correlation
    199namespace theplu {
    20 namespace cpptools { 
     10  class gslapi::vector;
     11
     12namespace statistics { 
     13
    2114  ///
    2215  /// Class for calculating Pearson correlation.
     
    4841
    4942    ///
    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$,
    5245    /// where \f$m_x = \frac{\sum w_ix_i}{\sum w_i}\f$ and \f$m_x =
    5346    /// \frac{\sum w_ix_i}{\sum w_i}\f$. This expression is chosen to
     
    5649    /// correlation.
    5750    ///
    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); }
    6156
    6257    ///
     
    7267    double score(const gslapi::vector& x, const gslapi::vector& y, 
    7368                 const gslapi::vector& wx, const gslapi::vector& wy,
    74                  const std::vector<size_t>& = std::vector<size_t>());
     69                 const std::vector<size_t>&);
    7570   
    7671    ///
     
    8883
    8984
    90     void centralize(vector, const vector);
     85    void centralize(gslapi::vector&, const gslapi::vector&);
    9186  };
    9287
    93 }} // of namespace cpptools and namespace theplu
     88}} // of namespace statistics and namespace theplu
    9489
    9590#endif
  • trunk/lib/statistics/ROC.cc

    r294 r295  
    11// $Id$
    22
    3 #include "ROC.h"
     3#include <c++_tools/statistics/ROC.h>
    44
    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
    610#include <cmath>
    7 #include <gsl/gsl_cdf.h>
    811#include <iostream>
    912#include <utility>
    1013#include <vector>
    1114
    12 // Thep C++ Tools
    13 #include "stl_utility.h"
    14 #include "vector.h"
    1515
    1616namespace theplu {
    17 namespace cpptools { 
     17namespace statistics { 
    1818
    1919  ROC::ROC(bool b)
     
    151151    }
    152152    std::sort(value_.begin(),value_.end(),
    153          pair_value_compare<double, double>());
     153         cpptools::pair_value_compare<double, double>());
    154154  }
    155155
  • trunk/lib/statistics/ROC.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_roc_
    4 #define _theplu_cpptools_roc_
     3#ifndef _theplu_statistics_roc_
     4#define _theplu_statistics_roc_
    55
    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>
    108
    11 // Standard C++ includes
    12 ////////////////////////
    139#include <utility>
    1410#include <vector>
    1511
    1612namespace theplu {
    17 namespace cpptools { 
     13namespace statistics { 
    1814  ///
    1915  /// Class for ROC (Reciever Operating Characteristic).
     
    9490    /// data.
    9591    std::vector<std::pair<double, double> > value_;
     92   
     93    /// Implemented as in MatLab 13.1
     94    double ROC::get_p_approx(const double) const;
    9695
    97    
    98     ///
    99     ///
    10096    /// Implemented as in MatLab 13.1
    101     /// @return the p-value
    102     ///
    103     double ROC::get_p_approx(const double) const;
    104    
    105     ///
    106     /// @return the p-value
    107     ///
    10897    double ROC::get_p_exact(const double, const double,
    10998                            const double) const;
    110  
    111     ///
     99
    112100    /// sorting value_, should always be done when changing train_set_
    113     ///
    114101    void ROC::sort();
    115102       
     
    124111
    125112
    126 }} // of namespace cpptools and namespace theplu
     113}} // of namespace statistics and namespace theplu
    127114
    128115#endif
  • trunk/lib/statistics/Regression.cc

    r294 r295  
    11// $Id$
    22
    3 #include "Regression.h"
     3#include <c++_tools/statistics/Regression.h>
    44
    55namespace theplu {
  • trunk/lib/statistics/Regression.h

    r294 r295  
    44#define _theplu_statistics_regression_
    55
    6 #include "vector.h"
    7 
     6#include <ostream>
    87
    98namespace theplu {
     9namespace gslapi {
     10  class vector;
     11}
     12
    1013namespace statistics { 
    1114
     
    4649                    const gslapi::vector& w)=0;
    4750    ///
    48     ///
     51    /// function predicting in one point
    4952    ///
    5053    virtual void predict(const double x, double& y, double& y_err,
     
    6164             
    6265  protected:
     66    ///
     67    /// x for predicted point
     68    ///
    6369    double x_;
     70    ///
     71    /// y for predicted point
     72    ///
    6473    double y_;
     74    ///
     75    /// estimated error of predicted point (in y).
     76    ///
    6577    double y_err_;
    6678  };
  • trunk/lib/statistics/RegressionLinear.cc

    r294 r295  
    11// $Id$
    22
    3 // Header
    4 #include "RegressionLinear.h"
     3#include <c++_tools/statistics/RegressionLinear.h>
    54
    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>
    108
    119#include <gsl/gsl_fit.h>
  • trunk/lib/statistics/RegressionLinear.h

    r294 r295  
    44#define _theplu_statistics_regression_linear_
    55
    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>
    108
    11 // Standard C++ includes
    12 ////////////////////////
    139#include <cmath>
    1410
  • trunk/lib/statistics/RegressionLocal.cc

    r294 r295  
    11// $Id$
    22
    3 #include "RegressionLocal.h"
     3#include <c++_tools/statistics/RegressionLocal.h>
    44
    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>
    98
    10 #include "algorithm"
     9//#include <algorithm>
    1110
    1211namespace theplu {
    1312namespace statistics {
    1413
    15   RegressionLocal::RegressionLocal(Regression& r,
    16                                    RegressionKernel& k)
     14  RegressionLocal::RegressionLocal(Regression& r, Kernel& k)
    1715    : kernel_(&k), regressor_(&r)
    1816  {
  • trunk/lib/statistics/RegressionLocal.h

    r294 r295  
    44#define _theplu_statistics_regression_local_
    55
    6 // C++ tools include
    7 /////////////////////
    8 #include "Regression.h"
    9 #include "RegressionKernel.h"
    10 #include "vector.h"
     6#include <c++_tools/statistics/RegressionLocal.h>
    117
    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>
    1411
    1512
     
    4643    /// type of \a kernel.
    4744    ///
    48     RegressionLocal(Regression& regressor, RegressionKernel& kernel);
     45    RegressionLocal(Regression& regressor, Kernel& kernel);
    4946
    5047    ///
     
    9794  private:
    9895    std::vector<std::pair<double, double> > data_;
    99     RegressionKernel* kernel_;
     96    Kernel* kernel_;
    10097    Regression* regressor_;
    10198    std::vector<double> x_;
  • trunk/lib/statistics/RegressionNaive.cc

    r294 r295  
    22
    33
    4 #include "RegressionNaive.h"
     4#include <c++_tools/statistics/RegressionNaive.h>
    55
    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>
    1010
    1111#include <iostream>
     
    3535                            const gslapi::vector& w)
    3636  {
    37     WeightedAverager a;
     37    AveragerWeighted a;
    3838    for (size_t i=0; i<y.size(); i++)
    3939      a.add(y(i), w(i));
  • trunk/lib/statistics/RegressionNaive.h

    r294 r295  
    44#define _theplu_statistics_regression_naive_
    55
    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
    1513#include <iostream>
    1614#include <utility>
  • trunk/lib/statistics/Score.cc

    r294 r295  
    11// $Id$
    22
    3 #include "Score.h"
     3#include <c++_tools/statistics/Score.h>
    44
    55namespace theplu {
    6 namespace cpptools { 
     6namespace statistics { 
    77
    88  Score::Score(bool absolute)
  • trunk/lib/statistics/Score.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_score_
    4 #define _theplu_cpptools_score_
     3#ifndef _theplu_statistics_score_
     4#define _theplu_statistics_score_
    55
    6 #include "vector.h"
     6#include <c++_tools/gslapi/vector.h>
    77
    88namespace theplu {
    9 namespace cpptools {
     9namespace statistics {
    1010
    1111  ///
     
    3131    inline void absolute(bool absolute) {absolute_=absolute;}
    3232
     33    ///
     34    /// @return statistica.
     35    ///
    3336    virtual double
    3437    score(const gslapi::vector&,
     
    3639          const std::vector<size_t>& = std::vector<size_t>()) = 0;
    3740 
     41    ///
     42    /// @return statistica (weighted version)
     43    ///
    3844    virtual double
    3945    score(const gslapi::vector&,
     
    4248          const std::vector<size_t>& = std::vector<size_t>()) = 0;
    4349
     50    ///
     51    /// @return the ///one-sided p-value( if absolute true is used
     52    /// this is equivalent to the two-sided p-value.)
     53    ///
    4454    virtual double p_value(void) const = 0;
    4555 
     
    5666  }; // class Score
    5767
    58 }} // of namespace cpptools and namespace theplu
     68}} // of namespace statistics and namespace theplu
    5969
    6070#endif
  • trunk/lib/statistics/tScore.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_t_score_
    4 #define _theplu_cpptools_t_score_
     3#ifndef _theplu_statistics_t_score_
     4#define _theplu_statistics_t_score_
    55
    66// C++ tools include
    77/////////////////////
    8 #include "Score.h"
    9 #include "vector.h"
     8#include <c++_tools/statistics/Score.h>
     9#include <c++_tools/gslapi/vector.h>
     10
    1011#include <gsl/gsl_cdf.h>
    1112
    12 // Standard C++ includes
    13 ////////////////////////
    14 //#include <utility>
    15 //#include <vector>
    1613
    1714namespace theplu {
    18 namespace cpptools { 
     15namespace statistics { 
    1916  ///
    2017  /// Class for Fisher's t-test.
     
    7572  };
    7673
    77 }} // of namespace cpptools and namespace theplu
     74}} // of namespace statistics and namespace theplu
    7875
    7976#endif
  • trunk/lib/svm/ConsensusInputRanker.cc

    r294 r295  
    22
    33
    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>
    105
    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>
    1213#include <vector>
    1314
    1415namespace theplu {
    15 namespace cpptools
     16namespace svm
    1617
    1718  ConsensusInputRanker::ConsensusInputRanker(const gslapi::matrix& data,
    1819                                             const gslapi::vector& target,
    19                                              Score& score_object,
     20                                             statistics::Score& score_object,
    2021                                             const size_t rounds,
    2122                                             const size_t k)
     
    4344    //sort medians and assign id_ and rank_
    4445    sort(median.begin(), median.end(),
    45          pair_value_compare<size_t, double>());
     46         cpptools::pair_value_compare<size_t, double>());
    4647    id_.resize(data.rows());
    4748    rank_.resize(data.rows());
     
    5657                                             const gslapi::vector& target,
    5758                                             const gslapi::matrix& weight,
    58                                              Score& score_object,
     59                                             statistics::Score& score_object,
    5960                                             const size_t rounds,
    6061                                             const size_t k)
     
    8081    //sort medians and assign id_ and rank_
    8182    sort(median.begin(), median.end(),
    82          pair_value_compare<size_t, double>());
     83         cpptools::pair_value_compare<size_t, double>());
    8384    id_.resize(data.rows());
    8485    rank_.resize(data.rows());
     
    9192   
    9293
    93 }} // of namespace cpptools and namespace theplu
     94}} // of namespace svm and namespace theplu
  • trunk/lib/svm/ConsensusInputRanker.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_consensusinputranker_
    4 #define _theplu_cpptools_consensusinputranker_
     3#ifndef _theplu_svm_consensusinputranker_
     4#define _theplu_svm_consensusinputranker_
    55
    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>
    167
    178namespace theplu {
    18 namespace cpptools { 
     9  class gslapi::matrix;
     10  class gslapi::vector;
     11  class statistics::Score;
     12namespace svm { 
    1913
    2014  ///
     
    3428    ConsensusInputRanker(const gslapi::matrix& data,
    3529                         const gslapi::vector& target,
    36                          Score&,
     30                         statistics::Score&,
    3731                         const size_t n = 1 ,
    3832                         const size_t k = 3 );
     
    4640                         const gslapi::vector& target,
    4741                         const gslapi::matrix& weight,
    48                          Score&,
     42                         statistics::Score&,
    4943                         const size_t n = 1 ,
    5044                         const size_t k = 3 );
     
    7165  };
    7266
    73 }} // of namespace cpptools and namespace theplu
     67}} // of namespace svm and namespace theplu
    7468
    7569#endif
  • trunk/lib/svm/CrossValidation.cc

    r294 r295  
    11// $Id$
    22
    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
    48#include <vector>
    59
    6 // Thep C++ Tools
    7 #include "random_singleton.h"
    8 #include "CrossValidation.h"
    9 
    1010namespace theplu {
    11 namespace cpptools
     11namespace svm
    1212
    1313  CrossValidation::CrossValidation(const theplu::gslapi::vector& target,
     
    2424    }
    2525
    26     my_uniform_rng a;
     26    cpptools::my_uniform_rng a;
    2727    random_shuffle(index_negative_.begin(), index_negative_.end(), a);
    2828    random_shuffle(index_positive_.begin(), index_positive_.end(), a);
     
    3333    if (count_==k_){
    3434      count_=0;
    35       my_uniform_rng a;
     35      cpptools::my_uniform_rng a;
    3636      random_shuffle(index_negative_.begin(), index_negative_.end(), a);
    3737      random_shuffle(index_positive_.begin(), index_positive_.end(), a);
  • trunk/lib/svm/CrossValidation.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_crossvalidation_
    4 #define _theplu_cpptools_crossvalidation_
     3#ifndef _theplu_svm_crossvalidation_
     4#define _theplu_svm_crossvalidation_
    55
    6 // C++ tools include
    7 /////////////////////
    8 #include "vector.h"
    9 
    10 // Standard C++ includes
    11 ////////////////////////
    126#include <vector>
    137
    148namespace theplu {
    15 namespace cpptools { 
     9namespace gslapi {
     10  class vector;
     11}
     12namespace svm { 
    1613
    1714  ///
     
    2421  public:
    2522    ///
    26     /// Constructor taking \a target and \k for k-fold cross validation
     23    /// Constructor taking \a target and \a k for k-fold cross validation
    2724    ///
    2825    CrossValidation(const theplu::gslapi::vector& target, const size_t k = 3);
     
    4643  };
    4744
    48 }} // of namespace cpptools and namespace theplu
     45}} // of namespace svm and namespace theplu
    4946
    5047#endif
  • trunk/lib/svm/GaussianKernelFunction.cc

    r294 r295  
    11// $Id$
    22
    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
    49#include <math.h>
    510
    6 
    7 // Thep C++ Tools
    8 #include "GaussianKernelFunction.h"
    9 #include "matrix.h"
    10 #include "vector.h"
    11 
    1211namespace theplu {
    13 namespace cpptools
     12namespace svm
    1413
    1514GaussianKernelFunction::GaussianKernelFunction(double sigma)
     
    5352}
    5453
    55 }} // of namespace cpptools and namespace theplu
     54}} // of namespace svn and namespace theplu
  • trunk/lib/svm/GaussianKernelFunction.h

    r294 r295  
    11// $Id$
    22
    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_
    55
    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>
    810
    911namespace theplu {
     12class gslapi::vector;
    1013
    11 namespace gslapi {
    12   class vector;
    13 }
    14 
    15 namespace cpptools {
     14namespace svm {
    1615
    1716  ///
    1817  /// Class for Gaussian kernel calculations.
    1918  ///
    20 
    2119 
    2220  class GaussianKernelFunction : public KernelFunction
     
    4139    inline double operator()(const gslapi::vector& a1,
    4240                             const gslapi::vector& a2)
    43       {return exp(-(a1-a2)*(a1-a2)/pow(sigma_,2));}
     41      {return exp(-(a1-a2)*(a1-a2)/(sigma_*sigma_));}
    4442
     43    ///
    4544    ///returning the scalar product of two vectors in feature space using the
    4645    ///Gaussian kernel with weights.
     
    5251         
    5352    ///
    54     /// @kernel matrix
     53    /// @return kernel matrix
    5554    ///
    5655    const gslapi::matrix& operator()(theplu::gslapi::matrix& kernel,
     
    6261  }; // class GaussianKernelFunction
    6362
    64 }} // of namespace cpptools and namespace theplu
     63}} // of namespace svm and namespace theplu
    6564
    6665#endif
  • trunk/lib/svm/InputRanker.cc

    r294 r295  
    11// $Id$
    22
    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>
    99
    1010#include <vector>
     
    1212
    1313namespace theplu {
    14 namespace cpptools
     14namespace svm
    1515
    1616  InputRanker::InputRanker()
     
    2424  InputRanker::InputRanker(const gslapi::matrix& data,
    2525                           const gslapi::vector& target,
    26                            Score& score_object,
     26                           statistics::Score& score_object,
    2727                           const std::vector<size_t>& train_set)
    2828    :train_set_(train_set),
     
    4949    //sort the scores and assign id_ and rank_
    5050    sort(score.begin(), score.end(),
    51          pair_value_compare<size_t, double>());
     51         cpptools::pair_value_compare<size_t, double>());
    5252   
    5353    for (size_t i=0; i<nof_genes; i++){
     
    6060                           const gslapi::vector& target,
    6161                           const gslapi::matrix& weight,
    62                            Score& score_object,
     62                           statistics::Score& score_object,
    6363                           const std::vector<size_t>& train_set)
    6464    :train_set_(train_set),
     
    8484    //sort the scores and assign id_ and rank_
    8585    sort(score.begin(), score.end(),
    86          pair_value_compare<size_t, double>());
     86         cpptools::pair_value_compare<size_t, double>());
    8787
    8888    for (size_t i=0; i<nof_genes; i++){
     
    9292  }
    9393 
    94 }} // of namespace cpptools and namespace theplu
     94}} // of namespace svm and namespace theplu
  • trunk/lib/svm/InputRanker.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_inputranker_
    4 #define _theplu_cpptools_inputranker_
     3#ifndef _theplu_svm_inputranker_
     4#define _theplu_svm_inputranker_
    55
    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>
    157
    168namespace theplu {
    17 namespace cpptools { 
     9namespace gslapi {
     10  class matrix;
     11  class vector;
     12}
     13namespace statistics {
     14  class Score;
     15}
     16namespace svm { 
    1817  ///
    1918  /// Class for ranking rows in a matrix, using a Score and a
     
    3635    InputRanker(const gslapi::matrix&,
    3736                const gslapi::vector&,
    38                 Score&,
     37                statistics::Score&,
    3938                const std::vector<size_t>& = std::vector<size_t>());
    4039
     
    4746                const gslapi::vector&,
    4847                const gslapi::matrix&,
    49                 Score&,
     48                statistics::Score&,
    5049                const std::vector<size_t>& = std::vector<size_t>());
    5150
     
    7170  };
    7271
    73 }} // of namespace cpptools and namespace theplu
     72}} // of namespace svm and namespace theplu
    7473
    7574#endif
  • trunk/lib/svm/Kernel.cc

    r294 r295  
    11// $Id$
    22
    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>
    88
    99namespace theplu {
    10 namespace cpptools
     10namespace svm
    1111
    1212Kernel::Kernel(const gslapi::matrix& data, const KernelFunction& kf)
     
    3232
    3333
    34 }} // of namespace cpptools and namespace theplu
     34}} // of namespace svm and namespace theplu
  • trunk/lib/svm/Kernel.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_kernel_
    4 #define _theplu_cpptools_kernel_
     3#ifndef _theplu_svm_kernel_
     4#define _theplu_svm_kernel_
    55
    6 #include "matrix.h"
     6#include <c++_tools/gslapi/matrix.h>
    77
    88namespace theplu {
    9 namespace cpptools {
     9namespace svm {
    1010
    1111  class KernelFunction;
     
    4242  private:
    4343    gslapi::matrix k_;
    44     const theplu::cpptools::KernelFunction* kf_;
     44    const KernelFunction* kf_;
    4545    bool weighted_;
    4646
    4747  }; // class Kernel
    4848
    49 }} // of namespace cpptools and namespace theplu
     49}} // of namespace svm and namespace theplu
    5050
    5151#endif
  • trunk/lib/svm/KernelFunction.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_kernel_function_
    4 #define _theplu_cpptools_kernel_function_
     3#ifndef _theplu_svm_kernel_function_
     4#define _theplu_svm_kernel_function_
    55
    66namespace theplu {
     
    1111}
    1212
    13 namespace cpptools {
     13namespace svm {
    1414
    1515  ///
     
    3030    virtual ~KernelFunction(void) {};
    3131   
     32    ///
     33    /// @return scalar product of two vector in feature space.
     34    ///
    3235    virtual double operator()(const gslapi::vector&,
    3336                              const gslapi::vector&) const = 0;
    3437   
     38    ///
     39    /// @return scalar product of two vector in feature space.
     40    ///
    3541    virtual double operator()(const gslapi::vector&,
    3642                              const gslapi::vector&,
     
    3844                              const gslapi::vector&) const = 0;
    3945   
     46    ///
     47    /// @return kernel matrix
     48    ///
    4049    virtual const theplu::gslapi::matrix& operator()
    4150      (theplu::gslapi::matrix& k, const gslapi::matrix& data) const = 0;
     
    4352  }; // class KernelFunction
    4453
    45 }} // of namespace cpptools and namespace theplu
     54}} // of namespace svm and namespace theplu
    4655
    4756#endif
  • trunk/lib/svm/PolynomialKernelFunction.cc

    r294 r295  
    11// $Id$
    22
    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
    49#include <math.h>
    5 
    6 // Thep C++ Tools
    7 #include "PolynomialKernelFunction.h"
    8 #include "matrix.h"
    9 #include "vector.h"
    1010
    1111
    1212namespace theplu {
    13 namespace cpptools
     13namespace svm
    1414
    1515PolynomialKernelFunction::PolynomialKernelFunction(int order)
     
    4848                                     const theplu::gslapi::matrix& data) const
    4949{
    50   theplu::gslapi::matrix data_transposed(data.transpose());
     50  gslapi::matrix data_transposed(data.transpose());
    5151  kernel = data_transposed*data;
    5252  if (order_>1)
  • trunk/lib/svm/PolynomialKernelFunction.h

    r294 r295  
    11// $Id$
    22
    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_
    55
    6 #include "KernelFunction.h"
     6#include <c++_tools/svm/KernelFunction.h>
    77
    88namespace theplu {
     
    1212}
    1313
    14 namespace cpptools {
     14namespace svm {
    1515
    1616  ///
     
    4949   
    5050    ///
    51     /// @kernel matrix
     51    /// @return kernel matrix
    5252    ///
    5353    const gslapi::matrix& operator()(theplu::gslapi::matrix& kernel,
     
    5959  }; // class PolynomialKernelFunction
    6060
    61 }} // of namespace cpptools and namespace theplu
     61}} // of namespace svm and namespace theplu
    6262
    6363#endif
  • trunk/lib/svm/SVM.cc

    r294 r295  
    11// $Id$
    22
    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
    611#include <cmath>
    712#include <limits.h>
     
    914#include <vector>
    1015
    11 // Thep C++ Tools
    12 #include "Averager.h"
    13 #include "matrix.h"
    14 #include "random_singleton.h"
    15 #include "vector.h"
    16 
    17 
    1816
    1917namespace theplu {
    20 namespace cpptools
     18namespace svm
    2119
    2220  SVM::SVM(const Kernel& kernel,
     
    7674    for (size_t i=0; i<E.size(); i++)
    7775      tmp[i]=i;
    78     my_uniform_rng a;
     76    cpptools::my_uniform_rng a;
    7977    random_shuffle(tmp.begin(), tmp.end(), a);
    8078    for (size_t i=0; i<tmp.size(); i++){
  • trunk/lib/svm/SVM.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_svm_
    4 #define _theplu_cpptools_svm_
     3#ifndef _theplu_svm_svm_
     4#define _theplu_svm_svm_
    55
    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>
    118
    12 
    13 // Standard C++ includes
    14 ////////////////////////
    159#include <utility>
    1610#include <vector>
     
    1812
    1913namespace theplu {
    20 namespace cpptools
     14namespace svm
    2115  ///
    2216  /// Class for SVM using Keerthi's second modification of Platt's SMO. Also
     
    3529    /// Constructor taking the kernel matrix and the target vector as input
    3630    ///
    37     SVM(const Kernel&, const gslapi::vector&,
     31    SVM(const Kernel&,
     32        const gslapi::vector&,
    3833        const std::vector<size_t>& = std::vector<size_t>());
    3934         
     
    9085    double bias_;
    9186    double c_;
    92     Kernel kernel_;
     87    Kernel kernel_; // Peter, const ref?
    9388    unsigned long int max_epochs_;
    94     gslapi::vector target_;
     89    gslapi::vector target_; // Peter, const ref?
    9590    bool trained_;
    9691    std::vector<size_t> train_set_;
     
    116111
    117112
    118 }} // of namespace cpptools and namespace theplu
     113}} // of namespace svm and namespace theplu
    119114
    120115#endif
  • trunk/lib/utility/Alignment.cc

    r294 r295  
    11// $Id$
    22
    3 #include "Alignment.h"
    4 #include "matrix.h"
     3#include <c++_tools/utility/Alignment.h>
     4#include <c++_tools/gslapi/matrix.h>
    55
    66#include <utility>
  • trunk/lib/utility/FileIO.cc

    r294 r295  
    11// $Id$
     2
     3#include <c++_tools/utility/FileIO.h>
    24
    35#include <iostream>
    46#include <unistd.h>
    57
    6 #include "FileIO.h"
    78
    89namespace theplu {
  • trunk/lib/utility/Merge.cc

    r294 r295  
    11// $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>
    29
    310#include <algorithm>
     
    512#include <fstream>
    613#include <map>
    7 
    8 #include "stl_utility.h"
    9 #include "Merge.h"
    10 #include "Averager.h"
    11 #include "WeightedAverager.h"
    1214
    1315namespace theplu {
     
    8890
    8991  void Merge::merging(vector<u_int> index, gslapi::matrix& weights){
    90     statistics::WeightedAverager w_av;
     92    statistics::AveragerWeighted w_av;
    9193    statistics::Averager av;
    9294    // merge genes for each assay
  • trunk/lib/utility/Merge.h

    r294 r295  
    11// $Id$
    22
    3 #ifndef _theplu_cpptools_merge_  //vad är detta?
     3#ifndef _theplu_cpptools_merge_ 
    44#define _theplu_cpptools_merge_
     5
     6#include <c++_tools/gslapi/matrix.h>
     7//#include <c++_tools/gslapi/vector.h>
    58
    69#include <iostream>
     
    912#include <vector>
    1013
    11 #include "vector.h"
    12 #include "matrix.h"
    1314
    1415namespace theplu {
     
    1718  using namespace std;
    1819
    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
    2928  class Merge
    3029  {
     
    5554   
    5655    ///
    57     /// Return matrix
    58     ///
    5956    /// @return Const reference to the data matrix.
    6057    ///
    6158    inline const gslapi::matrix& data_matrix(void) const { return data_; }
     59
     60    ///
     61    /// @return Const reference to the error matrix.
     62    ///
    6263    inline const gslapi::matrix& error_matrix(void) const { return error_; }
    6364
  • trunk/lib/utility/NNI.cc

    r294 r295  
    11// $Id$
     2
     3#include <c++_tools/utility/NNI.h>
     4
     5#include <c++_tools/utility/stl_utility.h>
    26
    37#include <algorithm>
     
    59#include <fstream>
    610
    7 #include "stl_utility.h"
    8 #include "NNI.h"
    911
    1012namespace theplu {
  • trunk/lib/utility/NNI.h

    r294 r295  
    88#include <vector>
    99
    10 #include "matrix.h"
     10#include <c++_tools/gslapi/matrix.h>
    1111
    1212namespace theplu {
  • trunk/lib/utility/PCA.cc

    r294 r295  
    55#include <memory>
    66
    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
    1310
    1411namespace theplu {
  • trunk/lib/utility/PCA.h

    r294 r295  
    44#define _theplu_cpptools_pca_
    55
    6 #include "vector.h"
    7 #include "matrix.h"
     6#include <c++_tools/gslapi/matrix.h>
     7#include <c++_tools/gslapi/vector.h>
    88
    99// Standard C++ includes
  • trunk/lib/utility/SVD.cc

    r294 r295  
    11// $Id$
    22
    3 #include "SVD.h"
     3#include <c++_tools/utility/SVD.h>
    44
    55
  • trunk/lib/utility/SVD.h

    r294 r295  
    44#define _theplu_cpptools_svd_
    55
    6 #include "matrix.h"
    7 #include "vector.h"
     6#include <c++_tools/gslapi/matrix.h>
     7#include <c++_tools/gslapi/vector.h>
    88
    99#include <gsl/gsl_linalg.h>
  • trunk/lib/utility/WeNNI.cc

    r294 r295  
    11// $Id$
    22
    3 #include "WeNNI.h"
     3#include <c++_tools/utility/WeNNI.h>
     4
     5#include <c++_tools/utility/stl_utility.h>
    46
    57#include <algorithm>
    68#include <cmath>
    79#include <fstream>
    8 
    9 #include "stl_utility.h"
    1010
    1111namespace theplu {
  • trunk/lib/utility/WeNNI.h

    r294 r295  
    44#define _theplu_cpptools_wenni_
    55
    6 #include "NNI.h"
     6#include <c++_tools/utility/NNI.h>
     7
     8#include <c++_tools/gslapi/matrix.h>
    79
    810#include <iostream>
    911
    10 #include "matrix.h"
     12
    1113
    1214namespace theplu {
  • trunk/lib/utility/kNNI.cc

    r294 r295  
    11// $Id$
    22
    3 #include "kNNI.h"
     3#include <c++_tools/utility/kNNI.h>
    44
    55#include <algorithm>
     
    88#include <vector>
    99
    10 #include "stl_utility.h"
     10#include <c++_tools/utility/stl_utility.h>
    1111
    1212namespace theplu {
  • trunk/lib/utility/kNNI.h

    r294 r295  
    44#define _theplu_cpptools_knni_
    55
    6 #include "NNI.h"
     6#include <c++_tools/utility/NNI.h>
    77
    88#include <iostream>
  • trunk/lib/utility/random_singleton.cc

    r294 r295  
    11// $Id$
    22
    3 #include "random_singleton.h"
     3#include <c++_tools/utility/random_singleton.h>
    44
    55namespace theplu {
  • trunk/lib/utility/stl_utility.cc

    r294 r295  
    11// $Id$
    22
    3 #include "stl_utility.h"
     3#include <c++_tools/utility/stl_utility.h>
    44
    55#include <iostream>
  • trunk/lib/utility/stl_utility.h

    r294 r295  
    2727  struct pair_value_compare
    2828  {
     29    ///
     30    /// @return true if x.second<y.second or (x.second==y.second and
     31    /// x.first<y.first)
     32    ///
    2933    inline bool operator()(const std::pair<T1,T2>& x,
    3034                           const std::pair<T1,T2>& y) {
Note: See TracChangeset for help on using the changeset viewer.