461 |
16 Dec 05 |
peter |
// $Id$ |
461 |
16 Dec 05 |
peter |
2 |
|
675 |
10 Oct 06 |
jari |
3 |
/* |
831 |
27 Mar 07 |
peter |
Copyright (C) 2005 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2006 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2012 Peter Johansson |
461 |
16 Dec 05 |
peter |
9 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
675 |
10 Oct 06 |
jari |
11 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
675 |
10 Oct 06 |
jari |
16 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 |
10 Oct 06 |
jari |
General Public License for more details. |
675 |
10 Oct 06 |
jari |
21 |
|
675 |
10 Oct 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
675 |
10 Oct 06 |
jari |
24 |
*/ |
675 |
10 Oct 06 |
jari |
25 |
|
2881 |
18 Nov 12 |
peter |
26 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
27 |
|
680 |
11 Oct 06 |
jari |
28 |
#include "WilcoxonFoldChange.h" |
680 |
11 Oct 06 |
jari |
29 |
#include "utility.h" |
675 |
10 Oct 06 |
jari |
30 |
#include "yat/classifier/Target.h" |
1471 |
02 Sep 08 |
peter |
31 |
#include "yat/utility/DataWeight.h" |
675 |
10 Oct 06 |
jari |
32 |
|
465 |
16 Dec 05 |
peter |
33 |
#include <cmath> |
475 |
22 Dec 05 |
peter |
34 |
#include <vector> |
488 |
04 Jan 06 |
peter |
35 |
#include <iostream> |
461 |
16 Dec 05 |
peter |
36 |
|
461 |
16 Dec 05 |
peter |
37 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
38 |
namespace yat { |
461 |
16 Dec 05 |
peter |
39 |
namespace statistics { |
461 |
16 Dec 05 |
peter |
40 |
|
461 |
16 Dec 05 |
peter |
41 |
|
461 |
16 Dec 05 |
peter |
42 |
WilcoxonFoldChange::WilcoxonFoldChange(bool absolute) |
461 |
16 Dec 05 |
peter |
43 |
: Score(absolute) |
461 |
16 Dec 05 |
peter |
44 |
{ |
461 |
16 Dec 05 |
peter |
45 |
} |
461 |
16 Dec 05 |
peter |
46 |
|
461 |
16 Dec 05 |
peter |
47 |
|
4200 |
19 Aug 22 |
peter |
48 |
double WilcoxonFoldChange::score(const classifier::Target& target, |
1023 |
01 Feb 08 |
peter |
49 |
const utility::VectorBase& value) const |
461 |
16 Dec 05 |
peter |
50 |
{ |
465 |
16 Dec 05 |
peter |
51 |
std::vector<double> distance; |
4200 |
19 Aug 22 |
peter |
//Peter, should reserve the vector to avoid reallocations |
475 |
22 Dec 05 |
peter |
53 |
for (size_t i=0; i<target.size(); i++) { |
1315 |
19 May 08 |
peter |
54 |
if (target.binary(i)) continue; |
488 |
04 Jan 06 |
peter |
55 |
for (size_t j=0; j<target.size(); j++) { |
1315 |
19 May 08 |
peter |
56 |
if (!target.binary(j)) |
1315 |
19 May 08 |
peter |
57 |
distance.push_back(value(i)-value(j)); |
465 |
16 Dec 05 |
peter |
58 |
} |
465 |
16 Dec 05 |
peter |
59 |
} |
465 |
16 Dec 05 |
peter |
60 |
if (absolute_) |
1683 |
30 Dec 08 |
peter |
61 |
return std::abs(median(distance.begin(), distance.end())); |
932 |
05 Oct 07 |
peter |
62 |
return median(distance.begin(), distance.end()); |
461 |
16 Dec 05 |
peter |
63 |
} |
461 |
16 Dec 05 |
peter |
64 |
|
623 |
05 Sep 06 |
peter |
65 |
|
4200 |
19 Aug 22 |
peter |
66 |
double WilcoxonFoldChange::score(const classifier::Target& target, |
1023 |
01 Feb 08 |
peter |
67 |
const utility::VectorBase& value, |
1023 |
01 Feb 08 |
peter |
68 |
const utility::VectorBase& weight) const |
461 |
16 Dec 05 |
peter |
69 |
{ |
1471 |
02 Sep 08 |
peter |
70 |
std::vector<utility::DataWeight> distance; |
4200 |
19 Aug 22 |
peter |
//Peter, should reserve the vector to avoid reallocations |
1471 |
02 Sep 08 |
peter |
72 |
for (size_t i=0; i<target.size(); i++) { |
1471 |
02 Sep 08 |
peter |
73 |
if (target.binary(i)) continue; |
1471 |
02 Sep 08 |
peter |
74 |
for (size_t j=0; j<target.size(); j++) { |
1471 |
02 Sep 08 |
peter |
75 |
if (!target.binary(j)) |
1471 |
02 Sep 08 |
peter |
76 |
distance.push_back(utility::DataWeight(value(i)-value(j), |
1471 |
02 Sep 08 |
peter |
77 |
weight(i)*weight(j))); |
1471 |
02 Sep 08 |
peter |
78 |
} |
1471 |
02 Sep 08 |
peter |
79 |
} |
1471 |
02 Sep 08 |
peter |
80 |
if (absolute_) |
1683 |
30 Dec 08 |
peter |
81 |
return std::abs(median(distance.begin(), distance.end())); |
1471 |
02 Sep 08 |
peter |
82 |
return median(distance.begin(), distance.end()); |
1471 |
02 Sep 08 |
peter |
83 |
|
4200 |
19 Aug 22 |
peter |
84 |
|
465 |
16 Dec 05 |
peter |
85 |
return 0; |
461 |
16 Dec 05 |
peter |
86 |
} |
461 |
16 Dec 05 |
peter |
87 |
|
680 |
11 Oct 06 |
jari |
88 |
}}} // of namespace statistics, yat, and theplu |