source: trunk/yat/statistics/WilcoxonFoldChange.cc @ 1797

Last change on this file since 1797 was 1797, checked in by Peter, 13 years ago

updating copyright statements

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