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

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

Continued fixing of regression stuff.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 871 bytes
Line 
1// $Id: Polynomial.cc 385 2005-08-13 09:24:18Z 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(void)
14  {
15    if (work_)
16      gsl_multifit_linear_free(work_);
17  }
18
19
20
21  void Polynomial::fit(const gslapi::vector& x, const gslapi::vector& y)
22  {
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_);
33  }
34
35
36}}} // of namespaces regression, statisitcs and thep
Note: See TracBrowser for help on using the repository browser.