Statistics.h

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2011-2012 Heiko Strathmann
00008  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
00009  *
00010  * ALGLIB Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier under GPL2+
00011  * http://www.alglib.net/
00012  * See method comments which functions are taken from ALGLIB (with adjustments
00013  * for shogun)
00014  */
00015 
00016 #ifndef __STATISTICS_H_
00017 #define __STATISTICS_H_
00018 
00019 #include <math.h>
00020 #include <shogun/lib/config.h>
00021 #include <shogun/base/SGObject.h>
00022 
00023 namespace shogun
00024 {
00025 template<class T> class SGMatrix;
00026 
00030 class CStatistics: public CSGObject
00031 {
00032 
00033 public:
00034 
00041     static float64_t mean(SGVector<float64_t> values);
00042 
00069     static float64_t median(SGVector<float64_t> values, bool modify=false,
00070             bool in_place=false);
00071 
00089     static float64_t matrix_median(SGMatrix<float64_t> values,
00090             bool modify=false, bool in_place=false);
00091 
00100     static float64_t variance(SGVector<float64_t> values);
00101 
00110     static float64_t std_deviation(SGVector<float64_t> values);
00111 
00122     static SGVector<float64_t> matrix_mean(SGMatrix<float64_t> values,
00123             bool col_wise=true);
00124 
00137     static SGVector<float64_t> matrix_variance(SGMatrix<float64_t> values,
00138             bool col_wise=true);
00139 
00152     static SGVector<float64_t> matrix_std_deviation(
00153             SGMatrix<float64_t> values, bool col_wise=true);
00154 
00155 #ifdef HAVE_LAPACK
00156 
00173     static SGMatrix<float64_t> covariance_matrix(
00174             SGMatrix<float64_t> observations, bool in_place=false);
00175 #endif //HAVE_LAPACK
00176 
00191     static float64_t confidence_intervals_mean(SGVector<float64_t> values,
00192             float64_t alpha, float64_t& conf_int_low, float64_t& conf_int_up);
00193 
00201     static float64_t inverse_student_t(int32_t k, float64_t p);
00202 
00214     static float64_t inverse_incomplete_beta(float64_t a, float64_t b,
00215             float64_t y);
00216 
00239     static float64_t incomplete_beta(float64_t a, float64_t b, float64_t x);
00240 
00257     static float64_t inverse_normal_cdf(float64_t y0);
00258 
00260     static float64_t inverse_normal_cdf(float64_t y0, float64_t mean,
00261                 float64_t std_dev);
00262 
00264     static inline float64_t lgamma(float64_t x)
00265     {
00266         return ::lgamma((double) x);
00267     }
00268 
00271     static inline floatmax_t lgammal(floatmax_t x)
00272     {
00273 #ifdef HAVE_LGAMMAL
00274         return ::lgammal((long double) x);
00275 #else
00276         return ::lgamma((double) x);
00277 #endif // HAVE_LGAMMAL
00278     }
00279 
00281     static inline float64_t tgamma(float64_t x)
00282     {
00283         return ::tgamma((double) x);
00284     }
00285 
00302     static float64_t incomplete_gamma(float64_t a, float64_t x);
00303 
00320     static float64_t incomplete_gamma_completed(float64_t a, float64_t x);
00321 
00330     static float64_t gamma_cdf(float64_t x, float64_t a, float64_t b);
00331 
00341     static float64_t inverse_gamma_cdf(float64_t p, float64_t a, float64_t b);
00342 
00357     static float64_t inverse_incomplete_gamma_completed(float64_t a,
00358             float64_t y0);
00359 
00377     static float64_t normal_cdf(float64_t x, float64_t std_dev=1);
00378 
00394     static float64_t error_function(float64_t x);
00395 
00410     static float64_t error_function_complement(float64_t x);
00411 
00414     static float64_t mutual_info(float64_t* p1, float64_t* p2, int32_t len);
00415 
00418     static float64_t relative_entropy(
00419             float64_t* p, float64_t* q, int32_t len);
00420 
00422     static float64_t entropy(float64_t* p, int32_t len);
00423 
00427     static SGVector<float64_t> fishers_exact_test_for_multiple_2x3_tables(SGMatrix<float64_t> tables);
00428 
00432     static float64_t fishers_exact_test_for_2x3_table(SGMatrix<float64_t> table);
00433 
00438     static SGVector<int32_t> sample_indices(int32_t sample_size, int32_t N);
00439 
00441     virtual const char* get_name() const
00442     {
00443         return "Statistics";
00444     }
00445 
00454         static float64_t dlgamma(float64_t x);
00455 
00456 
00457 protected:
00463     static float64_t ibetaf_incompletebetaps(float64_t a, float64_t b,
00464             float64_t x, float64_t maxgam);
00465 
00470     static float64_t ibetaf_incompletebetafe(float64_t a, float64_t b,
00471             float64_t x, float64_t big, float64_t biginv);
00472 
00477     static float64_t ibetaf_incompletebetafe2(float64_t a, float64_t b,
00478             float64_t x, float64_t big, float64_t biginv);
00479 
00481     static inline bool equal(float64_t a, float64_t b) { return a==b; }
00482 
00484     static inline bool not_equal(float64_t a, float64_t b) { return a!=b; }
00485 
00487     static inline bool less(float64_t a, float64_t b) { return a<b; }
00488 
00490     static inline bool less_equal(float64_t a, float64_t b) { return a<=b; }
00491 
00493     static inline bool greater(float64_t a, float64_t b) { return a>b; }
00494 
00496     static inline bool greater_equal(float64_t a, float64_t b) { return a>=b; }
00497 };
00498 
00499 }
00500 
00501 #endif /* __STATISTICS_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation