source: trunk/c++_tools/statistics/Polynomial.cc @ 586

Last change on this file since 586 was 586, checked in by Peter, 15 years ago

closes #23 redesign of regression classes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.0 KB
Line 
1// $Id: Polynomial.cc 586 2006-06-19 09:56:04Z peter $
2
3#include <c++_tools/statistics/Polynomial.h>
4#include <c++_tools/gslapi/matrix.h>
5#include <c++_tools/gslapi/vector.h>
6
7namespace theplu {
8namespace statistics {
9namespace regression {
10
11
12  void Polynomial::fit(const gslapi::vector& x, const gslapi::vector& y)
13  {
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);
19  }
20
21  double Polynomial::predict(const double x) const
22  {
23    gslapi::vector vec(power_+1,1);
24    for (size_t i=1; i<=power_; ++i)
25      vec(i) = vec(i-1)*x;
26    return md_.predict(vec);
27  }
28
29  double Polynomial::prediction_error(const double x) const
30  {
31    gslapi::vector vec(power_+1,1);
32    for (size_t i=1; i<=power_; ++i)
33      vec(i) = vec(i-1)*x;
34    return md_.prediction_error(vec);
35  }
36
37  double Polynomial::standard_error(const double x) const
38  {
39    gslapi::vector vec(power_+1,1);
40    for (size_t i=1; i<=power_; ++i)
41      vec(i) = vec(i-1)*x;
42    return md_.standard_error(vec);
43  }
44
45}}} // of namespaces regression, statisitcs and thep
Note: See TracBrowser for help on using the repository browser.