Changeset 386


Ignore:
Timestamp:
Aug 15, 2005, 1:16:52 AM (16 years ago)
Author:
Jari Häkkinen
Message:

Extracted the underlying GSL multifit algo from Polynomial into separate
class (MultiDimensional?).

Location:
trunk/lib/statistics
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/statistics/Makefile.am

    r384 r386  
    99libstatistics_la_SOURCES = \
    1010  Averager.cc AveragerPair.cc AveragerWeighted.cc Fisher.cc Histogram.cc \
    11   Kernel.cc KernelBox.cc KernelTriCube.cc Linear.cc Local.cc Naive.cc \
     11  Kernel.cc KernelBox.cc KernelTriCube.cc Linear.cc Local.cc \
     12  MultiDimensional.cc Naive.cc \
    1213  Pearson.cc Polynomial.cc ROC.cc Score.cc utility.cc
    1314
     
    1617include_statistics_HEADERS = \
    1718  Averager.h AveragerPair.h AveragerWeighted.h Fisher.h Histogram.h \
    18   Kernel.h KernelBox.h KernelTriCube.h Linear.h Local.h Naive.h \
     19  Kernel.h KernelBox.h KernelTriCube.h Linear.h Local.h \
     20  MultiDimensional.h Naive.h \
    1921  OneDimensional.h Pearson.h Polynomial.h ROC.h Score.h tScore.h utility.h
  • trunk/lib/statistics/Polynomial.cc

    r385 r386  
    33#include <c++_tools/statistics/Polynomial.h>
    44#include <c++_tools/gslapi/matrix.h>
    5 
    6 #include <cmath>
     5#include <c++_tools/gslapi/vector.h>
    76
    87namespace theplu {
     
    1110
    1211
    13   Polynomial::~Polynomial(void)
    14   {
    15     if (work_)
    16       gsl_multifit_linear_free(work_);
    17   }
    18 
    19 
    20 
    2112  void Polynomial::fit(const gslapi::vector& x, const gslapi::vector& y)
    2213  {
    23     if (work_)
    24       gsl_multifit_linear_free(work_);
    25     work_=gsl_multifit_linear_alloc(x.size(),fit_parameters_.size());
    26     X_=gslapi::matrix(x.size(),fit_parameters_.size());
    27     for (size_t i=0; i<x.size(); ++i)
    28       for (u_int j=0; j<fit_parameters_.size(); j++)
    29         X_(i,j)=pow(x(i),j);
    30     gsl_multifit_linear(X_.gsl_matrix_pointer(),y.gsl_vector_pointer(),
    31                         fit_parameters_.TEMP_gsl_vector_pointer(),
    32                         covariance_.gsl_matrix_pointer(),&chisquare_,work_);
     14    gslapi::matrix X=gslapi::matrix(x.size(),power_+1,1);
     15    for (size_t i=0; i<X.rows(); ++i)
     16      for (u_int j=1; j<X.columns(); j++)
     17        X(i,j)=X(i,j-1)*x(i);
     18    md_.fit(X,y);
    3319  }
    3420
  • trunk/lib/statistics/Polynomial.h

    r385 r386  
    55
    66#include <c++_tools/statistics/OneDimensional.h>
     7#include <c++_tools/statistics/MultiDimensional.h>
    78
    8 #include <c++_tools/gslapi/matrix.h>
    99#include <c++_tools/gslapi/vector.h>
    1010
     
    2727    ///
    2828    inline Polynomial(size_t power)
    29       : OneDimensional(), chisquare_(0),
    30         covariance_(gslapi::matrix(power+1,power+1)),
    31         fit_parameters_(gslapi::vector(power+1)), work_(NULL) {}
     29      : OneDimensional(), power_(power) {}
    3230
    3331    ///
    3432    /// @brief Destructor
    3533    ///
    36     ~Polynomial(void);
     34    inline ~Polynomial(void) {};
    3735
    3836    ///
     
    4442    ///
    4543    ///
    46     gslapi::vector fit_parameters(void) { return fit_parameters_; }
     44    gslapi::vector fit_parameters(void) { return md_.fit_parameters(); }
    4745
    4846    inline void fit(const gslapi::vector& x, const gslapi::vector& y,
     
    6058
    6159  private:
    62     double chisquare_;
    63     gslapi::matrix covariance_;
    64     gslapi::vector fit_parameters_;
    65     gsl_multifit_linear_workspace* work_;
    66     gslapi::matrix X_;    // matrix of predictor variables in GSL language
     60    MultiDimensional md_;
     61    size_t power_;
    6762
    6863  };
Note: See TracChangeset for help on using the changeset viewer.