Changeset 703 for trunk/yat/statistics
- Timestamp:
- Dec 18, 2006, 1:47:44 AM (17 years ago)
- Location:
- trunk/yat/statistics
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/statistics/Averager.cc
r680 r703 43 43 } 44 44 45 void Averager::add(double d, u_long n) 46 { 47 n_ += n; 48 x_ += n*d; 49 xx_ += n*d*d; 50 } 51 52 void Averager::rescale(double a) 53 { 54 x_ *= a; 55 xx_ *= a*a; 56 } 57 58 void Averager::reset(void) 59 { 60 n_=0; 61 x_=xx_=0.0; 62 } 63 64 const Averager& Averager::operator=(const Averager& a) 65 { 66 n_ = a.n_; 67 x_ = a.x_; 68 xx_ = a.xx_; 69 return *this; 70 } 71 45 72 const Averager& Averager::operator+=(const Averager& a) 46 73 { -
trunk/yat/statistics/Averager.h
r680 r703 62 62 /// Adding \a n (default=1) number of data point(s) with value \a d. 63 63 /// 64 inline void add(double d, u_long n=1) { n_+=n; x_+=n*d; xx_+=n*d*d;}64 void add(double d, u_long n=1); 65 65 66 66 /// … … 95 95 96 96 /// 97 /// Rescales the object, \f$ \forall x_i \rightarrow a*x_i \f$, 97 /// @brief Rescales the object 98 /// 99 /// \f$ \forall x_i \rightarrow a*x_i \f$, 98 100 /// \f$ \forall x_i^2 \rightarrow a^2*x_i^2 \f$ 99 101 /// 100 inline void rescale(double a) { x_*=a; xx_*=a*a; }102 inline void rescale(double a); 101 103 102 104 /// … … 107 109 108 110 /// 109 /// The standard deviation is defined as the square root of the110 /// variance.111 /// @brief The standard deviation is defined as the square root of 112 /// the variance. 111 113 /// 112 114 /// @return The standard deviation, root of the variance(). … … 115 117 116 118 /// 117 /// The standard deviation is defined as the square root of the118 /// variance.119 /// @brief The standard deviation is defined as the square root of 120 /// the variance. 119 121 /// 120 122 /// @return Standard deviation around \a m, root of the variance(m). … … 138 140 139 141 /// 142 /// @brief The variance with know mean 143 /// 144 /// The variance is calculated as 140 145 /// \f$ \frac{1}{n}\sum (x_i-m)^2 \f$. 141 146 /// … … 146 151 147 152 /// 153 /// @brief The estimated variance 154 /// 148 155 /// The variance is calculated as \f$ \frac{1}{N}\sum_i 149 156 /// (x_i-m)^2 \f$, where \f$ m \f$ is the mean. 150 157 /// 151 /// @return estimation of variance158 /// @return Estimation of variance 152 159 /// 153 160 inline double variance(void) const … … 166 173 167 174 /// 168 /// Resets everything to zero 169 /// 170 inline void reset(void) { n_=0; x_=xx_=0.0;} 171 172 /// 173 /// The assignment operator 174 /// 175 inline const Averager& operator=(const Averager& a) 176 { n_=a.n_; x_=a.x_; xx_=a.xx_; return *this; } 175 /// @brief Reset everything to zero 176 /// 177 void reset(void); 178 179 /// 180 /// @brief The assignment operator 181 /// 182 const Averager& operator=(const Averager&); 177 183 178 184 /// -
trunk/yat/statistics/AveragerPair.cc
r683 r703 31 31 namespace yat { 32 32 namespace statistics { 33 33 34 AveragerPair::AveragerPair(void) 35 : x_(Averager()), y_(Averager()), xy_(0.0) 36 { 37 } 38 39 AveragerPair::AveragerPair(const AveragerPair& a) 40 : x_(a.x_averager()), y_(a.y_averager()), xy_(a.sum_xy()) 41 { 42 } 43 44 void AveragerPair::add(const double x, const double y, const unsigned long n) 45 { 46 x_.add(x,n); y_.add(y,n); xy_ += n*x*y; 47 } 48 49 void AveragerPair::reset(void) 50 { 51 x_.reset(); y_.reset(); xy_=0.0; 52 } 53 54 const AveragerPair& AveragerPair::operator=(const AveragerPair& a) 55 { 56 x_=a.x_; y_=a.y_; xy_=a.xy_; 57 return *this; 58 } 59 34 60 const AveragerPair& AveragerPair::operator+=(const AveragerPair& a) 35 61 { -
trunk/yat/statistics/AveragerPair.h
r680 r703 45 45 46 46 /// 47 /// Default constructor47 /// @brief The default constructor 48 48 /// 49 inline AveragerPair(void) : x_(Averager()), y_(Averager()), xy_(0.0) {}50 49 AveragerPair(void); 50 51 51 /// 52 52 /// Constructor taking sum of \a x , \a xx , \a y , \a yy , xy and … … 58 58 59 59 /// 60 /// Copy constructor60 /// The copy constructor 61 61 /// 62 inline AveragerPair(const AveragerPair& a) 63 : x_(a.x_averager()), y_(a.y_averager()), xy_(a.sum_xy()) {} 64 62 AveragerPair(const AveragerPair&); 63 65 64 /// 66 65 /// Adding \a n pairs of data points with value \a x and \a y. 67 66 /// 68 inline void add(const double x, const double y, const unsigned long n=1) 69 { x_.add(x,n); y_.add(y,n), xy_ += n*x*y; } 67 void add(const double x, const double y, const unsigned long n=1); 70 68 71 69 /// … … 131 129 132 130 /// 133 /// Resetseverything to zero131 /// @brief Reset everything to zero 134 132 /// 135 inline void reset(void) { x_.reset(); y_.reset(); xy_=0.0; }133 void reset(void); 136 134 137 135 /// … … 156 154 157 155 /// 158 /// The assigment operator156 /// @brief The assigment operator 159 157 /// 160 inline const AveragerPair& operator=(const AveragerPair& a) 161 { x_=a.x_; y_=a.y_; xy_=a.xy_; return *this; } 158 const AveragerPair& operator=(const AveragerPair& a); 162 159 163 160 /// -
trunk/yat/statistics/AveragerPairWeighted.cc
r701 r703 31 31 namespace yat { 32 32 namespace statistics { 33 33 34 35 AveragerPairWeighted::AveragerPairWeighted(void) 36 : wxy_(0), w_(0) 37 { 38 } 39 34 40 35 41 void AveragerPairWeighted::add(const double x, const double y, … … 64 70 } 65 71 72 73 void AveragerPairWeighted::reset(void) 74 { 75 x_.reset(); y_.reset(); wxy_=0; w_=0; 76 } 77 66 78 }}} // of namespace statistics, yat, and theplu -
trunk/yat/statistics/AveragerPairWeighted.h
r683 r703 55 55 public: 56 56 57 AveragerPairWeighted()58 : wxy_(0), w_(0)59 {60 }57 /// 58 /// @brief The default constructor 59 /// 60 AveragerPairWeighted(void); 61 61 62 62 /// … … 122 122 123 123 /// 124 /// reset everything to zero124 /// @brief Reset everything to zero 125 125 /// 126 inline void reset(void) { x_.reset(); y_.reset(); wxy_=0; w_=0; }126 void reset(void); 127 127 128 128 /// -
trunk/yat/statistics/AveragerWeighted.cc
r683 r703 28 28 namespace statistics { 29 29 30 AveragerWeighted AveragerWeighted::operator+=(const AveragerWeighted& a) 30 AveragerWeighted::AveragerWeighted(void) 31 : w_(Averager()), wx_(Averager()), wwx_(0), wxx_(0) 32 { 33 } 34 35 AveragerWeighted::AveragerWeighted(const AveragerWeighted& a) 36 : w_(Averager(a.sum_w(),a.sum_ww(),1)), 37 wx_(Averager(a.sum_wx(),a.sum_wwxx(),1)), 38 wwx_(a.sum_wwx()), 39 wxx_(a.sum_wxx()) 40 { 41 } 42 43 void AveragerWeighted::add(const double d, const double w) 44 { 45 if (!w) 46 return; 47 w_.add(w); wx_.add(w*d); wwx_+=w*w*d; wxx_+=w*d*d; 48 } 49 50 void AveragerWeighted::rescale(double a) 51 { 52 wx_.rescale(a); 53 wwx_*=a; 54 wxx_*=a*a; 55 } 56 57 void AveragerWeighted::reset(void) 58 { 59 wx_.reset(); w_.reset(); wwx_=0; wxx_=0; 60 } 61 62 const AveragerWeighted& AveragerWeighted::operator+=(const AveragerWeighted& a) 31 63 { 32 64 wx_+=a.wx(); w_+=a.w(); wwx_+=a.sum_wwx(); wxx_+=a.sum_wxx(); -
trunk/yat/statistics/AveragerWeighted.h
r699 r703 65 65 66 66 /// 67 /// Default constructor67 /// @brief The default constructor 68 68 /// 69 inline AveragerWeighted(void) 70 : w_(Averager()), wx_(Averager()), wwx_(0), wxx_(0) {} 71 72 /// 73 /// Copy constructor 74 /// 75 inline AveragerWeighted(const AveragerWeighted& a) 76 : w_(Averager(a.sum_w(),a.sum_ww(),1)), 77 wx_(Averager(a.sum_wx(),a.sum_wwxx(),1)), wwx_(a.sum_wwx()), 78 wxx_(a.sum_wxx()) {} 79 80 /// 81 /// adding a data point d, with weight w (default is 1) 82 /// 83 inline void add(const double d,const double w=1) 84 { if(w==0) return; w_.add(w); wx_.add(w*d); wwx_+=w*w*d; wxx_+=w*d*d; } 69 AveragerWeighted(void); 70 71 /// 72 /// @brief The copy constructor 73 /// 74 AveragerWeighted(const AveragerWeighted&); 75 76 /// 77 /// Adding a data point \a d, with weight \a w (default is 1) 78 /// 79 void add(const double d,const double w=1); 85 80 86 81 /// … … 96 91 97 92 /// 98 /// Calculatingthe weighted mean93 /// @brief Calculate the weighted mean 99 94 /// 100 95 /// @return \f$ \frac{\sum w_ix_i}{\sum w_i} \f$ 101 96 /// 102 inline double mean(void) const { return sum_w() ? 103 sum_wx()/sum_w() : 0; } 97 inline double mean(void) const { return sum_w() ? sum_wx()/sum_w() : 0; } 104 98 105 99 /// … … 117 111 118 112 /// 119 /// rescale object, i.e. each data point is rescaled 120 /// \f$ x = a * x \f$ 121 /// 122 inline void rescale(double a) { wx_.rescale(a); wwx_*=a; wxx_*=a*a; } 123 124 /// 125 /// resets everything to zero 126 /// 127 inline void reset(void) { wx_.reset(); w_.reset(); wwx_=0; wxx_=0; } 128 129 /// 130 /// The standard deviation is defined as the square root of the 131 /// variance(). 113 /// @brief Rescale object. 114 /// 115 /// Each data point is rescaled as \f$ x = a * x \f$ 116 /// 117 void rescale(double a); 118 119 /// 120 /// @brief Reset everything to zero. 121 /// 122 void reset(void); 123 124 /// 125 /// @brief The standard deviation is defined as the square root of 126 /// the variance(). 132 127 /// 133 128 /// @return The standard deviation, root of the variance(). … … 136 131 137 132 /// 138 /// Calculates standard deviation of the mean(). Variance from the 133 /// @brief Calculates standard deviation of the mean(). 134 /// 135 /// Variance from the 139 136 /// weights are here neglected. This is true when the weight is 140 137 /// known before the measurement. In case this is not a good … … 219 216 /// operator to add a AveragerWeighted 220 217 /// 221 AveragerWeightedoperator+=(const AveragerWeighted&);218 const AveragerWeighted& operator+=(const AveragerWeighted&); 222 219 223 220 Averager w_; … … 226 223 double wxx_; 227 224 228 inline Averager wx(void) const {return wx_;} 229 inline Averager w(void) const {return w_;} 230 231 225 inline Averager wx(void) const { return wx_; } 226 inline Averager w(void) const { return w_; } 232 227 }; 233 228 -
trunk/yat/statistics/Distance.cc
r683 r703 31 31 namespace statistics{ 32 32 33 double Distance::operator()(const classifier::DataLookup1D& x, 33 Distance::Distance(void) 34 { 35 } 36 37 Distance::~Distance(void) 38 { 39 } 40 41 double Distance::operator()(const classifier::DataLookup1D& x, 34 42 const classifier::DataLookup1D& y) const 35 43 { -
trunk/yat/statistics/Distance.h
r683 r703 44 44 public: 45 45 46 Distance() 47 { 48 } 46 /// 47 /// @brief The default constructor 48 /// 49 Distance(void); 49 50 50 virtual ~Distance() 51 { 52 } 51 /// 52 /// @brief The destructor 53 /// 54 virtual ~Distance(void); 53 55 54 56 /// -
trunk/yat/statistics/Pearson.cc
r683 r703 38 38 Pearson::Pearson(bool b) 39 39 : Score(b), r_(0), nof_samples_(0) 40 { 41 } 42 43 Pearson::~Pearson(void) 40 44 { 41 45 } -
trunk/yat/statistics/Pearson.h
r683 r703 43 43 class Pearson : public Score 44 44 { 45 46 45 public: 47 46 /// 48 /// Default Constructor.47 /// @brief The default constructor. 49 48 /// 50 49 Pearson(bool absolute=true); 51 50 52 51 /// 53 /// Destructor52 /// @brief The destructor. 54 53 /// 55 virtual ~Pearson(void) {};54 virtual ~Pearson(void); 56 55 57 56 -
trunk/yat/statistics/PearsonDistance.cc
r683 r703 31 31 namespace statistics{ 32 32 33 PearsonDistance::PearsonDistance(void) 34 : Distance() 35 { 36 } 37 38 PearsonDistance::~PearsonDistance(void) 39 { 40 } 41 33 42 double PearsonDistance::operator()(const utility::vector& x, 34 43 const utility::vector& y) const -
trunk/yat/statistics/PearsonDistance.h
r683 r703 47 47 public: 48 48 49 PearsonDistance() 50 : Distance() 51 { 52 } 49 PearsonDistance(void); 53 50 54 virtual ~PearsonDistance() 55 { 56 } 57 51 virtual ~PearsonDistance(void); 52 58 53 // Use all operator() from Distance except the ones that are 59 54 // overloaded in this class. … … 68 63 const utility::vector& wx, 69 64 const utility::vector& wy) const; 70 71 private:72 65 }; 73 66 -
trunk/yat/statistics/ROC.cc
r683 r703 39 39 ROC::ROC(bool b) 40 40 : Score(b), area_(0.5), minimum_size_(10), nof_pos_(0) 41 { 42 } 43 44 ROC::~ROC(void) 41 45 { 42 46 } -
trunk/yat/statistics/ROC.h
r683 r703 50 50 public: 51 51 /// 52 /// Default constructor52 /// @brief Default constructor 53 53 /// 54 54 ROC(bool absolute=true); 55 55 56 56 /// 57 /// Destructor57 /// @brief The destructor 58 58 /// 59 virtual ~ROC(void) {};59 virtual ~ROC(void); 60 60 61 61 /// Function taking \a value, \a target (+1 or -1) and vector -
trunk/yat/statistics/SNR.h
r683 r703 54 54 public: 55 55 /// 56 /// Default Constructor.56 /// @brief Default Constructor. 57 57 /// 58 58 SNR(bool absolute=true); -
trunk/yat/statistics/Score.cc
r683 r703 33 33 } 34 34 35 Score::~Score(void) 36 { 37 } 38 39 double Score::score(const classifier::Target& target, 40 const classifier::DataLookup1D& value) 41 { 42 assert(target.size()==value.size()); 43 utility::vector a; 44 classifier::convert(value,a); 45 return score(target,a); 46 } 47 48 double Score::score(const classifier::Target& target, 49 const classifier::DataLookup1D& value, 50 const classifier::DataLookup1D& weight) 51 { 52 utility::vector a; 53 classifier::convert(value,a); 54 utility::vector b; 55 classifier::convert(weight,a); 56 return score(target,a,b); 57 } 58 35 59 }}} // of namespace statistics, yat, and theplu -
trunk/yat/statistics/Score.h
r683 r703 52 52 public: 53 53 /// 54 /// 54 /// @brief Constructor 55 55 /// 56 56 Score(bool absolute=true) ; 57 57 58 58 /// 59 /// 59 /// @brief Destructor 60 60 /// 61 virtual ~Score(void) {};61 virtual ~Score(void); 62 62 63 63 /// 64 /// Function changing mode of Score64 /// @brief Function changing mode of Score 65 65 /// 66 66 inline void absolute(bool absolute) {absolute_=absolute;} … … 87 87 /// @param value vector of the values 88 88 /// 89 inline double 90 score(const classifier::Target& target, 91 const classifier::DataLookup1D& value) 92 { 93 assert(target.size()==value.size()); 94 utility::vector a; 95 classifier::convert(value,a); 96 return score(target,a); 97 } 89 double score(const classifier::Target& target, 90 const classifier::DataLookup1D& value); 98 91 99 92 /// … … 127 120 /// is wanted. 128 121 /// 129 inline double 130 score(const classifier::Target& target, 131 const classifier::DataLookup1D& value, 132 const classifier::DataLookup1D& weight) 133 { 134 utility::vector a; 135 classifier::convert(value,a); 136 utility::vector b; 137 classifier::convert(weight,a); 138 return score(target,a,b); 139 } 122 double score(const classifier::Target& target, 123 const classifier::DataLookup1D& value, 124 const classifier::DataLookup1D& weight); 140 125 141 126 protected: -
trunk/yat/statistics/tScore.h
r683 r703 48 48 public: 49 49 /// 50 /// Default Constructor.50 /// 2brief Default Constructor. 51 51 /// 52 52 tScore(bool absolute=true); -
trunk/yat/statistics/utility.cc
r683 r703 37 37 p+= gsl_ran_hypergeometric_pdf(i, n1, n2, t); 38 38 return p; 39 } 40 41 double kurtosis(const utility::vector& v) 42 { 43 const gsl_vector* gvp=v.gsl_vector_p(); 44 return gsl_stats_kurtosis(gvp->data,gvp->stride,gvp->size); 39 45 } 40 46 … … 82 88 } 83 89 90 double skewness(const utility::vector& v) 91 { 92 const gsl_vector* gvp=v.gsl_vector_p(); 93 return gsl_stats_skew(gvp->data,gvp->stride,gvp->size); 94 } 95 84 96 }}} // of namespace statistics, yat, and theplu -
trunk/yat/statistics/utility.h
r683 r703 40 40 //forward declarations 41 41 template <class T> 42 inlinedouble median(const std::vector<T>& v, const bool sorted=false);42 double median(const std::vector<T>& v, const bool sorted=false); 43 43 44 44 template <class T> … … 61 61 62 62 /// 63 /// Computes the kurtosis of the data in a vector. The kurtosis 64 /// measures how sharply peaked a distribution is, relative to its 65 /// width. The kurtosis is normalized to zero for a gaussian 66 /// distribution. 63 /// @brief Computes the kurtosis of the data in a vector. 67 64 /// 68 inline double kurtosis(const utility::vector& v)69 {70 const gsl_vector* gvp=v.gsl_vector_p();71 return gsl_stats_kurtosis(gvp->data,gvp->stride,gvp->size);72 }65 /// The kurtosis measures how sharply peaked a distribution is, 66 /// relative to its width. The kurtosis is normalized to zero for a 67 /// gaussian distribution. 68 /// 69 double kurtosis(const utility::vector&); 73 70 74 71 … … 173 170 174 171 /// 175 /// Computes the skewness of the data in a vector. The skewness 176 /// measures the asymmetry of the tails of a distribution. 172 /// @brief Computes the skewness of the data in a vector. 177 173 /// 178 inline double skewness(const utility::vector& v) 179 { 180 const gsl_vector* gvp=v.gsl_vector_p(); 181 return gsl_stats_skew(gvp->data,gvp->stride,gvp->size); 182 } 174 /// The skewness measures the asymmetry of the tails of a 175 /// distribution. 176 /// 177 double skewness(const utility::vector&); 183 178 184 179 }}} // of namespace statistics, yat, and theplu
Note: See TracChangeset
for help on using the changeset viewer.