SHOGUN  5.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
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-2016 Heiko Strathmann
8  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
9  *
10  * Most cdf routines are wrappers for CDFLIB, part of the public domain NETLIB.
11  * https://people.sc.fsu.edu/~jburkardt/f_src/cdflib/cdflib.html
12  */
13 
14 #ifndef __STATISTICS_H_
15 #define __STATISTICS_H_
16 
17 #include <shogun/lib/config.h>
18 #include <shogun/base/SGObject.h>
19 #include <shogun/lib/SGVector.h>
20 #include <shogun/io/SGIO.h>
21 
22 namespace shogun
23 {
24 template<class T> class SGMatrix;
25 template<class T> class SGSparseMatrix;
26 
30 class CStatistics: public CSGObject
31 {
32 
33 public:
34 
41  template<class T>
43  {
44  floatmax_t sum = 0;
45 
46  for ( index_t i = 0 ; i < vec.vlen ; ++i )
47  sum += vec[i];
48 
49  return sum/vec.vlen;
50  }
51 
60  static float64_t variance(SGVector<float64_t> values);
61 
71 
83  bool col_wise=true);
84 
98  bool col_wise=true);
99 
113  SGMatrix<float64_t> values, bool col_wise=true);
114 
128  SGMatrix<float64_t> observations, bool in_place=false);
129 
131  static inline float64_t lgamma(float64_t x)
132  {
133  return ::lgamma((double) x);
134  }
135 
138  static inline floatmax_t lgammal(floatmax_t x)
139  {
140 #ifdef HAVE_LGAMMAL
141  return ::lgammal((long double) x);
142 #else
143  return ::lgamma((double) x);
144 #endif // HAVE_LGAMMAL
145  }
146 
148  static inline float64_t tgamma(float64_t x)
149  {
150  return ::tgamma((double) x);
151  }
152 
166 
182 
194  static float64_t normal_cdf(float64_t x, float64_t std_dev=1);
195 
211  float64_t std_dev=1);
212 
224  static float64_t lnormal_cdf(float64_t x);
225 
233  static float64_t chi2_cdf(float64_t x, float64_t k);
234 
244 
251 
254  static float64_t mutual_info(float64_t* p1, float64_t* p2, int32_t len);
255 
259  float64_t* p, float64_t* q, int32_t len);
260 
262  static float64_t entropy(float64_t* p, int32_t len);
263 
268 
273 
278  static SGVector<int32_t> sample_indices(int32_t sample_size, int32_t N);
279 
281  virtual const char* get_name() const
282  {
283  return "Statistics";
284  }
285 
291  static float64_t dlgamma(float64_t x);
292 
295  {
298 
301  };
302 
317 
333 
349 
366 
383  SGMatrix<float64_t> cov, int32_t N=1, bool precision_matrix=false);
384 
401  SGSparseMatrix<float64_t> cov, int32_t N=1, bool precision_matrix=false);
402 
404  static const float64_t ERFC_CASE1;
405 
407  static const float64_t ERFC_CASE2;
408 
409 
410 };
411 
413 template <>
414  inline floatmax_t CStatistics::mean<complex128_t>(SGVector<complex128_t> vec)
415  {
417  return floatmax_t(0.0);
418  }
419 
420 }
421 
422 #endif /* __STATISTICS_H_ */
static SGVector< int32_t > sample_indices(int32_t sample_size, int32_t N)
Definition: Statistics.cpp:322
static SGVector< float64_t > matrix_mean(SGMatrix< float64_t > values, bool col_wise=true)
Definition: Statistics.cpp:43
static SGVector< float64_t > matrix_std_deviation(SGMatrix< float64_t > values, bool col_wise=true)
Definition: Statistics.cpp:125
static float64_t lgamma(float64_t x)
Definition: Statistics.h:131
int32_t index_t
Definition: common.h:62
static float64_t std_deviation(SGVector< float64_t > values)
Definition: Statistics.cpp:120
static float64_t fdistribution_cdf(float64_t x, float64_t d1, float64_t d2)
Definition: Statistics.cpp:537
static SGVector< float64_t > fishers_exact_test_for_multiple_2x3_tables(SGMatrix< float64_t > tables)
Definition: Statistics.cpp:168
static float64_t relative_entropy(float64_t *p, float64_t *q, int32_t len)
Definition: Statistics.cpp:302
#define SG_SNOTIMPLEMENTED
Definition: SGIO.h:198
static const float64_t ERFC_CASE2
Definition: Statistics.h:407
static SGMatrix< float64_t > sample_from_gaussian(SGVector< float64_t > mean, SGMatrix< float64_t > cov, int32_t N=1, bool precision_matrix=false)
Definition: Statistics.cpp:703
static float64_t mutual_info(float64_t *p1, float64_t *p2, int32_t len)
Definition: Statistics.cpp:291
static float64_t log_det_general(const SGMatrix< float64_t > A)
Definition: Statistics.cpp:606
static float64_t gamma_cdf(float64_t x, float64_t a, float64_t b)
Definition: Statistics.cpp:395
static float64_t log_det(SGMatrix< float64_t > m)
Definition: Statistics.cpp:660
Class that contains certain functions related to statistics, such as probability/cumulative distribut...
Definition: Statistics.h:30
static float64_t lnormal_cdf(float64_t x)
Definition: Statistics.cpp:418
static float64_t tgamma(float64_t x)
Definition: Statistics.h:148
static SigmoidParamters fit_sigmoid(SGVector< float64_t > scores)
Definition: Statistics.cpp:821
index_t vlen
Definition: SGVector.h:494
static const float64_t ERFC_CASE1
Definition: Statistics.h:404
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:115
shogun vector
static float64_t entropy(float64_t *p, int32_t len)
Definition: Statistics.cpp:312
double float64_t
Definition: common.h:50
long double floatmax_t
Definition: common.h:51
virtual const char * get_name() const
Definition: Statistics.h:281
static SGMatrix< float64_t > covariance_matrix(SGMatrix< float64_t > observations, bool in_place=false)
Definition: Statistics.cpp:135
static floatmax_t mean(SGVector< T > vec)
Definition: Statistics.h:42
static float64_t inverse_normal_cdf(float64_t y0, float64_t mean=0, float64_t std_dev=1)
Definition: Statistics.cpp:348
static float64_t gamma_inverse_cdf(float64_t p, float64_t a, float64_t b)
Definition: Statistics.cpp:513
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)
Definition: Statistics.cpp:464
static float64_t dlgamma(float64_t x)
Definition: Statistics.cpp:558
static float64_t variance(SGVector< float64_t > values)
Definition: Statistics.cpp:29
static float64_t normal_cdf(float64_t x, float64_t std_dev=1)
Definition: Statistics.cpp:508
static float64_t fishers_exact_test_for_2x3_table(SGMatrix< float64_t > table)
Definition: Statistics.cpp:183
static float64_t chi2_cdf(float64_t x, float64_t k)
Definition: Statistics.cpp:374
static SGVector< float64_t > matrix_variance(SGMatrix< float64_t > values, bool col_wise=true)
Definition: Statistics.cpp:80
static floatmax_t lgammal(floatmax_t x)
Definition: Statistics.h:138

SHOGUN Machine Learning Toolbox - Documentation