SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Statistics.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2011-2012 Heiko Strathmann
8  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
9  *
10  * ALGLIB Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier under GPL2+
11  * http://www.alglib.net/
12  * See method comments which functions are taken from ALGLIB (with adjustments
13  * for shogun)
14  */
15 
16 #ifndef __STATISTICS_H_
17 #define __STATISTICS_H_
18 
19 #include <math.h>
20 #include <shogun/lib/config.h>
21 #include <shogun/base/SGObject.h>
22 
23 namespace shogun
24 {
25 template<class T> class SGMatrix;
26 template<class T> class SGSparseMatrix;
27 
31 class CStatistics: public CSGObject
32 {
33 
34 public:
35 
42  static float64_t mean(SGVector<float64_t> values);
43 
70  static float64_t median(SGVector<float64_t> values, bool modify=false,
71  bool in_place=false);
72 
91  bool modify=false, bool in_place=false);
92 
101  static float64_t variance(SGVector<float64_t> values);
102 
112 
124  bool col_wise=true);
125 
139  bool col_wise=true);
140 
154  SGMatrix<float64_t> values, bool col_wise=true);
155 
156 #ifdef HAVE_LAPACK
157 
175  SGMatrix<float64_t> observations, bool in_place=false);
176 #endif //HAVE_LAPACK
177 
193  float64_t alpha, float64_t& conf_int_low, float64_t& conf_int_up);
194 
202  static float64_t inverse_student_t(int32_t k, float64_t p);
203 
216  float64_t y);
217 
241 
259 
262  float64_t std_dev);
263 
265  static inline float64_t lgamma(float64_t x)
266  {
267  return ::lgamma((double) x);
268  }
269 
272  static inline floatmax_t lgammal(floatmax_t x)
273  {
274 #ifdef HAVE_LGAMMAL
275  return ::lgammal((long double) x);
276 #else
277  return ::lgamma((double) x);
278 #endif // HAVE_LGAMMAL
279  }
280 
282  static inline float64_t tgamma(float64_t x)
283  {
284  return ::tgamma((double) x);
285  }
286 
304 
322 
332 
343 
359  float64_t y0);
360 
378  static float64_t normal_cdf(float64_t x, float64_t std_dev=1);
379 
395  static float64_t lnormal_cdf(float64_t x);
396 
404  static float64_t chi2_cdf(float64_t x, float64_t k);
405 
415 
416  /* use to estimates erfc(x) valid for -100 < x < -8
417  *
418  * @param x real value
419  *
420  * @return weighted sum
421  */
423 
440 
456 
459  static float64_t mutual_info(float64_t* p1, float64_t* p2, int32_t len);
460 
464  float64_t* p, float64_t* q, int32_t len);
465 
467  static float64_t entropy(float64_t* p, int32_t len);
468 
473 
478 
483  static SGVector<int32_t> sample_indices(int32_t sample_size, int32_t N);
484 
486  virtual const char* get_name() const
487  {
488  return "Statistics";
489  }
490 
496  static float64_t dlgamma(float64_t x);
497 
500  {
503 
506  };
507 
522 
523 #ifdef HAVE_EIGEN3
524 
539 
555 
572 
589  SGMatrix<float64_t> cov, int32_t N=1, bool precision_matrix=false);
590 
607  SGSparseMatrix<float64_t> cov, int32_t N=1, bool precision_matrix=false);
608 #endif //HAVE_EIGEN3
609 
610  /* Magic number for computing lnormal_cdf */
611  static const float64_t ERFC_CASE1;
612 
613  /* Magic number for computing lnormal_cdf */
614  static const float64_t ERFC_CASE2;
615 
616 protected:
623  float64_t x, float64_t maxgam);
624 
630  float64_t x, float64_t big, float64_t biginv);
631 
637  float64_t x, float64_t big, float64_t biginv);
638 
640  static inline bool equal(float64_t a, float64_t b) { return a==b; }
641 
643  static inline bool not_equal(float64_t a, float64_t b) { return a!=b; }
644 
646  static inline bool less(float64_t a, float64_t b) { return a<b; }
647 
649  static inline bool less_equal(float64_t a, float64_t b) { return a<=b; }
650 
652  static inline bool greater(float64_t a, float64_t b) { return a>b; }
653 
655  static inline bool greater_equal(float64_t a, float64_t b) { return a>=b; }
656 };
657 
658 }
659 
660 #endif /* __STATISTICS_H_ */

SHOGUN Machine Learning Toolbox - Documentation