1 | // $Id: tScore.cc 1275 2008-04-11 06:10:12Z jari $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2004 Jari Häkkinen, Peter Johansson |
---|
5 | Copyright (C) 2005 Peter Johansson |
---|
6 | Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér |
---|
7 | Copyright (C) 2007 Jari Häkkinen, Peter Johansson |
---|
8 | Copyright (C) 2008 Peter Johansson |
---|
9 | |
---|
10 | This file is part of the yat library, http://trac.thep.lu.se/yat |
---|
11 | |
---|
12 | The yat library is free software; you can redistribute it and/or |
---|
13 | modify it under the terms of the GNU General Public License as |
---|
14 | published by the Free Software Foundation; either version 2 of the |
---|
15 | License, or (at your option) any later version. |
---|
16 | |
---|
17 | The yat library is distributed in the hope that it will be useful, |
---|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
20 | General Public License for more details. |
---|
21 | |
---|
22 | You should have received a copy of the GNU General Public License |
---|
23 | along with this program; if not, write to the Free Software |
---|
24 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
25 | 02111-1307, USA. |
---|
26 | */ |
---|
27 | |
---|
28 | #include "tScore.h" |
---|
29 | #include "Averager.h" |
---|
30 | #include "AveragerWeighted.h" |
---|
31 | #include "yat/classifier/DataLookup1D.h" |
---|
32 | #include "yat/classifier/DataLookupWeighted1D.h" |
---|
33 | #include "yat/classifier/Target.h" |
---|
34 | #include "yat/utility/VectorBase.h" |
---|
35 | |
---|
36 | #include <cassert> |
---|
37 | #include <cmath> |
---|
38 | |
---|
39 | namespace theplu { |
---|
40 | namespace yat { |
---|
41 | namespace statistics { |
---|
42 | |
---|
43 | tScore::tScore(bool b) |
---|
44 | : Score(b) |
---|
45 | { |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
49 | double tScore::score(const classifier::Target& target, |
---|
50 | const utility::VectorBase& value) const |
---|
51 | { |
---|
52 | return score(target, value, NULL); |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | double tScore::score(const classifier::Target& target, |
---|
57 | const utility::VectorBase& value, |
---|
58 | double* dof) const |
---|
59 | { |
---|
60 | statistics::Averager positive; |
---|
61 | statistics::Averager negative; |
---|
62 | for(size_t i=0; i<target.size(); i++){ |
---|
63 | if (target.binary(i)) |
---|
64 | positive.add(value(i)); |
---|
65 | else |
---|
66 | negative.add(value(i)); |
---|
67 | } |
---|
68 | return score(positive, negative, dof); |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | double tScore::score(const classifier::Target& target, |
---|
73 | const classifier::DataLookupWeighted1D& value) const |
---|
74 | { |
---|
75 | return score(target, value, NULL); |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | double tScore::score(const classifier::Target& target, |
---|
80 | const classifier::DataLookupWeighted1D& value, |
---|
81 | double* dof) const |
---|
82 | { |
---|
83 | statistics::AveragerWeighted positive; |
---|
84 | statistics::AveragerWeighted negative; |
---|
85 | for(size_t i=0; i<target.size(); i++){ |
---|
86 | if (target.binary(i)) |
---|
87 | positive.add(value.data(i),value.weight(i)); |
---|
88 | else |
---|
89 | negative.add(value.data(i),value.weight(i)); |
---|
90 | } |
---|
91 | return score(positive, negative, dof); |
---|
92 | } |
---|
93 | |
---|
94 | |
---|
95 | double tScore::score(const classifier::Target& target, |
---|
96 | const utility::VectorBase& value, |
---|
97 | const utility::VectorBase& weight) const |
---|
98 | { |
---|
99 | return score(target, value, weight, NULL); |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | double tScore::score(const classifier::Target& target, |
---|
104 | const utility::VectorBase& value, |
---|
105 | const utility::VectorBase& weight, |
---|
106 | double* dof) const |
---|
107 | { |
---|
108 | statistics::AveragerWeighted positive; |
---|
109 | statistics::AveragerWeighted negative; |
---|
110 | for(size_t i=0; i<target.size(); i++){ |
---|
111 | if (target.binary(i)) |
---|
112 | positive.add(value(i),weight(i)); |
---|
113 | else |
---|
114 | negative.add(value(i),weight(i)); |
---|
115 | } |
---|
116 | return score(positive, negative, dof); |
---|
117 | } |
---|
118 | |
---|
119 | }}} // of namespace statistics, yat, and theplu |
---|