1 | // $Id: SAMScore.cc 1486 2008-09-09 21:17:19Z 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 this program; if not, write to the Free Software |
---|
21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
22 | 02111-1307, USA. |
---|
23 | */ |
---|
24 | |
---|
25 | #include "SAMScore.h" |
---|
26 | #include "Averager.h" |
---|
27 | #include "AveragerWeighted.h" |
---|
28 | #include "yat/classifier/DataLookupWeighted1D.h" |
---|
29 | #include "yat/classifier/Target.h" |
---|
30 | #include "yat/utility/VectorBase.h" |
---|
31 | |
---|
32 | #include <cmath> |
---|
33 | |
---|
34 | namespace theplu { |
---|
35 | namespace yat { |
---|
36 | namespace statistics { |
---|
37 | |
---|
38 | SAMScore::SAMScore(const double s0, bool b) |
---|
39 | : Score(b), s0_(s0) |
---|
40 | { |
---|
41 | } |
---|
42 | |
---|
43 | double SAMScore::score(const classifier::Target& target, |
---|
44 | const utility::VectorBase& value) const |
---|
45 | { |
---|
46 | statistics::Averager positive; |
---|
47 | statistics::Averager negative; |
---|
48 | for(size_t i=0; i<target.size(); i++){ |
---|
49 | if (target.binary(i)) |
---|
50 | positive.add(value(i)); |
---|
51 | else |
---|
52 | negative.add(value(i)); |
---|
53 | } |
---|
54 | return score(positive, negative); |
---|
55 | } |
---|
56 | |
---|
57 | double SAMScore::score(const classifier::Target& target, |
---|
58 | const classifier::DataLookupWeighted1D& value) const |
---|
59 | { |
---|
60 | statistics::AveragerWeighted positive; |
---|
61 | statistics::AveragerWeighted negative; |
---|
62 | for(size_t i=0; i<target.size(); i++){ |
---|
63 | if (target.binary(i)) |
---|
64 | positive.add(value.data(i),value.weight(i)); |
---|
65 | else |
---|
66 | negative.add(value.data(i),value.weight(i)); |
---|
67 | } |
---|
68 | return score(positive, negative); |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | double SAMScore::score(const classifier::Target& target, |
---|
74 | const utility::VectorBase& value, |
---|
75 | const utility::VectorBase& weight) const |
---|
76 | { |
---|
77 | statistics::AveragerWeighted positive; |
---|
78 | statistics::AveragerWeighted negative; |
---|
79 | for(size_t i=0; i<target.size(); i++){ |
---|
80 | if (target.binary(i)) |
---|
81 | positive.add(value(i),weight(i)); |
---|
82 | else |
---|
83 | negative.add(value(i),weight(i)); |
---|
84 | } |
---|
85 | return score(positive, negative); |
---|
86 | } |
---|
87 | |
---|
88 | }}} // of namespace statistics, yat, and theplu |
---|