Changeset 483


Ignore:
Timestamp:
Jan 3, 2006, 11:23:42 AM (16 years ago)
Author:
Peter
Message:

Went through averager class. Changed function to be sum_xx and
sum_xx_centered to be in line with the rest of averagers. Also added
different kinds of the variance estimators e.g. when the mean is
known.

Location:
trunk/lib/statistics
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/statistics/Averager.h

    r433 r483  
    5858 
    5959    ///
    60     /// @return Mean of squared values \f$ \frac{1}{n}\sum x_i^2 \f$.
    61     ///
    62     inline double mean_sqr(void) const { return n_ ? xx_/n_ : 0; }
    63 
    64     ///
    6560    /// @return Number of data points
    6661    ///
     
    7469
    7570    ///
    76     /// Resets everything to zero
     71    /// @return Standard error, i.e. standard deviation of the mean
     72    /// \f$ \sqrt{variance()/n} \f$
    7773    ///
    78     inline void reset(void) { n_=0; x_=xx_=0.0;}
     74    inline double standard_error(void) const { return sqrt(variance()/n_); }
    7975
    8076    ///
     
    8783
    8884    ///
    89     /// @return Standard error, i.e. standard deviation of the mean
    90     /// \f$ \sqrt{variance()/n} \f$
     85    /// The standard deviation is defined as the square root of the
     86    /// variance.
    9187    ///
    92     inline double standard_error(void) const { return sqrt(variance()/n_); }
     88    /// @return Standard deviation around \a m, root of the variance(m).
     89    ///
     90    inline double std(const double m) const { return sqrt(variance(m)); }
    9391
    9492    ///
     
    10098    /// @return The sum of squares
    10199    ///
    102     inline double sum_xsqr(void) const { return xx_; }
     100    inline double sum_xx(void) const { return xx_; }
    103101
    104102    ///
    105103    /// @return \f$ \sum_i (x_i-m)^2\f$
    106104    ///
    107     inline double sum_xsqr_centered(void) const { return xx_-x_*x_/n_; }
     105    inline double sum_xx_centered(void) const { return xx_-x_*x_/n_; }
     106
     107    ///
     108    /// \f$ \frac{1}{n}\sum (x_i-m)^2 \f$.
     109    ///
     110    /// @return Variance when the mean is known to be \a m.
     111    ///
     112    inline double variance(const double m) const
     113    { return n_ ? (xx_ - 2*m*x_ + m*m) /n_ : 0; }
     114
     115    ///
     116    /// The variance is calculated as \f$ \frac{1}{N}\sum_i
     117    /// (x_i-m)^2\f$, where \f$m\f$ is the mean.
     118    ///
     119    /// @return estimation of variance
     120    ///
     121    inline double variance(void) const
     122    { return n_ ? sum_xx_centered()/n_ : 0; }
    108123
    109124    ///
     
    113128    /// mean.
    114129    ///
    115     /// @return The variance
     130    /// @return unbiased estimation of variance
    116131    ///
    117     inline double variance(void) const
    118     { return (n_>1) ? sum_xsqr_centered()/(n_-1) : 0; }
     132    inline double variance_unbiased(void) const
     133    { return (n_>1) ? sum_xx_centered()/(n_-1) : 0; }
     134
     135    ///
     136    /// Resets everything to zero
     137    ///
     138    inline void reset(void) { n_=0; x_=xx_=0.0;}
    119139
    120140    ///
  • trunk/lib/statistics/AveragerPair.h

    r475 r483  
    2828    /// number of pair of values \a n
    2929    ///
    30     inline AveragerPair(const double x, const double xx, const double y,
    31                         const double yy, const double xy, const unsigned long n)
    32       : x_(Averager(x,xx,n)), y_(Averager(y,yy,n)), xy_(xy) {}
     30    //inline AveragerPair(const double x, const double xx, const double y,
     31    //                    const double yy, const double xy, const unsigned long n)
     32    //  : x_(Averager(x,xx,n)), y_(Averager(y,yy,n)), xy_(xy) {}
    3333
    3434    ///
     
    8686    /// \frac{1}{N} \sum (x-y)^2 \f$
    8787    ///
    88     inline double msd() const {return x_.mean_sqr()+y_.mean_sqr()-2*mean_xy();}
     88    // Peter, fix this
     89    //    inline double msd() const {return x_.mean_sqr()+y_.mean_sqr()-2*mean_xy();}
    8990
    9091    ///
  • trunk/lib/statistics/AveragerWeighted.h

    r476 r483  
    123123
    124124    inline double sum_ww(void)  const
    125     { return w_.sum_xsqr(); }
     125    { return w_.sum_xx(); }
    126126
    127127    ///
     
    129129    ///
    130130    inline double sum_wwxx(void)  const
    131     { return wx_.sum_xsqr(); }
     131    { return wx_.sum_xx(); }
    132132   
    133133    ///
  • trunk/lib/statistics/Linear.cc

    r430 r483  
    2525    // estimating the noise level, i.e. the conditional variance of y
    2626    // given x, Var(y|x).
    27     double Q = (ap_.y_averager().sum_xsqr_centered() - ap_.sum_xy_centered() *
    28                 ap_.sum_xy_centered()/ap_.x_averager().sum_xsqr_centered() ) ;
     27    double Q = (ap_.y_averager().sum_xx_centered() - ap_.sum_xy_centered() *
     28                ap_.sum_xy_centered()/ap_.x_averager().sum_xx_centered() ) ;
    2929    s2_ = Q/(x.size()-2);
    3030    r2_= 1;
    3131    alpha_var_ = s2_ / x.size();
    32     beta_var_ = s2_ / ap_.x_averager().sum_xsqr_centered();
     32    beta_var_ = s2_ / ap_.x_averager().sum_xx_centered();
    3333    m_x_ = ap_.x_averager().mean();
    3434  }
  • trunk/lib/statistics/tScore.cc

    r475 r483  
    3232    }
    3333    double diff = positive.mean() - negative.mean();
    34     double s=sqrt((positive.sum_xsqr()+negative.sum_xsqr())
     34    double s=sqrt((positive.sum_xx()+negative.sum_xx())
    3535                  /(positive.n()+negative.n()-2));
    3636    t_=diff/s/(1.0/positive.n()+1.0/negative.n());
Note: See TracChangeset for help on using the changeset viewer.