Changeset 280


Ignore:
Timestamp:
Apr 20, 2005, 6:19:31 PM (16 years ago)
Author:
Peter
Message:

modified to use vector views

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/RegressionLocal.cc

    r253 r280  
    2323  {
    2424    sort(data_.begin(), data_.end());
     25
     26    // coying data to 2 gslapi vectors ONCE to use views from
     27    gslapi::vector x_total(data_.size());
     28    gslapi::vector y_total(data_.size());
     29    for (size_t j=0; j<x_total.size(); j++)
     30      x_total(j)=data_[j].first;
     31    for (size_t j=0; j<y_total.size(); j++)
     32      y_total(j)=data_[j].second;
     33   
    2534    regressor_->print_header(s);
    2635    s << std::endl;
     
    5564      }
    5665
    57       // copying data
    58       // Peter, too much copying. Move the copying outside loop and
    59       // use a vector view (when available in gslapi::vector class).
    60       gslapi::vector x(nof_points);
    61       gslapi::vector y(nof_points);
     66     
     67     
     68      gslapi::vector x(x_total, min_index, nof_points);
     69      //for (size_t j=0; j<x.size(); j++)
     70      //  x(j)=data_[min_index+j].first;
     71
     72      gslapi::vector y(y_total, min_index, nof_points);
     73      //for (size_t j=0; j<y.size(); j++){
     74      //  y(j)=data_[min_index+j].second;
     75      //}
     76
     77      // calculating weights
    6278      gslapi::vector w(nof_points);
    63       for (size_t j=0; j<x.size(); j++)
    64         x(j)=data_[min_index+j].first;
    65       for (size_t j=0; j<y.size(); j++){
    66         y(j)=data_[min_index+j].second;
    67       }
    68       // calculating weights
    6979      for (size_t j=0; j<y.size(); j++)
    7080        w(j) = kernel_->weight( (x(j)-(data_[min_index].first+
  • trunk/src/RegressionLocal.h

    r253 r280  
    1919 
    2020  ///
    21   /// Class for Locally-weighted regression. 
     21  /// Class for Locally weighted regression.
    2222  ///
     23  /// Locally weighted regression is an algorithm for learning
     24  /// continuous non-linear mappings in a non-parametric manner.  In
     25  /// locally weighted regression, points are weighted by proximity to
     26  /// the current x in question using a RegressionKernel. A weighted
     27  /// regression is then computed using the weighted points and a
     28  /// specific Regression method. This procedure is repeated, which
     29  /// results in a pointwise approximation of the underlying (unknown)
     30  /// function.
     31  ///
     32
     33
    2334 
    2435  class RegressionLocal
     
    7081 
    7182    ///
    72     /// Performs the fit in data defined by add using a kernel and a
    73     /// regression method defined in the constructor. The algorithm
    74     /// selects boundaries for the kernel such that \a fraction of the
    75     /// data points are used and the point where the fit is done is in
    76     /// the middle. Starting with the smallest x, the function jumps
    77     /// \a step_size point in each iteration to do the next
    78     /// fit. Result is sent to ostream \a s.
     83    /// Performs the fit in data defined by add using a
     84    /// RegressionKernel and a Regression method defined in the
     85    /// constructor. The function starts by regressing over the lowest
     86    /// x value, followed by stepping forward \a step_size number of
     87    /// points, et cetera. The kernel is centralized over the x-value
     88    /// in question and the width is set so \a fraction of all points
     89    /// are used. The result is sent to ostream \a s, using print
     90    /// function in used Regression.
    7991    ///
    8092    void fit(std::ostream& s, const double fraction, const u_int step_size=1);
     
    8597  private:
    8698    std::vector<std::pair<double, double> > data_;
    87     gslapi::vector data_y_;
    8899    RegressionKernel* kernel_;
    89100    Regression* regressor_;
Note: See TracChangeset for help on using the changeset viewer.