1 | // $Id: SAMScore.cc 1487 2008-09-10 08:41:36Z jari $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson |
---|
5 | Copyright (C) 2008 Peter Johansson |
---|
6 | |
---|
7 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
8 | |
---|
9 | The yat library is free software; you can redistribute it and/or |
---|
10 | modify it under the terms of the GNU General Public License as |
---|
11 | published by the Free Software Foundation; either version 3 of the |
---|
12 | License, or (at your option) any later version. |
---|
13 | |
---|
14 | The yat library is distributed in the hope that it will be useful, |
---|
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
17 | General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License |
---|
20 | along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
21 | */ |
---|
22 | |
---|
23 | #include "SAMScore.h" |
---|
24 | #include "Averager.h" |
---|
25 | #include "AveragerWeighted.h" |
---|
26 | #include "yat/classifier/DataLookupWeighted1D.h" |
---|
27 | #include "yat/classifier/Target.h" |
---|
28 | #include "yat/utility/VectorBase.h" |
---|
29 | |
---|
30 | #include <cmath> |
---|
31 | |
---|
32 | namespace theplu { |
---|
33 | namespace yat { |
---|
34 | namespace statistics { |
---|
35 | |
---|
36 | SAMScore::SAMScore(const double s0, bool b) |
---|
37 | : Score(b), s0_(s0) |
---|
38 | { |
---|
39 | } |
---|
40 | |
---|
41 | double SAMScore::score(const classifier::Target& target, |
---|
42 | const utility::VectorBase& value) const |
---|
43 | { |
---|
44 | statistics::Averager positive; |
---|
45 | statistics::Averager negative; |
---|
46 | for(size_t i=0; i<target.size(); i++){ |
---|
47 | if (target.binary(i)) |
---|
48 | positive.add(value(i)); |
---|
49 | else |
---|
50 | negative.add(value(i)); |
---|
51 | } |
---|
52 | return score(positive, negative); |
---|
53 | } |
---|
54 | |
---|
55 | double SAMScore::score(const classifier::Target& target, |
---|
56 | const classifier::DataLookupWeighted1D& value) const |
---|
57 | { |
---|
58 | statistics::AveragerWeighted positive; |
---|
59 | statistics::AveragerWeighted negative; |
---|
60 | for(size_t i=0; i<target.size(); i++){ |
---|
61 | if (target.binary(i)) |
---|
62 | positive.add(value.data(i),value.weight(i)); |
---|
63 | else |
---|
64 | negative.add(value.data(i),value.weight(i)); |
---|
65 | } |
---|
66 | return score(positive, negative); |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | |
---|
71 | double SAMScore::score(const classifier::Target& target, |
---|
72 | const utility::VectorBase& value, |
---|
73 | const utility::VectorBase& weight) const |
---|
74 | { |
---|
75 | statistics::AveragerWeighted positive; |
---|
76 | statistics::AveragerWeighted negative; |
---|
77 | for(size_t i=0; i<target.size(); i++){ |
---|
78 | if (target.binary(i)) |
---|
79 | positive.add(value(i),weight(i)); |
---|
80 | else |
---|
81 | negative.add(value(i),weight(i)); |
---|
82 | } |
---|
83 | return score(positive, negative); |
---|
84 | } |
---|
85 | |
---|
86 | }}} // of namespace statistics, yat, and theplu |
---|