Changeset 588
- Timestamp:
- Jun 21, 2006, 5:43:29 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/c++_tools/statistics/utility.h
r519 r588 11 11 #include <vector> 12 12 13 #include <gsl/gsl_statistics_double.h> 14 13 15 namespace theplu { 14 16 namespace statistics { … … 21 23 22 24 /// 23 /// Calculates the probabil ty to get \a k or smaller from a25 /// Calculates the probability to get \a k or smaller from a 24 26 /// hypergeometric distribution with parameters \a n1 \a n2 \a 25 27 /// t. Hypergeomtric situation you get in the following situation: … … 31 33 /// 32 34 double cdf_hypergeometric_P(u_int k, u_int n1, u_int n2, u_int t); 35 36 37 /// 38 /// Computes the kurtosis of the data in a vector. The kurtosis 39 /// measures how sharply peaked a distribution is, relative to its 40 /// width. The kurtosis is normalized to zero for a gaussian 41 /// distribution. 42 /// 43 inline double kurtosis(const gslapi::vector& v) 44 { 45 const gsl_vector* gvp=v.gsl_vector_p(); 46 return gsl_stats_kurtosis(gvp->data,gvp->stride,gvp->size); 47 } 33 48 34 49 … … 110 125 const bool sorted=false); 111 126 127 /// 128 /// Computes the skewness of the data in a vector. The skewness 129 /// measures the asymmetry of the tails of a distribution. 130 /// 131 inline double skewness(const gslapi::vector& v) 132 { 133 const gsl_vector* gvp=v.gsl_vector_p(); 134 return gsl_stats_skew(gvp->data,gvp->stride,gvp->size); 135 } 136 137 112 138 }} // of namespace statistics and namespace theplu 113 139 -
trunk/test/statistics_test.cc
r511 r588 7 7 #include <cstdlib> 8 8 #include <iostream> 9 9 #include <cmath> 10 10 11 11 int main() … … 18 18 gsl_vec(i)=i; 19 19 } 20 20 21 double m=statistics::median(data); 21 22 double m_gsl=statistics::median(gsl_vec); 22 23 if (m!=4.5 || m!=m_gsl) 23 24 return -1; 25 26 double tolerance=1e-10; 27 double skewness_gsl=statistics::skewness(gsl_vec); 28 if (fabs(skewness_gsl)>tolerance) 29 return -1; 30 double kurtosis_gsl=statistics::kurtosis(gsl_vec); 31 if (fabs(kurtosis_gsl+1.5616363636363637113)>tolerance) 32 return -1; 24 33 return 0; 25 34 }
Note: See TracChangeset
for help on using the changeset viewer.