Changeset 489

Ignore:
Timestamp:
Jan 4, 2006, 8:42:00 PM (16 years ago)
Message:

added functions to AveragerPairWeighted?. Not tested yet.

Location:
trunk
Files:
7 edited
1 moved

Unmodified
Removed
• trunk/doc/Makefile.am

 r320 ## $Id$ all-local: doxygen doxygen.config all-local: doxygen-local Statistics clean-local: distclean-local: clean-local doxygen-local: doxygen doxygen.config Statistics: Statistics.tex latex2html Statistics.tex
• trunk/lib/statistics/Averager.h

 r484 /// Class to calculate simple (first and second moments) averages. /// /// @see AveragerWeighted /// @see Averager AveragerPair AveragerPairWeighted /// class Averager
• trunk/lib/statistics/AveragerPair.h

 r487 /// /// Class for taking care of mean and covariance of two variables. /// /// @see Averager AveragerPair AveragerPairWeighted /// class AveragerPair
• trunk/lib/statistics/AveragerPairWeighted.h

 r476 /// a weighted manner. /// /// Weighted Statistics document /// /// If nothing else stated, each function fulfills the /// following:
• Setting a weight to zero corresponds to /// removing the data point from the dataset.
• Setting all /// weights to unity, the yields the same result as from /// corresponding function in AveragerPair.
• Rescaling weights /// does not change the performance of the object.
/// /// @see Averager AveragerPair AveragerPairWeighted /// class AveragerPairWeighted { /// /// Adding a pair of data points with value \a x and \a y, and /// their weights. /// their weights. If either of the weights are zero the addition /// is ignored /// void  add(const double x, const double y, /// /// Adding vectors /// Adding pair of data and corresponding weight in vectors /// void add(const gslapi::vector& x, /// /// @return Pearson correlation coefficient. /// @brief Pearson correlation coefficient. /// /// @return \f$\frac{\sum w_xw_y (x-m_x)(y-m_y)}{\sqrt{\sum /// w_xw_y (y-m_y)^2\sum w_xw_y (y-m_y)^2}} \f$ where m is /// calculated as \f$m_x = \frac {\sum w_xw_yx}{\sum w} \f$ /// inline double correlation(void) const { return (wxy_/w_ - x_.mean()*y_.mean() )/ sqrt(x_.variance()*y_.variance()); } { return covariance() / ( x_.std()*y_.std() ); } /// /// @reset /// \f$\frac{\sum w_xw_y (x-m_x)(y-m_y)}{\sum w_xw_y} \f$ where m /// is calculated as \f$m_x = \frac {\sum w_xw_yx}{\sum w} \f$ /// inline double covariance(void) const { return sum_xy_centered()/sum_w(); } /// /// reset everything to zero /// inline void reset(void) { x_.reset(); y_.reset(); wxy_=0; w_=0; } /// /// @return \f$\sum w_xw_y \f$ /// inline double sum_w(void) const { return w_; } /// /// @return \f$\sum w_xw_yxy \f$ /// inline double sum_xy(void) const { return wxy_; } /// /// @return \f$\sum w_xw_y (x-m_x)(y-m_y) \f$ where m is calculated as /// \f$m_x = \frac {\sum w_xw_yx}{\sum w} \f$ /// inline double sum_xy_centered(void) const { return sum_xy() - x_.sum_wx()*y_.mean(); } /// /// @note the weights are calculated as \f$w = w_x * w_y \f$ /// /// @return AveragerWeighted for x /// inline const AveragerWeighted& x_averager(void) const { return x_; } /// /// @note the weights are calculated as \f$w = w_x * w_y \f$ /// /// @return AveragerWeighted for y /// inline const AveragerWeighted& y_averager(void) const { return y_; } private: AveragerWeighted x_; AveragerWeighted y_; AveragerWeighted x_; // weighted averager with w = w_x*w_y AveragerWeighted y_; // weighted averager with w = w_x*w_y double wxy_; double w_;
• trunk/lib/statistics/AveragerWeighted.h

 r486 /// /// \f$\sum w_ix_i \f$ /// /// @return weighted sum of x /// inline double sum_wx(void)  const { return wx_.sum_x(); } /// /// @return \f$\sum_i w_i (x_i-m)^2\f$ /// private: /// /// \f$\sum w_ix_i \f$ @return weighted sum of x /// inline double sum_wx(void)  const { return wx_.sum_x(); } inline double sum_ww(void)  const { return w_.sum_xx(); }
• trunk/lib/statistics/LinearWeighted.cc

 r429 #include #include #include #include const gslapi::vector& w) { double m_x = w*x /w.sum(); double m_y = w*y /w.sum(); // AveragerPairWeighted requires 2 weights but works only on the // product wx*wy, so we can send in w and a dummie to get what we // want. gslapi::vector dummie(w.size(),1); AveragerPairWeighted ap; ap.add(x,y,w,dummie); double m_x = ap.x_averager().mean(); double m_y = ap.y_averager().mean(); double sxy = 0; for (size_t i=0; i
• trunk/test/regression_test.cc

 r430 double y_predicted_err=0; linear_w.predict(1990,y_predicted,y_predicted_err); if (y_predicted!=12.8){ *error << "regression_LinearWeighted: cannot reproduce fit." << std::endl; if (fabs(y_predicted-12.8)>0.001){ *error << "error: cannot reproduce fit." << std::endl; *error << "predicted value: " << y_predicted << " expected 12.8" << std::endl; ok=false; }
Note: See TracChangeset for help on using the changeset viewer.