Changeset 495

Ignore:
Timestamp:
Jan 11, 2006, 6:27:22 PM (17 years ago)
Message:

modified interface for Regression::Local

Location:
trunk
Files:
8 edited

Unmodified
Removed
• trunk/lib/statistics/LinearWeighted.cc

 r489 alpha_ = m_y; beta_ = sxy/sxx; alpha_var_ = s2_/w.sum(); alpha_var_ = ap.y_averager().standard_error() * ap.y_averager().standard_error(); beta_var_ = s2_/sxx; m_x_=m_x;
• trunk/lib/statistics/LinearWeighted.h

 r430 /// /// Function predicting value using the linear model. \a y_err is /// the expected deviation from the line for a new data point. If /// weights are used a weight can be specified for the new point. /// the estimated error of y(x) /// inline void predict(const double x, double& y, double& y_err, { y = alpha_ + beta_ * (x-m_x_); y_err_ = y_err = sqrt( alpha_var_+beta_var_*(x-m_x_)*(x-m_x_)+s2_/w ); y_err_ = y_err = sqrt( alpha_var_+beta_var_*(x-m_x_)*(x-m_x_)); x_=x; y_=y;
• trunk/lib/statistics/Local.cc

 r430 void Local::fit(const double width, const gslapi::vector& points) void Local::fit(const size_t step_size, const size_t nof_points) { // Peter, avoid this copying x_=points; y_predicted_ = gslapi::vector(points.size()); y_err_ = gslapi::vector(points.size()); if (step_size==0 || nof_points<3){ // Peter to Jari, throw exception? std::cerr << "theplu::statistics::regression::Local " << "Parameters invalid. Fitting ignored." << std::endl; return; } size_t nof_fits=data_.size()/step_size; x_= gslapi::vector(nof_fits); y_predicted_ = gslapi::vector(x_.size()); y_err_ = gslapi::vector(x_.size()); sort(data_.begin(), data_.end()); gslapi::vector x(data_.size()); gslapi::vector y(data_.size()); for (size_t j=0; j( (i+0.5)*step_size ); size_t min_index; double width; // distance from middle of windo to border of window double x_mid; // middle of window // right border case if (max_index > data_.size()-1){ min_index = max_index - nof_points + 1; max_index = data_.size()-1; width = ( (( x(max_index)-x(0) )*(nof_points-1)) / ( 2*(max_index-min_index)) ); x_mid = x(min_index)+width; } // normal middle case else if (max_index > nof_points-1){ min_index = max_index - nof_points + 1; width = (x(max_index)-x(min_index))/2; x_mid = x(min_index)+width; } // left border case else { min_index = 0; width = ( (( x(max_index)-x(0) )*(nof_points-1)) / ( 2*(max_index-min_index)) ); x_mid = x(max_index)-width; } assert(min_indexweight( (x_local(j)- x(i))/width ); for (size_t j=0; jweight( (x_local(j)- x_mid)/width ); // fitting the regressor locally regressor_->fit(x_local,y_local,w); regressor_->predict(x(i), y_predicted_(i),y_err_(i)); assert(ipredict(x(i*step_size), y_predicted_(i),y_err_(i)); } }
• trunk/lib/statistics/Local.h

 r430 /// /// Performs the fit in data defined by add using a /// RegressionKernel and a Regression method defined in the /// constructor. For each element in vector \a x a fit is /// performed. The kernel used has width \a width and is /// centralized over the data point \f\$ x_i \f\$, which means data /// in \f\$ [x-width, x+width] is used in the fit. /// @todo doc /// @param nof_points Number of points used in each fit /// @param step_size Size of step between each fit /// void fit(const double width, const gslapi::vector& x); void fit(const size_t step_size, const size_t nof_points); ///
• trunk/lib/statistics/NaiveWeighted.cc

 r429 x_ = x; y = m_; y_err = sqrt(m_err_*m_err_ + s2_/w); y_err = m_err_; }
• trunk/lib/statistics/NaiveWeighted.h

 r429 /// /// Function predicting value using the naive model. \a y_err is /// the expected deviation from the line for a new data point. The /// weight for the new point can be specified. A smaller weight /// means larger error. The error has two components: the variance /// of point and error in estimation of m_. /// Function predicting value using the naive model, i.e. a /// weighted average. \a y_err is the standard error of the /// weighted mean /// /// @see AveragerWeighted::standard_error /// void predict(const double x, double& y, double& y_err,
• trunk/lib/statistics/OneDimensionalWeighted.h

 r429 const gslapi::vector& w)=0; /// /// function predicting in one point /// function predicting in one point. y will contain the y(x) /// according to the model. y_err will contain the estimated error /// of y(x). /// virtual void predict(const double x, double& y, double& y_err,
• trunk/test/regression_test.cc

 r489 { statistics::regression::Local rl(r,k); gslapi::vector points(1000); for (size_t i=0; i<1000; i++){ rl.add(i, 10); points(i)=i; } rl.fit(100, points); rl.fit(10, 100); gslapi::vector y = rl.y_predicted();
Note: See TracChangeset for help on using the changeset viewer.