Changeset 383


Ignore:
Timestamp:
Aug 12, 2005, 5:39:24 PM (16 years ago)
Author:
Jari Häkkinen
Message:

Moved regression stuff into a namespace ...statistics::regression.
Filenames was changed and a first draft of a Polynomial regression is
implemented (compiles but does not run properly).

Location:
trunk
Files:
2 added
4 edited
8 moved

Legend:

Unmodified
Added
Removed
  • trunk/lib/statistics/Linear.cc

    r380 r383  
    11// $Id$
    22
    3 #include <c++_tools/statistics/RegressionLinear.h>
     3#include <c++_tools/statistics/Linear.h>
    44
    55#include <c++_tools/statistics/AveragerPair.h>
     
    1212namespace theplu {
    1313namespace statistics {
     14namespace regression {
    1415
    15  
    16   RegressionLinear::RegressionLinear(void)
    17     : Regression(), alpha_(0), alpha_var_(0), beta_(0), beta_var_(0), m_x_(0),
    18       s2_(0)
    19   {
    20   }
    2116
    22   void RegressionLinear::fit(const gslapi::vector& x, const gslapi::vector& y)
     17  void Linear::fit(const gslapi::vector& x, const gslapi::vector& y)
    2318  {
    2419    statistics::AveragerPair ap;
     
    4035  }
    4136
    42   void RegressionLinear::fit(const gslapi::vector& x, const gslapi::vector& y,
    43                              const gslapi::vector& w)
     37  void Linear::fit(const gslapi::vector& x,
     38                   const gslapi::vector& y,
     39                   const gslapi::vector& w)
    4440  {
    4541    double m_x = w*x /w.sum();
     
    6965  }
    7066
    71   std::ostream& RegressionLinear::print(std::ostream& s) const
     67  std::ostream& Linear::print(std::ostream& s) const
    7268  {
    7369    s << x_ << "\t"
     
    8480  }
    8581   
    86   std::ostream& RegressionLinear::print_header(std::ostream& s) const
     82  std::ostream& Linear::print_header(std::ostream& s) const
    8783  {
    8884    s << "# column 1: x\n"
     
    9894  }
    9995
    100    
    101 }} // of namespace statistics and namespace theplu
     96
     97}}} // of namespaces regression, statisitcs and thep
  • trunk/lib/statistics/Linear.h

    r380 r383  
    44#define _theplu_statistics_regression_linear_
    55
    6 #include <c++_tools/statistics/Regression.h>
     6#include <c++_tools/statistics/OneDimensional.h>
    77#include <c++_tools/gslapi/vector.h>
    88
     
    1111namespace theplu {
    1212namespace statistics { 
    13  
     13namespace regression {
     14
    1415  ///
    15   /// Class for Regression.   
     16  /// Class for OneDimensional.   
    1617  ///
    1718 
    18   class RegressionLinear : public Regression
     19  class Linear : public OneDimensional
    1920  {
    2021 
     
    2324    /// Default Constructor.
    2425    ///
    25     RegressionLinear(void);
     26    inline Linear(void)
     27      : OneDimensional(), alpha_(0), alpha_var_(0), beta_(0), beta_var_(0),
     28        m_x_(0), s2_(0) {}
    2629
    2730    ///
    2831    /// Copy Constructor. (not implemented)
    2932    ///
    30     RegressionLinear(const RegressionLinear&);
     33    Linear(const Linear&);
    3134
    3235    ///
    3336    /// Destructor
    3437    ///
    35     virtual ~RegressionLinear(void) {};
     38    virtual ~Linear(void) {};
    3639         
    3740    ///
     
    116119  };
    117120
    118 }} // of namespace statistics and namespace theplu
     121}}} // of namespaces regression, statisitcs and thep
    119122
    120123#endif
    121 
  • trunk/lib/statistics/Local.cc

    r380 r383  
    11// $Id$
    22
    3 #include <c++_tools/statistics/RegressionLocal.h>
     3#include <c++_tools/statistics/Local.h>
    44
    55#include <c++_tools/gslapi/vector.h>
    66#include <c++_tools/statistics/Kernel.h>
    7 #include <c++_tools/statistics/Regression.h>
     7#include <c++_tools/statistics/OneDimensional.h>
    88
    99//#include <algorithm>
     
    1111namespace theplu {
    1212namespace statistics {
     13namespace regression {
    1314
    14   RegressionLocal::RegressionLocal(Regression& r, Kernel& k)
    15     : kernel_(&k), regressor_(&r)
    16   {
    17   }
    1815
    19   void RegressionLocal::fit(std::ostream& s, const double f,
     16  void Local::fit(std::ostream& s, const double f,
    2017                            const u_int step_size)
    2118  {
     
    9390
    9491
    95 
    96 }} // of namespace statistics and namespace theplu
     92}}} // of namespaces regression, statisitcs and thep
  • trunk/lib/statistics/Local.h

    r380 r383  
    44#define _theplu_statistics_regression_local_
    55
    6 #include <c++_tools/statistics/RegressionLocal.h>
    7 
    86#include <c++_tools/statistics/Kernel.h>
    9 #include <c++_tools/statistics/Regression.h>
     7#include <c++_tools/statistics/OneDimensional.h>
    108#include <c++_tools/gslapi/vector.h>
    119
    1210
    1311namespace theplu {
    14 namespace statistics { 
    15  
    16  
     12namespace statistics {
     13namespace regression {
     14
    1715  ///
    1816  /// Class for Locally weighted regression.
     
    2624  /// a pointwise approximation of the underlying (unknown) function.
    2725  ///
    28 
    29 
    30  
    31   class RegressionLocal
     26  class Local
    3227  {
    3328 
    3429  public:
    3530    ///
    36     /// Default Constructor.
    37     ///
    38     RegressionLocal(void);
    39 
    40     ///
    4131    /// Constructor taking type of \a regressor,
    4232    /// type of \a kernel.
    4333    ///
    44     RegressionLocal(Regression& regressor, Kernel& kernel);
    45 
    46     ///
    47     /// Copy Constructor. (Not implemented)
    48     ///
    49     RegressionLocal(const RegressionLocal&);
     34    inline Local(OneDimensional& r, Kernel& k) : kernel_(&k), regressor_(&r) {}
    5035
    5136    ///
    5237    /// Destructor
    5338    ///
    54     virtual ~RegressionLocal(void) {};
     39    virtual ~Local(void) {};
    5540
    5641
     
    9075    void fit(std::ostream& s, const double fraction, const u_int step_size=1);
    9176
    92  
    9377
    94          
    9578  private:
     79    ///
     80    /// Copy Constructor. (Not implemented)
     81    ///
     82    Local(const Local&);
     83
    9684    std::vector<std::pair<double, double> > data_;
    9785    Kernel* kernel_;
    98     Regression* regressor_;
     86    OneDimensional* regressor_;
    9987    std::vector<double> x_;
    10088    std::vector<double> y_;
    10189    std::vector<double> y_err_;
    102    
    103    
     90
    10491  };
    10592
    106 }} // of namespace statistics and namespace theplu
     93}}} // of namespaces regression, statisitcs and thep
    10794
    10895#endif
    109 
  • trunk/lib/statistics/Makefile.am

    r319 r383  
    22##
    33## $Id: Makefile.am 281 2005-04-20 16:45:02Z peter $
    4 
    54
    65
     
    109libstatistics_la_SOURCES = \
    1110  Averager.cc AveragerPair.cc AveragerWeighted.cc Fisher.cc Histogram.cc \
    12   Kernel.cc KernelBox.cc KernelTriCube.cc Pearson.cc Regression.cc \
    13   RegressionLinear.cc \
    14   RegressionLocal.cc RegressionNaive.cc ROC.cc Score.cc utility.cc
     11  Kernel.cc KernelBox.cc KernelTriCube.cc Linear.cc Local.cc Naive.cc \
     12  OneDimensional.cc Pearson.cc Polynomial.cc ROC.cc Score.cc utility.cc
    1513
    1614include_statisticsdir = $(includedir)/c++_tools/statistics
     
    1816include_statistics_HEADERS = \
    1917  Averager.h AveragerPair.h AveragerWeighted.h Fisher.h Histogram.h \
    20   Kernel.h KernelBox.h KernelTriCube.h Pearson.h Regression.h \
    21   RegressionLinear.h RegressionLocal.h RegressionNaive.h ROC.h \
    22   Score.h tScore.h utility.h
     18  Kernel.h KernelBox.h KernelTriCube.h Linear.h Local.h Naive.h \
     19  OneDimensional.h Pearson.h Polynomial.h ROC.h Score.h tScore.h utility.h
  • trunk/lib/statistics/Naive.cc

    r380 r383  
    11// $Id$
    22
    3 
    4 #include <c++_tools/statistics/RegressionNaive.h>
     3#include <c++_tools/statistics/Naive.h>
    54
    65#include <c++_tools/statistics/Averager.h>
    76#include <c++_tools/statistics/AveragerWeighted.h>
    8 #include <c++_tools/statistics/Regression.h>
     7#include <c++_tools/statistics/OneDimensional.h>
    98#include <c++_tools/gslapi/vector.h>
    109
     
    1413namespace theplu {
    1514namespace statistics {
     15namespace regression {
    1616
    17  
    18   RegressionNaive::RegressionNaive(void)
    19     : Regression(), m_(0.0), m_err_(0.0)
    20   {
    21   }
    2217
    23   void RegressionNaive::fit(const gslapi::vector& x, const gslapi::vector& y)
     18  void Naive::fit(const gslapi::vector& x, const gslapi::vector& y)
    2419  {
    2520    Averager a;
     
    3126  }
    3227
    33   void RegressionNaive::fit(const gslapi::vector& x,
    34                             const gslapi::vector& y,
    35                             const gslapi::vector& w)
     28  void Naive::fit(const gslapi::vector& x,
     29                  const gslapi::vector& y,
     30                  const gslapi::vector& w)
    3631  {
    3732    AveragerWeighted a;
     
    4338  }
    4439
    45   void RegressionNaive::predict(const double x, double& y, double& y_err,
    46                                 const double w)
     40  void Naive::predict(const double x, double& y, double& y_err, const double w)
    4741  {
    4842    x_ = x;
     
    5145  }
    5246 
    53   std::ostream& RegressionNaive::print(std::ostream& s) const
     47  std::ostream& Naive::print(std::ostream& s) const
    5448  {
    5549    s << x_ << "\t"
     
    5953  }
    6054 
    61   std::ostream& RegressionNaive::print_header(std::ostream& s) const
     55  std::ostream& Naive::print_header(std::ostream& s) const
    6256  {
    6357    s << "# column 1: x\n"
     
    6660    return s;
    6761  }
    68  
    69 }} // of namespace statistics and namespace theplu
     62
     63
     64}}} // of namespaces regression, statisitcs and thep
  • trunk/lib/statistics/Naive.h

    r380 r383  
    44#define _theplu_statistics_regression_naive_
    55
    6 #include <c++_tools/statistics/Regression.h>
     6#include <c++_tools/statistics/OneDimensional.h>
    77
    88#include <c++_tools/gslapi/vector.h>
    99#include <c++_tools/statistics/Averager.h>
    1010#include <c++_tools/statistics/AveragerWeighted.h>
    11 #include <c++_tools/statistics/RegressionNaive.h>
    1211
    1312#include <iostream>
     
    1514
    1615
     16namespace theplu {
     17namespace statistics {
     18namespace regression {
    1719
    18 namespace theplu {
    19 namespace statistics { 
    20  
    2120  ///
    22   /// Class for Regression.   
     21  /// Class for OneDimensional.   
    2322  ///
    24  
    25   class RegressionNaive : public Regression
     23  class Naive : public OneDimensional
    2624  {
    2725 
     
    3028    /// Default Constructor.
    3129    ///
    32     RegressionNaive(void);
     30    inline Naive(void) : OneDimensional(), m_(0.0), m_err_(0.0) {}
    3331
    3432    ///
    3533    /// Copy Constructor. (not implemented)
    3634    ///
    37     RegressionNaive(const RegressionNaive&);
     35    Naive(const Naive&);
    3836
    3937    ///
    4038    /// Destructor
    4139    ///
    42     virtual ~RegressionNaive(void) {};
     40    virtual ~Naive(void) {};
    4341         
    4442    ///
     
    8987  };
    9088
    91 }} // of namespace statistics and namespace theplu
     89
     90}}} // of namespaces regression, statisitcs and thep
    9291
    9392#endif
    94 
  • trunk/lib/statistics/OneDimensional.cc

    r380 r383  
    11// $Id$
    22
    3 #include <c++_tools/statistics/Regression.h>
     3#include <c++_tools/statistics/OneDimensional.h>
    44
    55namespace theplu {
    66namespace statistics {
    7 
    8  
    9   Regression::Regression()
    10     : x_(0.0), y_(0.0), y_err_(0.0)
    11   {
    12   }
     7namespace regression {
    138
    149
    1510
    16 }} // of namespace statistics and namespace theplu
     11
     12}}} // of namespaces regression, statisitcs and thep
  • trunk/lib/statistics/OneDimensional.h

    r380 r383  
    11// $Id$
    22
    3 #ifndef _theplu_statistics_regression_
    4 #define _theplu_statistics_regression_
     3#ifndef _theplu_statistics_regression_onedimensioanl_
     4#define _theplu_statistics_regression_onedimensioanl_
    55
    66#include <ostream>
     
    1111}
    1212
    13 namespace statistics { 
    14 
     13namespace statistics {
     14namespace regression {
    1515 
    1616  ///
    17   /// Virtual Class for Regression.   
     17  /// Virtual Class for OneDimensional.   
    1818  ///
    1919 
    20   class Regression
     20  class OneDimensional
    2121  {
    2222 
     
    2525    /// Default Constructor.
    2626    ///
    27     Regression();
     27    inline OneDimensional(void) : x_(0.0), y_(0.0), y_err_(0.0) {}
    2828
    29     ///
    30     /// Destructor
    31     ///
    32     virtual ~Regression(void) {};
     29    ///
     30    /// Destructor
     31    ///
     32    virtual ~OneDimensional(void) {};
    3333         
    3434    ///
     
    7878  };
    7979
    80 }} // of namespace statistics and namespace theplu
     80}}} // of namespaces regression, statisitcs and thep
    8181
    8282#endif
    83 
  • trunk/test/regression_linear_test.cc

    r301 r383  
    33// C++ tools include
    44////////////////////
    5 #include <c++_tools/statistics/RegressionLinear.h>
     5#include <c++_tools/statistics/Linear.h>
    66#include <c++_tools/gslapi/vector.h>
    77
     
    3232  w(3)=0.4;
    3333
    34   statistics::RegressionLinear r;
     34  statistics::regression::Linear r;
    3535  r.fit(x,w,y);
    3636  double y_predicted=0;
  • trunk/test/regression_local_test.cc

    r301 r383  
    22
    33#include <c++_tools/statistics/KernelBox.h>
    4 #include <c++_tools/statistics/RegressionLinear.h>
    5 #include <c++_tools/statistics/RegressionLocal.h>
    6 #include <c++_tools/statistics/RegressionNaive.h>
     4#include <c++_tools/statistics/Linear.h>
     5#include <c++_tools/statistics/Local.h>
     6#include <c++_tools/statistics/Naive.h>
    77#include <c++_tools/gslapi/vector.h>
    88
     
    1515using namespace theplu;
    1616
    17 bool test(statistics::Regression& r, statistics::Kernel& k)
     17bool test(statistics::regression::OneDimensional& r, statistics::Kernel& k)
    1818{
    19   statistics::RegressionLocal rl(r,k);
     19  statistics::regression::Local rl(r,k);
    2020  for (size_t i=0; i<1000; i++){
    2121    double x = i;
     
    4040  bool ok=true;
    4141 
    42   statistics::RegressionNaive rn;
     42  statistics::regression::Naive rn;
    4343  statistics::KernelBox kb;
    4444  ok = (ok && test(rn,kb));
    4545
    46   statistics::RegressionLinear rl;
     46  statistics::regression::Linear rl;
    4747  ok = (ok && test(rl,kb));
    4848
  • trunk/test/regression_naive_test.cc

    r301 r383  
    11// $Id$
    22
    3 #include <c++_tools/statistics/RegressionNaive.h>
     3#include <c++_tools/statistics/Naive.h>
    44#include <c++_tools/gslapi/vector.h>
    55
     
    2525  w(3)=0.4;
    2626
    27   statistics::RegressionNaive r;
     27  statistics::regression::Naive r;
    2828  r.fit(x,y,w);
    2929  double y_predicted=0;
Note: See TracChangeset for help on using the changeset viewer.