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