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_ */
static SGVector< int32_t > sample_indices(int32_t sample_size, int32_t N)
static SGVector< float64_t > matrix_mean(SGMatrix< float64_t > values, bool col_wise=true)
Definition: Statistics.cpp:230
template class SGSparseMatrix
Definition: Parameter.h:27
static bool less_equal(float64_t a, float64_t b)
Definition: Statistics.h:649
static bool not_equal(float64_t a, float64_t b)
Definition: Statistics.h:643
static float64_t error_function(float64_t x)
static float64_t ibetaf_incompletebetafe(float64_t a, float64_t b, float64_t x, float64_t big, float64_t biginv)
static SGVector< float64_t > matrix_std_deviation(SGMatrix< float64_t > values, bool col_wise=true)
Definition: Statistics.cpp:312
static float64_t lgamma(float64_t x)
Definition: Statistics.h:265
static bool greater_equal(float64_t a, float64_t b)
Definition: Statistics.h:655
static float64_t incomplete_gamma_completed(float64_t a, float64_t x)
static float64_t inverse_normal_cdf(float64_t y0)
static float64_t std_deviation(SGVector< float64_t > values)
Definition: Statistics.cpp:307
static float64_t fdistribution_cdf(float64_t x, float64_t d1, float64_t d2)
static float64_t confidence_intervals_mean(SGVector< float64_t > values, float64_t alpha, float64_t &conf_int_low, float64_t &conf_int_up)
Definition: Statistics.cpp:347
static SGVector< float64_t > fishers_exact_test_for_multiple_2x3_tables(SGMatrix< float64_t > tables)
static float64_t relative_entropy(float64_t *p, float64_t *q, int32_t len)
static const float64_t ERFC_CASE2
Definition: Statistics.h:614
static SGMatrix< float64_t > sample_from_gaussian(SGVector< float64_t > mean, SGMatrix< float64_t > cov, int32_t N=1, bool precision_matrix=false)
static float64_t median(SGVector< float64_t > values, bool modify=false, bool in_place=false)
Definition: Statistics.cpp:52
static float64_t ibetaf_incompletebetaps(float64_t a, float64_t b, float64_t x, float64_t maxgam)
static float64_t mutual_info(float64_t *p1, float64_t *p2, int32_t len)
static float64_t log_det_general(const SGMatrix< float64_t > A)
static float64_t gamma_cdf(float64_t x, float64_t a, float64_t b)
static float64_t log_det(SGMatrix< float64_t > m)
Class that contains certain functions related to statistics, such as probability/cumulative distribut...
Definition: Statistics.h:31
static float64_t lnormal_cdf(float64_t x)
static float64_t tgamma(float64_t x)
Definition: Statistics.h:282
static SigmoidParamters fit_sigmoid(SGVector< float64_t > scores)
static const float64_t ERFC_CASE1
Definition: Statistics.h:611
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:98
static float64_t inverse_incomplete_beta(float64_t a, float64_t b, float64_t y)
Definition: Statistics.cpp:422
static float64_t entropy(float64_t *p, int32_t len)
double float64_t
Definition: common.h:50
static float64_t matrix_median(SGMatrix< float64_t > values, bool modify=false, bool in_place=false)
Definition: Statistics.cpp:204
long double floatmax_t
Definition: common.h:51
virtual const char * get_name() const
Definition: Statistics.h:486
static float64_t inverse_student_t(int32_t k, float64_t p)
Definition: Statistics.cpp:374
static float64_t ibetaf_incompletebetafe2(float64_t a, float64_t b, float64_t x, float64_t big, float64_t biginv)
static SGMatrix< float64_t > covariance_matrix(SGMatrix< float64_t > observations, bool in_place=false)
Definition: Statistics.cpp:323
static bool less(float64_t a, float64_t b)
Definition: Statistics.h:646
static float64_t error_function_complement(float64_t x)
static float64_t erfc8_weighted_sum(float64_t x)
static float64_t dlgamma(float64_t x)
static float64_t variance(SGVector< float64_t > values)
Definition: Statistics.cpp:216
static float64_t normal_cdf(float64_t x, float64_t std_dev=1)
static float64_t inverse_gamma_cdf(float64_t p, float64_t a, float64_t b)
static float64_t incomplete_beta(float64_t a, float64_t b, float64_t x)
Definition: Statistics.cpp:874
static float64_t mean(SGVector< float64_t > values)
Definition: Statistics.cpp:40
static bool greater(float64_t a, float64_t b)
Definition: Statistics.h:652
static float64_t fishers_exact_test_for_2x3_table(SGMatrix< float64_t > table)
static float64_t chi2_cdf(float64_t x, float64_t k)
static SGVector< float64_t > matrix_variance(SGMatrix< float64_t > values, bool col_wise=true)
Definition: Statistics.cpp:267
static bool equal(float64_t a, float64_t b)
Definition: Statistics.h:640
static float64_t incomplete_gamma(float64_t a, float64_t x)
static floatmax_t lgammal(floatmax_t x)
Definition: Statistics.h:272
static float64_t inverse_incomplete_gamma_completed(float64_t a, float64_t y0)

SHOGUN Machine Learning Toolbox - Documentation