X-Boost  2.3.8
InformationMetrics.h
Go to the documentation of this file.
1 /* XBoost: Ada-Boost and Friends on Haar/ICF/HOG Features, Library and ToolBox
2  *
3  * Copyright (c) 2008-2014 Paolo Medici <medici@ce.unipr.it>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 
21 #ifndef _INFORMATION_METRICS_H
22 #define _INFORMATION_METRICS_H
23 
27 // Metriche usate nella teoria dell'informazione
28 // TODO: unused now
29 
30 struct Entropy { };
31 
32 struct GiniIndex { };
33 
35 
37 double entropy(const double *p, int n)
38 {
39 double acc=0.0;
40 static const double norm_factor = 1.0/log(2.0);
41 for(int i =0;i<n;++i)
42  acc+= p[i] * log(p[i]);
43 return -acc * norm_factor;
44 }
45 
47 double entropy(double p)
48 {
49 static const double norm_factor = 1.0/log(2.0);
50 return -(p*log(p)+(1.0-p)*log(1.0-p)) * norm_factor;
51 }
52 
54 double gini_index(const double *p, int n)
55 {
56 double acc=0.0;
57 for(int i =0;i<n;++i)
58  acc+= p[i]*p[i];
59 return 1.0 - acc;
60 }
61 
63 double gini_index(double p)
64 {
65 // return -2*p*p + 2*p ;
66 return 2*p*(1-p);
67 }
68 
70 double classification_error(const double *p, int n)
71 {
72 double acc=0.0;
73 for(int i =0;i<n;++i)
74  if(p[i]>acc) acc = p[i];
75 return 1.0 - acc;
76 }
77 
79 double classification_error(double p)
80 {
81 // return 1.0 -std::max(p,1.0-p);
82  return (p<0.5) ? (1.0-p) : p;
83 }
84 
85 
86 #endif
Definition: InformationMetrics.h:34
Definition: InformationMetrics.h:30
double entropy(const double *p, int n)
compute entropy of n-classes distribution
Definition: InformationMetrics.h:37
double gini_index(const double *p, int n)
gini index in a n-classes distributions
Definition: InformationMetrics.h:54
double classification_error(const double *p, int n)
classification error in n-classes distribution
Definition: InformationMetrics.h:70
Definition: InformationMetrics.h:32