source: trunk/c++_tools/statistics/FoldChange.cc @ 623

Last change on this file since 623 was 623, checked in by Peter, 15 years ago

fixes #112 and refs #123 added overloaded function score taking Target and DataLookupWeighted1D, which is needed for InputRanker?.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1// $Id: FoldChange.cc 623 2006-09-05 02:13:12Z peter $
2
3#include <c++_tools/statistics/FoldChange.h>
4#include <c++_tools/statistics/Score.h>
5#include <c++_tools/statistics/Averager.h>
6#include <c++_tools/statistics/AveragerWeighted.h>
7#include <c++_tools/classifier/DataLookupWeighted1D.h>
8#include <c++_tools/classifier/Target.h>
9
10namespace theplu {
11namespace statistics {
12
13
14  FoldChange::FoldChange(bool absolute)
15    : Score(absolute)
16  {
17  }
18
19
20
21  FoldChange::FoldChange(const FoldChange& other)
22    : Score(other)
23  {
24  }
25
26
27
28  FoldChange& FoldChange::operator=(const FoldChange& other)
29  {
30    Score::operator=(other);
31    return *this;
32  }
33
34  double FoldChange::score(const classifier::Target& target, 
35                           const utility::vector& value) 
36  {
37    weighted_=false;
38    Averager pos;
39    Averager neg;
40
41    for (size_t i=0; i<value.size(); i++) 
42      if (target.binary(i))
43        pos.add(value(i));
44      else
45        neg.add(value(i));
46         
47    if (absolute_)
48      return fabs(pos.mean()-neg.mean());
49    return pos.mean()-neg.mean();
50  }
51
52  double FoldChange::score(const classifier::Target& target, 
53                           const classifier::DataLookupWeighted1D& value) 
54  {
55    weighted_=true;
56    AveragerWeighted pos;
57    AveragerWeighted neg;
58
59    for (size_t i=0; i<value.size(); i++) 
60      if (target.binary(i))
61        pos.add(value.data(i),value.weight(i));
62      else
63        neg.add(value.data(i),value.weight(i));
64         
65    if (absolute_)
66      return fabs(pos.mean()-neg.mean());
67    return pos.mean()-neg.mean();
68  }
69
70
71  double FoldChange::score(const classifier::Target& target, 
72                           const utility::vector& value,
73                           const utility::vector& weight) 
74  {
75    weighted_=true;
76    AveragerWeighted pos;
77    AveragerWeighted neg;
78
79    for (size_t i=0; i<value.size(); i++) 
80      if (target.binary(i))
81        pos.add(value(i),weight(i));
82      else
83        neg.add(value(i),weight(i));
84         
85    if (absolute_)
86      return fabs(pos.mean()-neg.mean());
87    return pos.mean()-neg.mean();
88  }
89
90} // of namespace statistics
91} // of namespace theplu
Note: See TracBrowser for help on using the repository browser.