1 | // $Id: WilcoxonFoldChange.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 "WilcoxonFoldChange.h" |
---|
25 | #include "utility.h" |
---|
26 | #include "yat/classifier/Target.h" |
---|
27 | #include "yat/utility/DataWeight.h" |
---|
28 | |
---|
29 | #include <cmath> |
---|
30 | #include <vector> |
---|
31 | #include <iostream> |
---|
32 | |
---|
33 | namespace theplu { |
---|
34 | namespace yat { |
---|
35 | namespace statistics { |
---|
36 | |
---|
37 | |
---|
38 | WilcoxonFoldChange::WilcoxonFoldChange(bool absolute) |
---|
39 | : Score(absolute) |
---|
40 | { |
---|
41 | } |
---|
42 | |
---|
43 | |
---|
44 | double WilcoxonFoldChange::score(const classifier::Target& target, |
---|
45 | const utility::VectorBase& value) const |
---|
46 | { |
---|
47 | std::vector<double> distance; |
---|
48 | //Peter, should reserve the vector to avoid reallocations |
---|
49 | for (size_t i=0; i<target.size(); i++) { |
---|
50 | if (target.binary(i)) continue; |
---|
51 | for (size_t j=0; j<target.size(); j++) { |
---|
52 | if (!target.binary(j)) |
---|
53 | distance.push_back(value(i)-value(j)); |
---|
54 | } |
---|
55 | } |
---|
56 | if (absolute_) |
---|
57 | return std::abs(median(distance.begin(), distance.end())); |
---|
58 | return median(distance.begin(), distance.end()); |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | double WilcoxonFoldChange::score(const classifier::Target& target, |
---|
63 | const utility::VectorBase& value, |
---|
64 | const utility::VectorBase& weight) const |
---|
65 | { |
---|
66 | std::vector<utility::DataWeight> distance; |
---|
67 | //Peter, should reserve the vector to avoid reallocations |
---|
68 | for (size_t i=0; i<target.size(); i++) { |
---|
69 | if (target.binary(i)) continue; |
---|
70 | for (size_t j=0; j<target.size(); j++) { |
---|
71 | if (!target.binary(j)) |
---|
72 | distance.push_back(utility::DataWeight(value(i)-value(j), |
---|
73 | weight(i)*weight(j))); |
---|
74 | } |
---|
75 | } |
---|
76 | if (absolute_) |
---|
77 | return std::abs(median(distance.begin(), distance.end())); |
---|
78 | return median(distance.begin(), distance.end()); |
---|
79 | |
---|
80 | |
---|
81 | return 0; |
---|
82 | } |
---|
83 | |
---|
84 | }}} // of namespace statistics, yat, and theplu |
---|