SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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_ */
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:218
static bool less_equal(float64_t a, float64_t b)
Definition: Statistics.h:658
static bool not_equal(float64_t a, float64_t b)
Definition: Statistics.h:652
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:300
static float64_t lgamma(float64_t x)
Definition: Statistics.h:275
static bool greater_equal(float64_t a, float64_t b)
Definition: Statistics.h:664
int32_t index_t
Definition: common.h:62
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:295
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:335
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)
#define SG_SNOTIMPLEMENTED
Definition: SGIO.h:198
static const float64_t ERFC_CASE2
Definition: Statistics.h:623
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:40
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:32
static float64_t lnormal_cdf(float64_t x)
static float64_t tgamma(float64_t x)
Definition: Statistics.h:292
static SigmoidParamters fit_sigmoid(SGVector< float64_t > scores)
index_t vlen
Definition: SGVector.h:494
static const float64_t ERFC_CASE1
Definition: Statistics.h:620
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:112
static float64_t inverse_incomplete_beta(float64_t a, float64_t b, float64_t y)
Definition: Statistics.cpp:410
shogun vector
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:192
long double floatmax_t
Definition: common.h:51
virtual const char * get_name() const
Definition: Statistics.h:495
static float64_t inverse_student_t(int32_t k, float64_t p)
Definition: Statistics.cpp:362
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:311
static bool less(float64_t a, float64_t b)
Definition: Statistics.h:655
static floatmax_t mean(SGVector< T > vec)
Definition: Statistics.h:44
static float64_t error_function_complement(float64_t x)
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
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:204
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:862
static bool greater(float64_t a, float64_t b)
Definition: Statistics.h:661
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:255
static bool equal(float64_t a, float64_t b)
Definition: Statistics.h:649
static float64_t incomplete_gamma(float64_t a, float64_t x)
static floatmax_t lgammal(floatmax_t x)
Definition: Statistics.h:282
static float64_t inverse_incomplete_gamma_completed(float64_t a, float64_t y0)

SHOGUN Machine Learning Toolbox - Documentation