1 | #ifndef _theplu_statistics_score_ |
---|
2 | #define _theplu_statistics_score_ |
---|
3 | |
---|
4 | // $Id: Score.h 623 2006-09-05 02:13:12Z peter $ |
---|
5 | |
---|
6 | #include <c++_tools/classifier/utility.h> |
---|
7 | #include <c++_tools/utility/vector.h> |
---|
8 | |
---|
9 | #include <cassert> |
---|
10 | #ifndef NDEGUG |
---|
11 | #include <c++_tools/classifier/Target.h> |
---|
12 | #include <c++_tools/classifier/DataLookup1D.h> |
---|
13 | #endif |
---|
14 | |
---|
15 | namespace theplu { |
---|
16 | namespace classifier { |
---|
17 | class Target; |
---|
18 | class DataLookup1D; |
---|
19 | class DataLookupWeighted1D; |
---|
20 | } |
---|
21 | |
---|
22 | namespace statistics { |
---|
23 | |
---|
24 | /// |
---|
25 | /// Abstract Base Class defining the interface for the score classes. |
---|
26 | /// |
---|
27 | class Score |
---|
28 | { |
---|
29 | |
---|
30 | public: |
---|
31 | /// |
---|
32 | /// Constructor |
---|
33 | /// |
---|
34 | Score(bool absolute=true) ; |
---|
35 | |
---|
36 | /// |
---|
37 | /// Destructor |
---|
38 | /// |
---|
39 | virtual ~Score(void) {}; |
---|
40 | |
---|
41 | /// |
---|
42 | /// Function changing mode of Score |
---|
43 | /// |
---|
44 | inline void absolute(bool absolute) {absolute_=absolute;} |
---|
45 | |
---|
46 | /// |
---|
47 | /// Function calculating the score. In absolute mode, also the |
---|
48 | /// score using negated class labels is calculated, and the |
---|
49 | /// largest of the two scores are calculated. Absolute mode should |
---|
50 | /// be used when two-tailed test is wanted. |
---|
51 | /// |
---|
52 | virtual double |
---|
53 | score(const classifier::Target& target, |
---|
54 | const utility::vector& value) = 0; |
---|
55 | |
---|
56 | /// |
---|
57 | /// Function calculating the score. In absolute mode, also the |
---|
58 | /// score using negated class labels is calculated, and the |
---|
59 | /// largest of the two scores are calculated. Absolute mode should |
---|
60 | /// be used when two-tailed test is wanted. |
---|
61 | /// |
---|
62 | /// @return statistica. |
---|
63 | /// |
---|
64 | /// @param target vector of targets (most often +1 -1) |
---|
65 | /// @param value vector of the values |
---|
66 | /// |
---|
67 | inline double |
---|
68 | score(const classifier::Target& target, |
---|
69 | const classifier::DataLookup1D& value) |
---|
70 | { |
---|
71 | assert(target.size()==value.size()); |
---|
72 | utility::vector a; |
---|
73 | classifier::convert(value,a); |
---|
74 | return score(target,a); |
---|
75 | } |
---|
76 | |
---|
77 | /// |
---|
78 | /// Function calculating the score in a weighted fashion. In |
---|
79 | /// absolute mode, also the score using negated class labels is |
---|
80 | /// calculated, and the largest of the two scores are |
---|
81 | /// calculated. Absolute mode should be used when two-tailed test |
---|
82 | /// is wanted. |
---|
83 | /// |
---|
84 | virtual double |
---|
85 | score(const classifier::Target& target, |
---|
86 | const classifier::DataLookupWeighted1D& value) = 0; |
---|
87 | |
---|
88 | /// |
---|
89 | /// Function calculating the weighted version of score. In |
---|
90 | /// absolute mode, also the score using negated class labels is |
---|
91 | /// calculated, and the largest of the two scores are |
---|
92 | /// calculated. Absolute mode should be used when two-tailed test |
---|
93 | /// is wanted. |
---|
94 | /// |
---|
95 | virtual double |
---|
96 | score(const classifier::Target& target, |
---|
97 | const utility::vector& value, |
---|
98 | const utility::vector& weight) = 0; |
---|
99 | |
---|
100 | /// |
---|
101 | /// Function calculating the weighted version of score. In |
---|
102 | /// absolute mode, also the score using negated class labels is |
---|
103 | /// calculated, and the largest of the two scores are |
---|
104 | /// calculated. Absolute mode should be used when two-tailed test |
---|
105 | /// is wanted. |
---|
106 | /// |
---|
107 | inline double |
---|
108 | score(const classifier::Target& target, |
---|
109 | const classifier::DataLookup1D& value, |
---|
110 | const classifier::DataLookup1D& weight) |
---|
111 | { |
---|
112 | utility::vector a; |
---|
113 | classifier::convert(value,a); |
---|
114 | utility::vector b; |
---|
115 | classifier::convert(weight,a); |
---|
116 | return score(target,a,b); |
---|
117 | } |
---|
118 | |
---|
119 | protected: |
---|
120 | inline bool weighted(void) const { return weighted_; } |
---|
121 | |
---|
122 | bool absolute_; |
---|
123 | bool weighted_; |
---|
124 | |
---|
125 | }; // class Score |
---|
126 | |
---|
127 | }} // of namespace statistics and namespace theplu |
---|
128 | |
---|
129 | #endif |
---|