SHOGUN  4.1.0
 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 <shogun/lib/config.h>
20 #include <shogun/base/SGObject.h>
21 #include <shogun/lib/SGVector.h>
22 #include <shogun/io/SGIO.h>
23 
24 namespace shogun
25 {
26 template<class T> class SGMatrix;
27 template<class T> class SGSparseMatrix;
28 
32 class CStatistics: public CSGObject
33 {
34 
35 public:
36 
43  template<class T>
45  {
46  floatmax_t sum = 0;
47 
48  for ( index_t i = 0 ; i < vec.vlen ; ++i )
49  sum += vec[i];
50 
51  return sum/vec.vlen;
52  }
53 
80  static float64_t median(SGVector<float64_t> values, bool modify=false,
81  bool in_place=false);
82 
101  bool modify=false, bool in_place=false);
102 
111  static float64_t variance(SGVector<float64_t> values);
112 
122 
134  bool col_wise=true);
135 
149  bool col_wise=true);
150 
164  SGMatrix<float64_t> values, bool col_wise=true);
165 
166 #ifdef HAVE_LAPACK
167 
185  SGMatrix<float64_t> observations, bool in_place=false);
186 #endif //HAVE_LAPACK
187 
203  float64_t alpha, float64_t& conf_int_low, float64_t& conf_int_up);
204 
212  static float64_t inverse_student_t(int32_t k, float64_t p);
213 
226  float64_t y);
227 
251 
269 
272  float64_t std_dev);
273 
275  static inline float64_t lgamma(float64_t x)
276  {
277  return ::lgamma((double) x);
278  }
279 
282  static inline floatmax_t lgammal(floatmax_t x)
283  {
284 #ifdef HAVE_LGAMMAL
285  return ::lgammal((long double) x);
286 #else
287  return ::lgamma((double) x);
288 #endif // HAVE_LGAMMAL
289  }
290 
292  static inline float64_t tgamma(float64_t x)
293  {
294  return ::tgamma((double) x);
295  }
296 
314 
332 
342 
353 
369  float64_t y0);
370 
388  static float64_t normal_cdf(float64_t x, float64_t std_dev=1);
389 
405  static float64_t lnormal_cdf(float64_t x);
406 
414  static float64_t chi2_cdf(float64_t x, float64_t k);
415 
425 
432 
449 
465 
468  static float64_t mutual_info(float64_t* p1, float64_t* p2, int32_t len);
469 
473  float64_t* p, float64_t* q, int32_t len);
474 
476  static float64_t entropy(float64_t* p, int32_t len);
477 
482 
487 
492  static SGVector<int32_t> sample_indices(int32_t sample_size, int32_t N);
493 
495  virtual const char* get_name() const
496  {
497  return "Statistics";
498  }
499 
505  static float64_t dlgamma(float64_t x);
506 
509  {
512 
515  };
516 
531 
532 #ifdef HAVE_EIGEN3
533 
548 
564 
581 
598  SGMatrix<float64_t> cov, int32_t N=1, bool precision_matrix=false);
599 
616  SGSparseMatrix<float64_t> cov, int32_t N=1, bool precision_matrix=false);
617 #endif //HAVE_EIGEN3
618 
620  static const float64_t ERFC_CASE1;
621 
623  static const float64_t ERFC_CASE2;
624 
625 protected:
632  float64_t x, float64_t maxgam);
633 
639  float64_t x, float64_t big, float64_t biginv);
640 
646  float64_t x, float64_t big, float64_t biginv);
647 
649  static inline bool equal(float64_t a, float64_t b) { return a==b; }
650 
652  static inline bool not_equal(float64_t a, float64_t b) { return a!=b; }
653 
655  static inline bool less(float64_t a, float64_t b) { return a<b; }
656 
658  static inline bool less_equal(float64_t a, float64_t b) { return a<=b; }
659 
661  static inline bool greater(float64_t a, float64_t b) { return a>b; }
662 
664  static inline bool greater_equal(float64_t a, float64_t b) { return a>=b; }
665 };
666 
668 template <>
669  inline floatmax_t CStatistics::mean<complex128_t>(SGVector<complex128_t> vec)
670  {
672  return floatmax_t(0.0);
673  }
674 
675 }
676 
677 #endif /* __STATISTICS_H_ */

SHOGUN Machine Learning Toolbox - Documentation