Changeset 2809 for trunk/yat/statistics/Averager.h
 Timestamp:
 Aug 6, 2012, 3:44:47 PM (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/statistics/Averager.h
r2790 r2809 26 26 */ 27 27 28 #include "averager_base.h" 29 28 30 #include "yat/utility/iterator_traits.h" 29 31 … … 41 43 /// @see AveragerWeighted AveragerPair AveragerPairWeighted 42 44 /// 43 class Averager 45 class Averager : public averager_base2<Averager> 44 46 { 45 47 public: … … 49 51 /// 50 52 Averager(void); 51 53 52 54 /// 53 55 /// Constructor taking sum of \a x, sum of squared x, \a xx, and … … 62 64 63 65 /// 64 /// Adding \a n (default=1) number of data point(s) with value \a d.65 ///66 void add(double d, long n=1);67 68 /**69 @brief Coeffient of variation70 71 Coeffient of variation (cv) is defined as ratio between the72 standard deviation and the mean: \f$ \frac{\sigma}{\mu} \f$.73 74 @return standard deviation divided by mean.75 */76 double cv(void) const;77 78 ///79 /// @return %Mean of presented data, \f$ \frac{1}{n}\sum x_i \f$80 ///81 double mean(void) const;82 83 ///84 /// @return Number of data points85 ///86 long n(void) const;87 88 ///89 /// @brief Rescales the object90 ///91 /// \f$ \forall x_i \rightarrow a*x_i \f$,92 ///93 void rescale(double a);94 95 ///96 /// @return Standard error, i.e. standard deviation of the mean97 /// \f$ \sqrt{variance()/n} \f$98 ///99 double standard_error(void) const;100 101 ///102 /// @brief The standard deviation is defined as the square root of103 /// the variance.104 ///105 /// @return The standard deviation, root of the variance().106 ///107 double std(void) const;108 109 ///110 /// @brief The standard deviation is defined as the square root of111 /// the variance.112 ///113 /// @return Standard deviation around \a m, root of the variance(m).114 ///115 double std(double m) const;116 117 ///118 /// @return The sum of x119 ///120 double sum_x(void) const;121 122 ///123 /// @return The sum of squares124 ///125 double sum_xx(void) const;126 127 ///128 /// @return \f$ \sum_i (x_im)^2 \f$129 ///130 double sum_xx_centered(void) const;131 132 ///133 /// @brief The variance with know mean134 ///135 /// The variance is calculated as136 /// \f$ \frac{1}{n}\sum (x_im)^2 \f$.137 ///138 /// @return Variance when the mean is known to be \a m.139 ///140 double variance(double m) const;141 142 /**143 \brief The estimated variance144 145 The variance is calculated as \f$ \frac{1}{N}\sum_i146 (x_im)^2 \f$, where \f$ m \f$ is the mean.147 148 \return Estimation of variance149 */150 double variance(void) const;151 152 ///153 /// The variance is calculated using the \f$ (n1) \f$ correction,154 /// which means it is the best unbiased estimator of the variance155 /// \f$ \frac{1}{N1}\sum_i (x_im)^2 \f$, where \f$ m \f$ is the156 /// mean.157 ///158 /// @return unbiased estimation of variance159 ///160 double variance_unbiased(void) const;161 162 ///163 /// @brief Reset everything to zero164 ///165 void reset(void);166 167 ///168 66 /// @brief The assignment operator 169 67 /// 170 68 const Averager& operator=(const Averager&); 171 69 172 /// 173 /// Operator to add another Averager 174 /// 175 const Averager& operator+=(const Averager&); 70 /** 71 \brief plus assignment operator 72 73 Add another Averager 74 */ 75 template<class Derived> 76 const Averager& operator+=(const averager_base2<Derived>& other); 176 77 177 78 private: 178 long n_; 179 double mean_, m2_; 79 friend class averager_base<Averager>; 80 void add_impl(double, long int); 81 void rescale_impl(double); 180 82 }; 181 83 182 84 183 85 /** … … 195 97 } 196 98 99 // template implementation 100 template<class Derived> 101 const Averager& Averager::operator+=(const averager_base2<Derived>& other) 102 { 103 if (other.n()) 104 add2(other.mean(), other.sum_xx_centered(), other.n()); 105 return *this; 106 } 107 108 197 109 }}} // of namespace statistics, yat, and theplu 198 110
Note: See TracChangeset
for help on using the changeset viewer.