Ignore:
Timestamp:
Aug 13, 2005, 11:24:18 AM (16 years ago)
Author:
Jari Häkkinen
Message:

Continued fixing of regression stuff.

File:
1 edited

Legend:

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

    r383 r385  
    1111
    1212
    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))
     13  Polynomial::~Polynomial(void)
    1814  {
    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     }
     15    if (work_)
     16      gsl_multifit_linear_free(work_);
    2517  }
    2618
    2719
    2820
    29   Polynomial::~Polynomial(void)
     21  void Polynomial::fit(const gslapi::vector& x, const gslapi::vector& y)
    3022  {
    31     gsl_multifit_linear_free(work_);
     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_);
    3233  }
    3334
Note: See TracChangeset for help on using the changeset viewer.