source: trunk/yat/statistics/WilcoxonFoldChange.cc

Last change on this file was 2919, checked in by Peter, 9 years ago

update copyright years

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1// $Id: WilcoxonFoldChange.cc 2919 2012-12-19 06:54:23Z peter $
2
3/*
4  Copyright (C) 2005 Peter Johansson
5  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
6  Copyright (C) 2012 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 <config.h>
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
35namespace theplu {
36namespace yat {
37namespace 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 std::abs(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 std::abs(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
Note: See TracBrowser for help on using the repository browser.