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