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