SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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 template<class T> class SGSparseMatrix;
00027 
00031 class CStatistics: public CSGObject
00032 {
00033 
00034 public:
00035 
00042     static float64_t mean(SGVector<float64_t> values);
00043 
00070     static float64_t median(SGVector<float64_t> values, bool modify=false,
00071             bool in_place=false);
00072 
00090     static float64_t matrix_median(SGMatrix<float64_t> values,
00091             bool modify=false, bool in_place=false);
00092 
00101     static float64_t variance(SGVector<float64_t> values);
00102 
00111     static float64_t std_deviation(SGVector<float64_t> values);
00112 
00123     static SGVector<float64_t> matrix_mean(SGMatrix<float64_t> values,
00124             bool col_wise=true);
00125 
00138     static SGVector<float64_t> matrix_variance(SGMatrix<float64_t> values,
00139             bool col_wise=true);
00140 
00153     static SGVector<float64_t> matrix_std_deviation(
00154             SGMatrix<float64_t> values, bool col_wise=true);
00155 
00156 #ifdef HAVE_LAPACK
00157 
00174     static SGMatrix<float64_t> covariance_matrix(
00175             SGMatrix<float64_t> observations, bool in_place=false);
00176 #endif //HAVE_LAPACK
00177 
00192     static float64_t confidence_intervals_mean(SGVector<float64_t> values,
00193             float64_t alpha, float64_t& conf_int_low, float64_t& conf_int_up);
00194 
00202     static float64_t inverse_student_t(int32_t k, float64_t p);
00203 
00215     static float64_t inverse_incomplete_beta(float64_t a, float64_t b,
00216             float64_t y);
00217 
00240     static float64_t incomplete_beta(float64_t a, float64_t b, float64_t x);
00241 
00258     static float64_t inverse_normal_cdf(float64_t y0);
00259 
00261     static float64_t inverse_normal_cdf(float64_t y0, float64_t mean,
00262                 float64_t std_dev);
00263 
00265     static inline float64_t lgamma(float64_t x)
00266     {
00267         return ::lgamma((double) x);
00268     }
00269 
00272     static inline floatmax_t lgammal(floatmax_t x)
00273     {
00274 #ifdef HAVE_LGAMMAL
00275         return ::lgammal((long double) x);
00276 #else
00277         return ::lgamma((double) x);
00278 #endif // HAVE_LGAMMAL
00279     }
00280 
00282     static inline float64_t tgamma(float64_t x)
00283     {
00284         return ::tgamma((double) x);
00285     }
00286 
00303     static float64_t incomplete_gamma(float64_t a, float64_t x);
00304 
00321     static float64_t incomplete_gamma_completed(float64_t a, float64_t x);
00322 
00331     static float64_t gamma_cdf(float64_t x, float64_t a, float64_t b);
00332 
00342     static float64_t inverse_gamma_cdf(float64_t p, float64_t a, float64_t b);
00343 
00358     static float64_t inverse_incomplete_gamma_completed(float64_t a,
00359             float64_t y0);
00360 
00378     static float64_t normal_cdf(float64_t x, float64_t std_dev=1);
00379 
00395     static float64_t lnormal_cdf(float64_t x);
00396 
00412     static float64_t error_function(float64_t x);
00413 
00428     static float64_t error_function_complement(float64_t x);
00429 
00432     static float64_t mutual_info(float64_t* p1, float64_t* p2, int32_t len);
00433 
00436     static float64_t relative_entropy(
00437             float64_t* p, float64_t* q, int32_t len);
00438 
00440     static float64_t entropy(float64_t* p, int32_t len);
00441 
00445     static SGVector<float64_t> fishers_exact_test_for_multiple_2x3_tables(SGMatrix<float64_t> tables);
00446 
00450     static float64_t fishers_exact_test_for_2x3_table(SGMatrix<float64_t> table);
00451 
00456     static SGVector<int32_t> sample_indices(int32_t sample_size, int32_t N);
00457 
00459     virtual const char* get_name() const
00460     {
00461         return "Statistics";
00462     }
00463 
00469     static float64_t dlgamma(float64_t x);
00470 
00472     struct SigmoidParamters
00473     {
00475         float64_t a;
00476 
00478         float64_t b;
00479     };
00480 
00494     static SigmoidParamters fit_sigmoid(SGVector<float64_t> scores);
00495 
00496 #ifdef HAVE_EIGEN3
00497 
00511     static float64_t log_det(SGMatrix<float64_t> m);
00512 
00528     static float64_t log_det(const SGSparseMatrix<float64_t> m);
00529 
00545     static SGMatrix<float64_t> sample_from_gaussian(SGVector<float64_t> mean,
00546     SGMatrix<float64_t> cov, int32_t N=1, bool precision_matrix=false);
00547 
00563     static SGMatrix<float64_t> sample_from_gaussian(SGVector<float64_t> mean,
00564     SGSparseMatrix<float64_t> cov, int32_t N=1, bool precision_matrix=false);
00565 #endif //HAVE_EIGEN3
00566 
00567 
00568 protected:
00574     static float64_t ibetaf_incompletebetaps(float64_t a, float64_t b,
00575             float64_t x, float64_t maxgam);
00576 
00581     static float64_t ibetaf_incompletebetafe(float64_t a, float64_t b,
00582             float64_t x, float64_t big, float64_t biginv);
00583 
00588     static float64_t ibetaf_incompletebetafe2(float64_t a, float64_t b,
00589             float64_t x, float64_t big, float64_t biginv);
00590 
00592     static inline bool equal(float64_t a, float64_t b) { return a==b; }
00593 
00595     static inline bool not_equal(float64_t a, float64_t b) { return a!=b; }
00596 
00598     static inline bool less(float64_t a, float64_t b) { return a<b; }
00599 
00601     static inline bool less_equal(float64_t a, float64_t b) { return a<=b; }
00602 
00604     static inline bool greater(float64_t a, float64_t b) { return a>b; }
00605 
00607     static inline bool greater_equal(float64_t a, float64_t b) { return a>=b; }
00608 };
00609 
00610 }
00611 
00612 #endif /* __STATISTICS_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation