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