source: trunk/lib/statistics/Polynomial.cc @ 383

Last change on this file since 383 was 383, checked in by Jari Häkkinen, 16 years ago

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).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 757 bytes
Line 
1// $Id: Polynomial.cc 383 2005-08-12 15:39:24Z jari $
2
3#include <c++_tools/statistics/Polynomial.h>
4#include <c++_tools/gslapi/matrix.h>
5
6#include <cmath>
7
8namespace theplu {
9namespace statistics {
10namespace regression {
11
12
13  Polynomial::Polynomial(gslapi::matrix& data, size_t power)
14    : chisquare_(0), covariance_(gslapi::matrix(power+1,power+1)),
15      fit_parameters_(gslapi::vector(power+1)),
16      target_(gslapi::vector(data.rows())),
17      X_(gslapi::matrix(data.rows(),power+1))
18  {
19    work_=gsl_multifit_linear_alloc(data.rows(),power+1);
20    for (size_t i=0; i<data.rows(); ++i) {
21      target_[i]=data(i,1);
22      for (u_int j=0; j<=power; j++)
23        X_(i,j)=pow(data(i,0),j);
24    }
25  }
26
27
28
29  Polynomial::~Polynomial(void)
30  {
31    gsl_multifit_linear_free(work_);
32  }
33
34
35}}} // of namespaces regression, statisitcs and thep
Note: See TracBrowser for help on using the repository browser.